|
-
May 3rd, 2005, 10:10 PM
#1
Thread Starter
Banned
Trouble With Text Files
Ok i got great help earlier but having a problem o.0
Private Sub Form_Load()
Dim sTemp As String
Dim sTotalString As String
Shell "C:\File.bat > C:\Irc.txt"
Open "C:\Irc.txt" For Input As #1
Do While EOF(1) = False
Line Input #1, sTemp
sTotalString = sTotalString & sTemp
Text1.Text = sTotalString
Loop
End Sub
The First line in the file its opening its blank so i dont think its reading that because of it...The only way i can get output into the textbox is if i click the button twice..
Last edited by ThaRubby; May 3rd, 2005 at 10:14 PM.
-
May 3rd, 2005, 10:17 PM
#2
Re: Trouble With Text Files
First, indent your code, and use code tags.
VB Code:
dim ff as integer
ff = freefile
Open "C:\Irc.txt" For Input As #ff
Do While EOF(1) = False
Line Input #1, sTemp
sTotalString = sTotalString & sTemp
Loop
Close #1
text1.text = sTotalString
You could also read it all at once, with a choice of ways to parse it into lines.
This also counts the lines!
VB Code:
Option Explicit
Private Sub Form_Load()
Dim ff As Integer
Dim strBuff As String
Dim str() As String
ff = FreeFile
Open "C:\Irc.txt" For Input As #ff
strBuff = Input(LOF(ff), ff)
Close #ff
' ----------------- two ways to skin a cat --------------
MsgBox "Lines = " & Len(strBuff) - Len(Replace(strBuff, vbCrLf, "x")) + 1
' -------------------------------------------------------
str() = Split(strBuff, vbCrLf)
MsgBox "There are " & UBound(str) + 1 & " lines in the file"
End Sub
-
May 3rd, 2005, 10:17 PM
#3
Lively Member
Re: Trouble With Text Files
Why don't you load the entire file at once?
VB Code:
Open "C:\Irc.txt" For Input As #1
text1.text = Input(LOF(1), #1)
Close #1
-
May 3rd, 2005, 10:20 PM
#4
Re: Trouble With Text Files
You changed it!
If you put the code into the form_activate event, it will already be shown when you add the text. I thought it was on a click of a button.
What does the bat file do? It probably isn't finishing by the time you read irc.txt
-
May 3rd, 2005, 10:21 PM
#5
Thread Starter
Banned
Re: Trouble With Text Files
microalps, i tried that it didnt work. dglienna yea it is its echoed into the text file just fine but wont display in the text file..
-
May 3rd, 2005, 10:25 PM
#6
Re: Trouble With Text Files
i wrote a whole topic about this in the codebank..
dim ff as integer
Open "C:\Irc.txt" For binary As #ff
text1.text = Input(LOF(ff), #ff)
Close #ff
-
May 3rd, 2005, 10:29 PM
#7
Thread Starter
Banned
Re: Trouble With Text Files
-
May 3rd, 2005, 10:30 PM
#8
Re: Trouble With Text Files
It doesn't have time to echo and read at the same time.
Put the echo into the form load, and the text in a command button.
That should be enough time. Otherwise you need to wait a few seconds.
You could also use
VB Code:
"Start MyBatchFile.bat /wait"
-
May 3rd, 2005, 10:31 PM
#9
Lively Member
Re: Trouble With Text Files
Is the multiline property of text1 set to True? If you don't want it to have any enters then use this code
VB Code:
Open "C:\Irc.txt" For Input As #1
text1.text = Replace(Input(LOF(1), #1), vbCrLf, "")
Close #1
This will remove the enters from the input!
-
May 3rd, 2005, 10:33 PM
#10
Thread Starter
Banned
Re: Trouble With Text Files
Yes it was multiple line.
Open "C:\Irc.txt" For Input As #1
text1.text = Replace(Input(LOF(1), #1), vbCrLf, "")
Close #1
Worked!
-
May 3rd, 2005, 10:35 PM
#11
Lively Member
Re: Trouble With Text Files
You're welcome. Hope my input didn't confuse you though... Good luck on the rest of your project!
-
May 3rd, 2005, 10:45 PM
#12
Re: Trouble With Text Files
Open "C:\Irc.txt" For Input As #1
text1.text = Replace(Input(LOF(1), #1), vbCrLf, vbnullstring)
Close #1
^^just optimized it a pinch
but seriously you should use binary instead
Open "C:\Irc.txt" For binary As #1
text1.text = Replace(Input(LOF(1), #1), vbCrLf, vbnullstring)
Close #1
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
|