 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Hack-Addict Master Cheater
Reputation: 0
Joined: 20 Nov 2007 Posts: 287
|
Posted: Sat Dec 15, 2007 2:50 am Post subject: Visual basic prob, help please |
|
|
Hey, im trying to make it so that, if there's an error, that it will make the file, so like, if they don't have a file, and it comes up with error 53, that it will make the file, here's the code im trying to use...
| Code: | Private Sub Form_Load()
Dim ContentFile
Open "C:\Tutorial\Testfile.txt" For Input As #1
Input #1, ContentFile
Text1.Text = ContentFile
Close #1
If Text1.Text = "Lol test" Then
Form1.Show
Unload Me
Else
If Err.Number = 53 Then
Dim SaveFile As Long
SaveFile = FreeFile()
Open "C:\Tutorial\TestFile.txt" For Output As #SaveFile
Print #SaveFile, Text1.Text
Close #SaveFile
End If
End If
End Sub
|
Ive seen it done before, i just don't know why it won't work for me... Yes i googled it, Yes i searched it, couldent find an answer...
Please help T_T
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Dec 15, 2007 6:12 am Post subject: |
|
|
You sure it's error 53? Error 53 is bad network path and from looking at your code, it looks like, if any error would happen, it would be error 76. (Path not found.)
Also, Open will not create a directory if it does not exist, so that might also be a reason you are getting errors, you can do something like this instead to try to fix that though:
| Code: | Private Sub Form_Load()
On Error GoTo ErrHandle
Dim strFileContent() As String
Dim cFile As Long
Dim iLineCount As Long
'// Get A Valid File Handle
cFile = FreeFile
'// Open The File For Reading
Open "C:/Tutorial/TestFile.txt" For Input As #cFile
Do While Not EOF(cFile)
'// Resize String Array During Read
iLineCount = iLineCount + 1
ReDim Preserve strFileContent(iLineCount - 1)
Input #cFile, strFileContent(iLineCount - 1)
Loop
Close #cFile
Text1.Text = Join(strFileContent, vbCrLf)
'// Check Text For String
If Text1.Text = "Lol test" Then
Form1.Show
Unload Me
End If
Exit Sub
ErrHandle:
If Err.Number = 76 Then
'// Make The Directory If Needed
If Dir$("C:/Tutorial", vbDirectory) = vbNullString Then
MkDir "C:/Tutorial"
End If
'// Path Was Invalid, Create File
cFile = FreeFile
Open "C:/Tutorial/TestFile.txt" For Output As #1
Close #1
Else
MsgBox Err.Number & ": " & Err.Description
End If
End Sub |
Only tested it really quickly after writing it, looks to be working fine though.
_________________
- Retired. |
|
| Back to top |
|
 |
Hack-Addict Master Cheater
Reputation: 0
Joined: 20 Nov 2007 Posts: 287
|
Posted: Sat Dec 15, 2007 12:42 pm Post subject: |
|
|
| Wiccaan wrote: | You sure it's error 53? Error 53 is bad network path and from looking at your code, it looks like, if any error would happen, it would be error 76. (Path not found.)
Also, Open will not create a directory if it does not exist, so that might also be a reason you are getting errors, you can do something like this instead to try to fix that though:
| Code: | Private Sub Form_Load()
On Error GoTo ErrHandle
Dim strFileContent() As String
Dim cFile As Long
Dim iLineCount As Long
'// Get A Valid File Handle
cFile = FreeFile
'// Open The File For Reading
Open "C:/Tutorial/TestFile.txt" For Input As #cFile
Do While Not EOF(cFile)
'// Resize String Array During Read
iLineCount = iLineCount + 1
ReDim Preserve strFileContent(iLineCount - 1)
Input #cFile, strFileContent(iLineCount - 1)
Loop
Close #cFile
Text1.Text = Join(strFileContent, vbCrLf)
'// Check Text For String
If Text1.Text = "Lol test" Then
Form1.Show
Unload Me
End If
Exit Sub
ErrHandle:
If Err.Number = 76 Then
'// Make The Directory If Needed
If Dir$("C:/Tutorial", vbDirectory) = vbNullString Then
MkDir "C:/Tutorial"
End If
'// Path Was Invalid, Create File
cFile = FreeFile
Open "C:/Tutorial/TestFile.txt" For Output As #1
Close #1
Else
MsgBox Err.Number & ": " & Err.Description
End If
End Sub |
Only tested it really quickly after writing it, looks to be working fine though. |
EDIT: Got it working, i changed the 76 to 53, and made it so, if that error pops up, to write the text file... here's the code i used, works perfectly
| Code: | Private Sub Form_Load()
On Error GoTo ErrHandle
Dim strFileContent() As String
Dim cFile As Long
Dim iLineCount As Long
'// Get A Valid File Handle
cFile = FreeFile
'// Open The File For Reading
Open "C:/Tutorial/TestFile.txt" For Input As #cFile
Do While Not EOF(cFile)
'// Resize String Array During Read
iLineCount = iLineCount + 1
ReDim Preserve strFileContent(iLineCount - 1)
Input #cFile, strFileContent(iLineCount - 1)
Loop
Close #cFile
Text1.Text = Join(strFileContent, vbCrLf)
'// Check Text For String
If Text1.Text = "Lol test" Then
Form2.Show
Unload Me
End If
Exit Sub
ErrHandle:
If Err.Number = 53 Then
'// Make The Directory If Needed
If Dir$("C:/Tutorial", vbDirectory) = vbNullString Then
MkDir "C:/Tutorial"
End If
'// Path Was Invalid, Create File
cFile = FreeFile
Open "C:/Tutorial/SavedFile.txt" For Output As #1
Print #1, "Lol test1"
Close #1
Else
MsgBox Err.Number & ": " & Err.Description
Form2.Show
cFile = FreeFile
Open "C:/Tutorial/SavedFile.txt" For Output As #1
Print #1, "Lol test1"
Close #1
End If
End Sub |
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sat Dec 15, 2007 9:02 pm Post subject: Re: Visual basic prob, help please |
|
|
| Hack-Addict wrote: | Hey, im trying to make it so that, if there's an error, that it will make the file, so like, if they don't have a file, and it comes up with error 53, that it will make the file, here's the code im trying to use...
| Code: | Private Sub Form_Load()
Dim ContentFile
Open "C:\Tutorial\Testfile.txt" For Input As #1
Input #1, ContentFile
Text1.Text = ContentFile
Close #1
If Text1.Text = "Lol test" Then
Form1.Show
Unload Me
Else
If Err.Number = 53 Then
Dim SaveFile As Long
SaveFile = FreeFile()
Open "C:\Tutorial\TestFile.txt" For Output As #SaveFile
Print #SaveFile, Text1.Text
Close #SaveFile
End If
End If
End Sub
|
Ive seen it done before, i just don't know why it won't work for me... Yes i googled it, Yes i searched it, couldent find an answer...
Please help T_T |
Its supose to be error 76 cause I checked.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|