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,Uni ted States,
INSERT_INCL_TRANS:
2,0000320,10182001000001,1 23456789,0 9/01/2001
Thanks for your attention!
INSERT_MNL_ACCTS:
123456789,Manual Account Test,111223333,,10,ACB,123
INSERT_INCL_TRANS:
2,0000320,10182001000001,1
Thanks for your attention!
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
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
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
ASKER
Shyampaliyath,
Could you please give me an example to show me how to read data from ini? Thanks!
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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Split does that:
'getting string from text file
myStr="2,0000320,101820010
'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