problem with reading a .txt-file

Siegie
05-01-2003, 05:22 AM
hi all
i have a problem with following code:


Sub CreateFile()
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile(CommonDialog1.FileName & ".txt", True)
tf.writeline (Val(Text1.Text))
tf.writeline (Val(Text2.Text))
tf.writeline (Val(Text3.Text))
tf.writeline (Val(Text4.Text))
tf.Close
End Sub


Sub OpenFile()
Dim zt, z_fso
Set z_fso = CreateObject("Scripting.FileSystemObject")
Set z_t = z_fso.OpenTextFile(CommonDialog1.FileName, 1, False)
Text1 = Val(z_line1)
Text2 = Val(z_line2)
Text3 = Val(z_line3)
Text4 = Val(z_line4)
End Sub


Private Sub cmdSave_Click()
CommonDialog1.ShowSave
CreateFile
End Sub


Private Sub cmdOpen_Click()
CommonDialog1.ShowOpen
OpenFile
End Sub


at first, i save the contents of a textbox (numbers only) in a *.txt-file and then, i want to load the saved numbers.
my problem is that the loaded numbers are 0 (zero) and not the numbers i saved.

how can i solve this problem?

thank you all

regards
siegie

ps: sorry 4 my bad english

sjp
05-01-2003, 05:42 AM
hi all
Sub OpenFile()
Dim zt, z_fso
Set z_fso = CreateObject("Scripting.FileSystemObject")
Set z_t = z_fso.OpenTextFile(CommonDialog1.FileName, 1, False)
Text1 = Val(z_line1)
Text2 = Val(z_line2)
Text3 = Val(z_line3)
Text4 = Val(z_line4)
End Sub




where do u assing the lines u read to
z_line1
z_line2
z_line3
z_line4

i think thats the issue here.

Flyguy
05-01-2003, 06:15 AM
Why using the Val() function?
ASCII files are strings and textboxes are strings, so why convert it to numeric?

Siegie
05-01-2003, 06:48 AM
Hi Flyguy
If I don't use the Val() function I get a empty textbox.
I don't know what I did wrong :(

Squirm
05-01-2003, 06:50 AM
Please read sjp's reply:

where do u assing the lines u read to
z_line1
z_line2
z_line3
z_line4

i think thats the issue here.

If you sort that out, you certainly won't need the Val()s. Also, as a code purist I'd say scrap the FSO and use the native VB file I/O methods (Open, Close, Line Input, EOF() etc).

Siegie
05-01-2003, 07:14 AM
Hi Squirm.
Thank you!
It works now :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum