Click to See Complete Forum and Search --> : data saving


dummie
November 26th, 1999, 06:13 AM
Hello people,
i've got a problem.
How my name says I'm a dummie in Visual Basic.
And I donīt find someone who helps me.
My problem:
How can I save datas in VB on the harddisk ?
For example I want to save a highscore.
Is there a possibility to save the datas without
a database like Acces ?

Can someone help me ?
Perhaps you can send me documentations or good
links, or of course the best way cou can
discribe it me. (Iīm German, so please in a
easy English or in German)

Thank you very much,

Marcel

November 26th, 1999, 06:19 AM
haha

November 26th, 1999, 01:58 PM
Create an empty file using Notepad and save it as "C:\myTest.txt". Open VB and place 2 Command Buttons on the form. Open Code Window for Form1 and Paste the following code:

private Sub Command1_Click()
Dim intFreeFile as Integer
Dim TextLine as string
intFreeFile = FreeFile
Open "C:\myData.txt" for Output as #intFreeFile ' Open file.

Write #intFreeFile, "Hello World", 234 ' Write comma-delimited data.
Write #intFreeFile, ' Write blank line.
Write #intFreeFile, "You are not dummie if you are trying to do this"
Close #intFreeFile
End Sub

private Sub Command2_Click()
Dim intFreeFile as Integer
Dim TextLine as string
intFreeFile = FreeFile
Open "C:\myData.txt" for input as #intFreeFile ' Open file.
Do While Not EOF(intFreeFile) ' Loop until end of file.
Line input #intFreeFile, TextLine ' Read line into variable.
Debug.print TextLine ' print to the Immediate window.
Loop
Close #intFreeFile ' Close file.

End Sub




Run project and click on Command1, then on Command2. If you now open "C:\myTest.txt" you'll see, that it's not empty anymore. This is just the beginning. After that you can write the contents of the text box to the file , and display the contents of the file in a text box or in a grid.
Hope this helps
Vlad

Wayne Kane
November 26th, 1999, 05:13 PM
You can create a datafile using:

e.g. Private Sub Form_Load()
open "path\filename" for Input As #1

for i = 1 to arraynumber step 1
Write #1, variablename, variablename

just an example of something that may help