|
-
Mar 20th, 2003, 09:31 PM
#1
Thread Starter
New Member
output with text files
i have this complicated (at least i think so :P) project for programming class: Create a program that loads and breaks up a text file into different fields.
Private Sub Command1_Click()
Do While Not EOF(1) And Left$(Line1, 10) <> "Card Name:"
Line Input #1, Line1
Text1 = Line1
Loop
End Sub
that'll return the full line of text beginning with "card name:" but thats all i got for now, i need each line in a different text box so im getting stuck now, any help would be great!
-
Mar 20th, 2003, 10:45 PM
#2
Fanatic Member
VB Code:
Do While Not EOF(1) And Left$(Line1, 10) <> "Card Name:"
That line of code is NOT good! You do not want to keep reading the file if you reach eof. Your code requires both conditions to be true. What if eof is true but left$(Line1,10)<>"Card Name:" is not true? Then your program would try to keep reading the file even though it was already at the eof - crash! Never put another condition with eof. Eof should be the only test performed when reading a file to the end.
As for your question.
If you put a text box on a form and then copy and paste the same text box on the same form, vb will ask if you want to create a control array. (click on Yes!) A control array is just like an array, but with control.
So the first text box you put on the form would be text1(0) and the next one would be text1(1) and so on . . .
Assuming you had 20 text boxes and 20 lines in your imput file . . .
VB Code:
Private Sub Command1_Click()
Dim strLineOfText As String
Dim i As Integer
i = 0
Do While Not EOF(1)
Line Input #1, strLineOfText
Text1(i) = strLineOfText
i = i + 1
Loop
End Sub
I really don't want to do your homework because that wouldn't help you in the long run, but I hope that helps. If that example doesn't make sense, just let me know.
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Mar 22nd, 2003, 11:38 AM
#3
Thread Starter
New Member
i was thinking of using an array, my teacher told me i shouldn't have to but i guess my initial idea was right... thanks i'll try to work with what you've told me
-
Mar 22nd, 2003, 11:44 AM
#4
Fanatic Member
You and your teacher are both right. An array would be easier (you are correct) but you also don't need to (she is correct).
Good luck with the project and let us know if you run into any snags.
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Mar 22nd, 2003, 04:50 PM
#5
If your text file is delimited by commas or tabs you could look up
the Split command and put it into an array and put each element
into their respective text boxes.
-
Mar 23rd, 2003, 08:10 AM
#6
Hyperactive Member
hi,
why to take more text boxes.take one text box and display like this
Dim strLineOfText As String
Dim i As Integer
Do While Not EOF(1)
Line Input #1, strLineOfText
text1.text=text1.text & vbcrlf
Loop
-
Mar 24th, 2003, 08:45 PM
#7
Thread Starter
New Member
armbruster: i tried the code and when i got an error i remembered trying something almost the same but gave up on the idea because of this error:
Complie Error:
Can't Assign to Read Only Property
because of this line:
Text1(i) = strLineOfText
-
Mar 24th, 2003, 10:01 PM
#8
Fanatic Member
Ya know, it's always the easy stuff I screw up - the hard stuff is no problem !
should be . . .
VB Code:
Text1(i)[COLOR=red].Text[/COLOR] = strLineOfText
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Mar 25th, 2003, 01:32 PM
#9
Thread Starter
New Member
yikes, i wish i wasn't so bad at VB... but another error came up:
Compile Error:
Wrong number of arguments or invalid property assignment
-
Mar 25th, 2003, 05:53 PM
#10
Fanatic Member
post your code or zip your project . . .
what line is highlighted when you get the error?
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Mar 27th, 2003, 01:57 PM
#11
Thread Starter
New Member
i included other attempts but leave them commented out in my program
ERROR
Compile Error:
Wrong number of arguments or invalid property assignment
/ERROR 
Dim strLineOfText As String
Dim i As Integer
Dim Line1 As String
Option Explicit
Private Sub Command1_Click()
i = 0
Do While Not EOF(1)
Line Input #1, strLineOfText
Text1(i).Text = strLineOfText
i = i + 1
Loop
'Do While Not EOF(1)
' Line Input #1, strLineOfText
' Text1(i).Text = strLineOfText
' i = i + 1
'Loop
'Do While Not EOF(1) And Left$(Line1, 10) <> "Card Name:"
' Line Input #1, Line1
' Text1 = Line1
'Loop
End Sub
Private Sub Form_Load()
i = 0
Open "H:\Visual Basic\Magic Database\od_spoiler_en.txt" For Input As #1
End Sub
-
Mar 27th, 2003, 07:07 PM
#12
Fanatic Member
Don't open your file until you need to and close it when you are done!
VB Code:
Option Explicit
Dim strLineOfText As String
Dim i As Integer
Dim strFile As String
Private Sub Command1_Click()
i = 0
strFile = "H:\Visual Basic\Magic Database\od_spoiler_en.txt"
Open strFile For Input As #1
Do While Not EOF(1)
Line Input #1, strLineOfText
Text1(i).Text = strLineOfText
i = i + 1
Loop
Close #1
End Sub
I suspected that you did not have a control array on your form so I created one text box and got the same error you got.
Make sure you have several text boxes on your form with the same name!
If you put a text box on a form and then copy and paste the same text box on the same form, vb will ask if you want to create a control array. (CLICK ON YES!!!!!) A control array is just like an array, but with control.
You need to have a textbox control array for this to work!
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
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
|