Link to home
Start Free TrialLog in
Avatar of DevelHelper
DevelHelper

asked on

How to get data from a txt file?

I want to save all test data for different methods in a test.txt file. Do you know how to import those data to an array within the test.vbp which has a menu control to test all those methods? Here is an example:

INSERT_MNL_ACCTS:

123456789,Manual Account Test,111223333,,10,ACB,123 Any Street,Suite 10,,Cleveland,OH,44114,United States,

INSERT_INCL_TRANS:

2,0000320,10182001000001,123456789,09/01/2001

Thanks for your attention!
Avatar of Suat M. Ozgur
Suat M. Ozgur
Flag of United States of America image

you can use Split function in VB6. You should parse the string if you have older version.

Split does that:

'getting string  from text file
myStr="2,0000320,10182001000001,123456789,09/01/2001"
'setting MyArray using "," as delimiter
MyArray=Split(myStr,",")
'now you have UBound.MyArray value in MyArray array.
MyArray(0)="2"
MyArray(1)="0000320"
...
...

Did you need this?

Suat

Avatar of DevelHelper
DevelHelper

ASKER

My Question is that how to get string from text file.
dim q as long
q=filelen()
Open "c:\test.txt" For Binary As #q\

'if you want to write to the file
Put #q, 1, "testing"

'if you want to read from a specific location
'locations start with 1
'if the string you going to read is 50 character
dim s as string
s=string(50," ")
get #q, 1 , s

'if u donot know the characters lens
dim l as long
dim s as string
l=filelen("c:\test.txt")
s=string(l," ")
get #q,1,s
You can also use:

open "test.txt" for binary as #1
mystring = input$(lof(1), #1)
close #1
instead of storing this information as txt file u can store in ini files. This makes ur job more easier while retriving the data rather than in the txt file
Shyampaliyath,

Could you please give me an example to show me how to read data from ini? Thanks!
Search the VB help files for GetPrivateProfileString and PutPrivateProfileString for the pieces you need to read/write .ini file info.
I tried to search for GetPrivateProfileString and PutPrivateProfileString in VB help files. But unfortunately, I got a "Connection Timed Out" message from the window explorer. Could you please copy the code here? Thanks!
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

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