Click to See Complete Forum and Search --> : On Error GoTo....
Moses420ca
October 9th, 2001, 05:30 PM
what's wrong with this?
on error GoTo NoFTP
' just in case the FTP server is off-line
NoFTP: GoTo offline
offline = MsgBox("Sorry, I think the FTP server is Off-Line. Try back later.", vbRetryCancel, "Server offline")
If offline = vbRetry then
Command1.Value = 1
ElseIf offline = vbCancel then
End
End If
http://www.geocities.com/moses420ca/images/thumbnails/drewblue2.jpgThankz, Drew
Moses420ca@yahoo.ca?SUBJECT=I Love Your Stuff
Ryanitus
October 9th, 2001, 05:38 PM
Sub ConnectToFTP()
on error Goto NoFTP
...
...
NoFTP:
If Msgbox("message", vbRetryCancel) = vbRetry then
Command1.value = 1
End If
End Sub
Moses420ca
October 9th, 2001, 06:05 PM
ahh, so it's not the code but where you put the code. thanks, I did not know that.
http://www.geocities.com/moses420ca/images/thumbnails/drewblue2.jpgThankz, Drew
Moses420ca@yahoo.ca?SUBJECT=I Love Your Stuff
John G Duffy
October 9th, 2001, 06:18 PM
One thing I see wrong with it is the use of the "END" statement to terminate program execution. Microsoft Help says the only time the "END" statement should be used is in the Form_Load event of the startup form.
The "END" statement immediately terminates program execution leaving files opened, Databases active, memory allocations left dirty resulting in memory leaks and a host of other problems.
The correct way to terminate a application is to issue a "UNLOAD" command which will cause proper program termination freeing up acquired resources and closing files etc. If your application has multiple forms or uses its own memory management then the Form_Unload event should clean these things up as well as allowing VB to clean up.
Here is a simple routine that should be used in every Form_Unload event that will close all Forms allowing each form to go through its cleanup process.
'
' instead of the "END" statement do a
Unload me ' Terminate program execution
'
' then in the Form_Unload event
'
private Sub Form_Unload(Cancel as Integer)
Dim f as Form
for Each f In Forms
If f.Caption <> me.Caption then Unload f
next f
End Sub
'
' In the following example is a correct way to implement error handling for your problem
' MySub attempts to do something with the FTP Server which causes an error.
The error will automatically transfer control to routine NoFTP.
public Sub MySub()
on error GoTo NoFTP
' perform some code that causes an error. VB will automatically transfer
' control to routine NoFTP if an error occurs
'
' If you get here no error occured
Exit Sub
NoFTP:
offline = MsgBox("Sorry, I think the FTP server is Off-Line. Try back later.", vbRetryCancel, "Server offline")
If offline = vbRetry then
Command1.Value = 1
ElseIf offline = vbCancel then
Unload me
End If
End Sub
Another potential problem could be, but I can not tell from the sample code you supplied.
You do Command1.Value = 1
This should trigger a Command1_Click event but if you are already in the command1_Click event, it probably will not trigger the event. Even if it does you are getting into a recursive state which God knows what will happen depending on your code.
John G
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.