By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,097 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,097 IT Pros & Developers. It's quick & easy.

Import Data from a text file...

P: 4
How do you select a specific line from an open file and input those specific into a designated textbox?

When I open up a file with the opendialog() and then select the file that I want to import(or to pull data from). This is the text file setup that I am trying to get the information from:

--------------------------------------------------------
ASSIGN.RSM A 6:00:00 "Initialize Times"
ASSIGN.RSM B 6:10:59
ASSIGN.RSM C 6:02:02
--------------------------------------------------------

Now I want to input the first line if they select A, which designates the first line of the text file and then from there to input the 6 in textbox1.text and 00 into textbox2.text and 00 into textbox3.text. Now if they select B, then it'll pull the information from line 2 and put the 6 in textbox1.text and the 10 in textbox2.text and etc. How would I go about doing that? Any help would be greatly appreciated. Thanks.
Mar 30 '07 #1
Share this Question
Share on Google+
1 Reply


iburyak
Expert 100+
P: 1,017
Try this:

[PHP]Dim FH As Long, strLine As String, i As Integer
Dim strSplitLine, txtSplit

FH = FreeFile()
Open "File Name Here" For Input Access Read Shared As #FH
Do Until EOF(FH)
Line Input #FH, strLine
If Trim(strLine) <> "" Then

strSplitLine = Split(strLine, " ")
If strSplitLine(1) = "A" Then 'change "A" to variable here
txtSplit = Split(strSplitLine(2), ":")
For i = 0 To UBound(txtSplit)
Select Case i
Case 0
Text1.Text = txtSplit(i)
Case 1
Text2.Text = txtSplit(i)
Case 2
Text3.Text = txtSplit(i)

End Select
Next
Exit Do
End If
End If
Loop[/PHP]
Mar 30 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.