-
hi,
i have a text file called, hackingattempt.ooo first of all when the command button is clicked i need to kno if he file is there if it isn't i need to create it, once i have done this i want to apend this filw with the information from two labels and two textboxes, i have tried to use the following code to apend the file but it doesn't seem to work how can i inncorportae the information from the labels and text boxes into this file as well, and how do i check if he file excists ?
Code:
Open ("c:\hackingattempt.001") For Append As #1
a.writeline ("There was a invalid entry at")
a.writeline Label3.Caption + Label4.Caption
a.writeline text1.text + text2.text
Close #1
cheers to all that can help
Merlin ¿ :confused:
-
I would try using Print instead of a.writeline...
like:
Open ("c:\hackingattempt.001") For Append As #1
print #1, ("There was a invalid entry at")
print #1, Label3.Caption + Label4.Caption
print #1, text1.text + text2.text
close #1
That shoul work
-
<?>
Code:
Private Sub Command1_Click()
Dim intnum As Integer
intnum = FreeFile
'if it does not exist then create it
If Dir("c:\hackingattempt.001") = "" Then
Open "c:\hackingattempt.001" For Output As intnum
Print #intunm, "There was a invalid entry at"
Print #intnum, Label3.Caption & Label4.Caption
Print #intnum, text1.Text & text2.Text
'if you are adding you use +
'print #intnum, val(text1) + val(text2)
'you may want a space if you are just joining
'print intnum, label3.caption & " " & label4.caption
Close #intnum
'if it exists then append
Else
Open "c:\hackingattempt.001" For Append As intnum
Print #intunm, "There was a invalid entry at"
Print #intnum, Label3.Caption & Label4.Caption
Print #intnum, text1.Text & text2.Text
'if you are adding you use +
'print #intnum, val(text1) + val(text2)
'you may want a space if you are just joining
'print intnum, label3.caption & " " & label4.caption
Close #intnum
End If
End Sub
-
krushstone - thanks that is brilliant i didn;t relise that you could put a print statement in it
hesaidjoe, i like this one and i will use it but i have a problem with it when i run it and it creates the file i have the follwing error
bad name or number
with this line in both occurances in the code
Code:
Print #intunm, "There was a invalid entry at"
any suggestions
Merlin ¿ :confused:
-
Yep, it's because of this:
Code:
Open "c:\hackingattempt.001" For Output As intnum
Replace it with
Open "c:\hackingattempt.001" For Output As #intnum
Also for the Append one:
Open "c:\hackingattempt.001" For Append As #intnum
ok have fun Merlin!
-
cheers jop i managed to fix it in the end by replaceing the intnum with #1 and this fixed it
thanks anyway
Merlin ¿ :confused:
-
I suggest using #intnum tho.. because that VB handles the FileNumber and always take a FreeFile number... but it's up to you wich to use :)
-
cheers for your help :o)
Merlin ¿ :confused: