Liberty BASIC Community Forum
« Save to SD Card? »

Welcome Guest. Please Login or Register.
Sep 20th, 2017, 09:50am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Save to SD Card?  (Read 115 times)
cocos
New Member
Image


member is offline

Avatar




PM


Posts: 4
xx Save to SD Card?
« Thread started on: Sep 5th, 2017, 2:05pm »

Hello,

I am quite a novice in programming but I wonder if I can use liberty basic for my project:

The program shall (besides some other simpler stuff) write data to an SD Card.
It shall be written to the SD Card after pressing a button (don't want to use a file-explorer dialog to keep it simple for the user).
There shall be an error message in case no SD Card has been inserted.
I have checked the LB-documentation but I am still unsure wether this can be done with liberty basic. If yes, I would appreciate some sample code.

Thanks!
User IP Logged

Stefan Pendl
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Computers are like babies, you must teach them what you like them to do ...


Homepage PM

Gender: Male
Posts: 5295
xx Re: Save to SD Card?
« Reply #1 on: Sep 5th, 2017, 4:05pm »

An SD-Card is just another drive similar to a regular hard-disk, so there is no special code needed.
User IP Logged

Stefan

Make sure to read and follow the Forum Guidelines

Liberty BASIC Pro 4.04, Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Save to SD Card?
« Reply #2 on: Sep 6th, 2017, 03:31am »

Here are two of the example files combined to do the job of finding your SD card. You would have a named file on the card. In this case "test.txt". The code finds all the drives that exist on the PC then search each in turn for the named file.


Code:
    'a simple example illustrating the use of the Drives$ variable
    'nomainwin

    dim letters$(25)
    index = 0
    while word$(Drives$, index + 1) <> ""
        letters$(index) = word$(Drives$, index + 1)
        index = index + 1
    wend
    numberOfDrives=index-1




    'fileExists.bas - Show how to determine if a file exists
    dim info$(10,10)
    for i = 0 to numberOfDrives
        fpath$=letters$(i)+"\test.txt"
        if fileExists(fpath$) then
            print fpath$; " exists!"
        else
            print fpath$; " doesn't exist!"
        end if
    next
    end

'return a true if the file in fullPath$ exists, else return false
function fileExists(fullPath$)
    files pathOnly$(fullPath$), filenameOnly$(fullPath$), info$()
    fileExists = val(info$(0, 0)) > 0
end function

'return just the directory path from a full file path
function pathOnly$(fullPath$)
    pathOnly$ = fullPath$
    while right$(pathOnly$, 1) <> "\" and pathOnly$ <> ""
        pathOnly$ = left$(pathOnly$, len(pathOnly$)-1)
    wend
end function

'return just the filename from a full file path
function filenameOnly$(fullPath$)
    pathLength = len(pathOnly$(fullPath$))
    filenameOnly$ = right$(fullPath$, len(fullPath$)-pathLength)
end function



 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls