|
-
April 6th, 2001, 10:53 PM
#1
Text File Read and Display
Hi gurus...
I have a text file with following contents:
"abc", 123, xyz
"lmn", 345, qrs
"abc", 999, asd
I want to display "abc", "lmn", "abc" in a combo list box... and when clicked on "abc" from the list box, I wanna be able to display the correspondeing text such as "123, xyz" into a picture box or a textbox.
Any ideas as to how i can link the first part of a line in a text file with the rest of the line?
Looking for some code.. Much much appreciated.
[n]Shaikh
| http://nawedshaikh.com |
-
April 7th, 2001, 02:06 AM
#2
Re: Text File Read and Display
First you need to read the whole file into string (ReadFileStr), then you need to separate the string into individual line (Tokenize, GetToken), finally you need to use the mid$ function on individual string.
get those function (ReadFileStr, Tokenize, GetToken) from
http://vblib.virtualave.net
-
April 7th, 2001, 06:36 AM
#3
Re: Text File Read and Display
private sub form_load()
dim Str1(100) as string, str2(100) as string, str3(100) as string, str as string
dim arr
dim filenum as long
dim cnt as integer
filenum=freefile
open "data.txt" for input as #filenum
cnt = 0
do while not EOF(filenum)
line input #filenum, str
arr = split(str,",")
str1(cnt)=arr(0)
combo1.additem str1
str2(cnt)=arr(1)
str3(cnt)=arr(2)
cnt = cnt+1
loop
end sub
private sub combo1_click()
dim indx as integer
indx = combo1.listindex
text1.text = str2(indx)
text2.text = str3(indx)
end sub
-
April 7th, 2001, 09:25 AM
#4
Re: Text File Read and Display
Another way to do this
option Explicit
Dim Arr1(10) as string
Dim arr2(10) as string
private Sub Combo1_Click()
Text1 = Arr1(Combo1.ListIndex)
Text2 = arr2(Combo1.ListIndex)
End Sub
private Sub Command1_Click()
Dim Temp as string
Dim X as Integer
Open "C:\VB Stuff\Things to Look at\Test.txt" for input as #1
Do Until EOF(1)
input #1, Temp, Arr1(X), arr2(X)
Combo1.AddItem Temp
X = X + 1
Loop
End Sub
John G
-
April 7th, 2001, 11:19 PM
#5
Re: Text File Read and Display
Thank you so much guys/gals... you all are great! btw, your ratings just went up! : )
[n]Shaikh
| http://nawedshaikh.com |
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|