Saving and reading variables to/from a file
Saving and reading variables to/from a file
(OP)
Hello,
I'm attempting to implement a "save file" of sorts for a number of Extra basic macros. Ideally, i'd like it to ask a series of questions, then save the user responses to a text file so it remembers the answers the next time the macro runs.
The point I'm stumped at is how to code it to actually read the values from a file to set multiple variables. Is anyone familiar with how I might do this?
Thanks!
I'm attempting to implement a "save file" of sorts for a number of Extra basic macros. Ideally, i'd like it to ask a series of questions, then save the user responses to a text file so it remembers the answers the next time the macro runs.
The point I'm stumped at is how to code it to actually read the values from a file to set multiple variables. Is anyone familiar with how I might do this?
Thanks!
RE: Saving and reading variables to/from a file
Hi,
Have you looked at Extra HELP? Check out the Open command.
What code have you tried?
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: Saving and reading variables to/from a file
RE: Saving and reading variables to/from a file
Obviously this example opens a file for OUTPUT.
Maybe TRY opening your file for INPUT?
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: Saving and reading variables to/from a file
CODE
dim Somevariable1 as string
dim Somevariable2 as string
dim Somevariable3 as string
if dir$ ("c:\temp\savedvariables.txt") <> "savedvariables.txt" then
Somevariable1 = inputbox ("Somevariable1")
Somevariable2 = inputbox ("Somevariable2")
Somevariable3 = inputbox ("Somevariable3")
Open "c:\temp\savedvariables.txt" For Append Access Write Lock Read Write as #1
Write #1, Somevariable1, Somevariable2, Somevariable3
Close #1
Else
Open "c:\temp\savedvariables.txt" For Input as #1
Read #1, Somevariable1, Somevariable2, Somevariable3
Close #1
msgbox Somevariable1 & Somevariable2 & Somevariable3
End If
End Sub
RE: Saving and reading variables to/from a file
CODE
dim Somevariable1 as string
dim Somevariable2 as string
dim Somevariable3 as string
if dir$ ("c:\temp\savedvariables.txt") <> "savedvariables.txt" then
Somevariable1 = inputbox ("Somevariable1")
Somevariable2 = inputbox ("Somevariable2")
Somevariable3 = inputbox ("Somevariable3")
Open "c:\temp\savedvariables.txt" For Append Access Write Lock Read Write as #1
Write #1, Somevariable1, Somevariable2, Somevariable3
Close #1
Else
Open "c:\temp\savedvariables.txt" For Input as #1
Input #1, Somevariable1, Somevariable2, Somevariable3
Close #1
msgbox Somevariable1 & Somevariable2 & Somevariable3
End If
End Sub