Liberty BASIC Community Forum
« Saving »

Welcome Guest. Please Login or Register.
Jan 23rd, 2018, 7:23pm


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


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Saving  (Read 75 times)
mack
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 147
xx Saving
« Thread started on: Nov 20th, 2017, 10:43am »

Hi

Here is a simple program. I want to add a product into the textbox, then come out of LB and still save the product for next time I log in. How would I do this?

The file is C:\Users\User\Documents\Products.bas

I know how to do it with a text file but not GUI.

Thanks


nomainwin
statictext #1.1, "Product:", 20, 20, 75, 25
textbox #1.1, 100, 20, 75, 25

open "Data" for window as #1

UpperLeftX = 150
UpperLeftY = 200
WindowWidth = 500
WindowHeight = 400

print #1, "trapclose [quit]"
wait

[quit]

close #1
end

User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: Saving
« Reply #1 on: Nov 20th, 2017, 1:49pm »

http://lbpe.wikispaces.com/IniFiles
User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: Saving
« Reply #2 on: Nov 20th, 2017, 3:04pm »

Err...
you open file on program start
and write in on program end
But it's just takes more effort then it seems first
Code:
global filename$    'filename to use
filename$ = "product.dat"

nomainwin
statictext #1.1, "Product:", 20, 20, 75, 25
textbox #1.1, 100, 20, 75, 25

open "Data" for window as #1

UpperLeftX = 150
UpperLeftY = 200
WindowWidth = 500
WindowHeight = 400

print #1, "trapclose [quit]"

'read the data
call readData

wait

[quit]
'on closing, save the data
call saveData
close #1
end

'read data from a file
sub readData
     if fileExists(DefaultDir$, filename$) then
        open filename$ for input as #file
            line input #file, txt$     'read whole line from a file
        close #file
     end if
    #1.1 txt$  'put data to a textbox
end sub

'save data to a file
sub saveData
    #1.1 "!contents? txt$"  'read data from textbox
    open filename$ for output as #file
        #file txt$     'save it to a file
    close #file
end sub

function fileExists(path$, filename$)
  'from a help file
  dim info$(0, 0)
  files path$, filename$, info$()
  fileExists = val(info$(0, 0))  'non zero is true
end function
 
User IP Logged

damned Dog in the Manger
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