Link to home
Start Free TrialLog in
Avatar of amostcc
amostcc

asked on

Help!!!Read data Problem

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

(READ DATA)
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"??
.....................
ASKER CERTIFIED SOLUTION
Avatar of willisp
willisp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of twalgrave
twalgrave

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"
(READ DATA)
'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

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
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

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.

Netminder
EE Admin