Help!!!Read data Problem

amostcc used Ask the Experts™
Hi again,

This time, I got myself into mess because I tried to write 20 numeric data into a text files and could not revive the values back into each textbox, I really need to get those values display onto each textbox. Can anyone help me?
Here somthing how I wrote the code

Open c:\temp for input as #1
write #1 form1.value1
write #1 form1.value2
write #1 form1.value3
close #1

open c:\temp as input as #1
input #1 myvalue     <---- "not sure"    
close #1
text1.text = myvalue <---
text2.text = myvalue <--- "how to read the second value from the wriiten data"??
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Here's an example writing 2 text values to a file and reading them back in to textboxes:

Dim myvalue As String

Open "c:\temp.dat" For Output As #1
Write #1, Form1.Text1.Text
Write #1, Form1.Text2.Text
Close #1

Open "c:\temp.dat" For Input As #1
Input #1, myvalue       ' Read first value
Form1.Text1.Text = myvalue
Input #1, myvalue       ' Read 2nd value
Form1.Text2.Text = myvalue
Close #1

Hope this helps.
If you don't care if the individual lines are on separate lines of the text FILE. you can use something like this (it reads all values in at once:

Private Sub cmdRead_Click()
    Dim lFreeFile As Long
    lFreeFile = FreeFile
    Open "c:\temp.dat" For Input As #lFreeFile
    Dim sText1Val As String
    Dim sText2Val As String
    Input #lFreeFile, sText1Val, sText2Val
    Text1.Text = sText1Val
    Text2.Text = sText2Val
    Close #lFreeFile

End Sub

Private Sub cmdWrite_Click()
    Dim lFreeFile As Long
    lFreeFile = FreeFile

    Open "c:\temp.dat" For Output As #lFreeFile
    Write #lFreeFile, Form1.Text1.Text, Form1.Text2.Text
    Close #lFreeFile
End Sub

NOTE: In both the examples listed here, if the textbox contains one or more double-quotes ("), these techniques will not work.  You will need to switch to the Print function instead of Write.  In that case that you must allow double-quotes, willisp's code will be much easier to convert.
Dim Temp as String
First of all to write data you have to open it for output
'Open c:\temp for input as #1
Open c:\temp for outputas #1
write #1, form1.value1
write #1, form1.value2
write #1, form1.value3
close #1

Second You need variable when you read data from text file
and do not forget to write comma after "input #1"
'open c:\temp as input as #1
open c:\temp for input as #1
input #1, Temp
Text1.Text = Temp
input #1, Temp
Text2.Text = Temp

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

I would suggest you to use File System Object Reference, so that the code is much more easier
If u want any reference i will give u the code
Good Luck...

if your working with numbers you may want to get use to useing binary mode, and you should use the freefile function.

X = FreeFile
Open strFileName for binary as #X
Put #X, , intValue1
Put #X, , intValue2
Put #X, , lngValue3
Close #X

Then You can Get your Data Like This
X = FreeFile
Open strFileName for binary as #X
if Len(X) > 0 then
Get #X, , intValue1
Get #X, , intValue2
Get #X, , lngValue3
End if
Close #X
Text1.Text = Value1

just be bewear doing this, if you save the dat useing a int then you have to load it with an int.  also you may notice in the Get and Put functions the Get #X, , IntValue
theres nothing in the middle, you set the location in the file to store the value ex:
dim intMyVal as int
intMyVal = 12

Put #X, 50, intMyVal

Get #X, 50, intMyVal

you should get intMyVal to = 12

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- award the points to willisp
Please leave any comments here within the
next seven days.
Per recommendation, force-accepted.

EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial