|
-
Apr 29th, 2006, 11:49 AM
#1
Thread Starter
Addicted Member
Loading a file... i'll go into as much detail as possible
Right, i've asked similar questions a few times and got different answers and it has completely confused me so i've deicded to put exactly what i want in as much detail as possible. So, here we go:
I know how to create text files and am completely certain on that front. What i want to do is load a text file back into my program.
What i want it to do is take the top line and put it in, let's say label1.caption. and then take the second line and put it in label2.caption and third line in label3.caption. how would i do this? if i need to put some nessacery text in the file which would be a piece of code or something then tell me what it is and what i need to put.
Please give it as exactly what i need aswell, not a link to something which is a "variation" of what i want (which'll just confuse me and end in me asking again). thanks.
-
Apr 29th, 2006, 11:57 AM
#2
Re: Loading a file... i'll go into as much detail as possible
if your labels are named label1, label2, label3 etc, then you can do this:
VB Code:
Dim N As Long, sLine As String, FF As Long
FF = FreeFile
Open "C:\file.txt" For Input As #FF
Do Until EOF(FF)
Line Input #FF, sLine
N = N + 1
Me.Controls("Label" & N).Caption = sLine
Loop
Close #FF
-
Apr 29th, 2006, 12:17 PM
#3
Thread Starter
Addicted Member
Re: Loading a file... i'll go into as much detail as possible
still not sure. so if i put in the file:
test
test2
test3
then label1.caption will be test, label2.caption will be test2 and label3.caption will be test3, is that right?
-
Apr 29th, 2006, 12:18 PM
#4
Re: Loading a file... i'll go into as much detail as possible
-
May 1st, 2006, 07:02 AM
#5
Thread Starter
Addicted Member
Re: Loading a file... i'll go into as much detail as possible
and what would i do if i wanted say, the first line to be label1.caption, second line to go to label4.caption, thrid line to go to text1.text and 4th line to go to command1.caption?
(just chose some random things for this example)
-
May 1st, 2006, 08:14 AM
#6
PowerPoster
Re: Loading a file... i'll go into as much detail as possible
The you would need to manually check the value of "N" (select case) and set the control accordingly
-
May 1st, 2006, 10:22 AM
#7
Re: Loading a file... i'll go into as much detail as possible
Or add them to a collection and loop through the collection: i.e.
VB Code:
Private colControls As Collection
Private Sub Form_Load()
Set colControls = New Collection
With colControls
.Add Label1, Label1.Name
.Add Label4, Label4.Name
.Add Text1, Text1.Name
.Add Command1, Command1.Name
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set colControls = Nothing
End Sub
Private Sub Command1_Click()
Dim N As Long, sLine As String, FF As Long
FF = FreeFile
Open "C:\file.txt" For Input As #FF
Do Until EOF(FF)
Line Input #FF, sLine
N = N + 1
Select Case True
Case TypeOf colControls(N) Is TextBox
colControls(N).Text = sLine
Case Else
colControls(N).Caption = sLine
End Select
Loop
Close #FF
End Sub
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
|