Can someone plz explain how i would find out when 30lines have been writen to a text file? So every 30 lines, a msg box would pop up.
Thanx,
D!m
Printable View
Can someone plz explain how i would find out when 30lines have been writen to a text file? So every 30 lines, a msg box would pop up.
Thanx,
D!m
I know there has to be a better way to do it but if you get no replies then i guess a way is better then no way.
Dim sFirst, sSecond, sThird........, sThirty
Open "\file.txt" For Input As #7
Line Input #7, sfirst
If sthirty = "" Then
'sit on ur ass
else
Msgbox "There is something on line 30!"
Close #7
Maybe...
Write a function that does the writing to the file. It would have a for...next loop in with a counter to 30 and then message box would appear after the looping is done.
In the procedure that calls the function you could test to see if you need to write more or proceed when the function returns.
Just a suggestion.
Here's a way using mod which returns only the remainder of a division:
Dim x As Integer
Dim strMsg As String
Dim strInfo As String
x = 0 ' a counter
strMsg = "" ' message for messagebox
Open URFILE For Input As #1
' read the file until you get to EOF
Do Until EOF(1)
' if not at eof, then read line and increment counter
Line Input #1, strInfo
x = x + 1
If x Mod 30 = 0 Then
' x is evenly divisible by 30, ie a multiple
If strMsg = "" Then
' format the initial message
strMsg = "30 lines have been read"
Else
' format subsequent messages
strMsg = "30 more lines have been read"
End If ' strMsg = ""
' display the message box
MsgBox strMsg
End If ' mod(x)
Loop
Close #1
MsgBox "A total of " & Format(x, "0") & " lines were read"
How are you writing the lines?
What is your code?
A better approach would be to have a counter that increments every time you _write_ a RECORD.Quote:
Originally posted by fallnwrld
I know there has to be a better way to do it but if you get no replies then i guess a way is better then no way.
Dim sFirst, sSecond, sThird........, sThirty
Open "\file.txt" For Input As #7
Line Input #7, sfirst
If sthirty = "" Then
'sit on ur ass
else
Msgbox "There is something on line 30!"
Close #7
dim I as long
dim sText as string
i=1
Open "file.txt" for output as #6
for i = 1 to endofprint
print #6, text
if i mod 30 = 0 then msgbox "30 (more) records have been processed."
next i
Code:dim i as integer
dim LineStr as string
open Filename for input #1
do while not EOF(1)
line input #1, LineStr
i = i+1
if i = 30 then
msgbox "yo what up, this here file is at least 30 lines long!"
exit do
loop
close #1
Almost, Woss. You'll only report the first 30 lines, not every 30 lines.
if i = 30 then
i = 1
msgbox "bla bla"
Forgot your end if, Wayne.
Jhaus your a big help, has any of these techniques helped? Let us know!
I did exactly what HeSaidJoe suggested...and i think it's probably the best way.
Thanx guys,
D!m
it was wossname that did the trick with code....I just corrected an oversight it his/her code...
credit is not due me, but thanks for the thought.
All the best.