PDA

View Full Version : Bit a tough one



crag2804
12-10-2002, 03:15 PM
Tough firstly because I've no idea where to post this. I'm doing chemistry but as a drive to the "integrate computers into chemistry" ethos we've had to write a program in visual basic. I've no idea with this as all I've ever done is C.

My problem is when I leave one of my data input boxes empty the program dies.

I've done all the program and it works I just need to know a line that will pick up any errors and jump the :valueerror bit at the end. Once there it will print out the error message and won't die. Can anyone help.
Psedocode:

If error encounterd then goto valueerror.

Thanks anyone who can help



Dim constant As Single
Dim alpha1 As Single
Dim alpha2 As Single
Dim alpha3 As Single
Dim beff As Single
Dim v1 As Single
Dim v2 As Single
Dim v3 As Single
Dim counter As Integer
Dim testfile As String
Dim titlev1 As String
Dim titlev2 As String
Dim titlev3 As String
Dim titlebeff As String



titlev1 = "v1"
titlev2 = "v2"
titlev3 = "v3"
titlebeff = "B(eff)"
constant = conbox.Text
alpha1 = alpha1box.Text
alpha2 = alpha2box.Text
alpha3 = alpha3box.Text
testfile = "p:\rotat.txt"

Open testfile For Output As #1
Write #1, titlev1, titlev2, titlev3, titlebeff


For v1 = 0 To 2
For v2 = 0 To 2
For v3 = 0 To 2
beff = (constant - (alpha1 * (v1 + (1 / 2))) - (alpha2 * (v2 + (1 / 2))) - (alpha3 * (v3 + (2 / 2))))
Write #1, v1, v2, v3, beff
Next v3
Next v2
Next v1
Close #1


valueerror:
If Err.Number = 13 Then
Msg = "You have forgotten to fill in one of the boxes!"
MsgBox Msg
End If
Exit Sub

adrianxw
12-10-2002, 03:42 PM
You might want to try asking at www.programmersheaven.com

mepaco
12-10-2002, 03:55 PM
Here is a simple routine that closes some databases with error handling in it.


Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Error_Handler
datBOM1.Recordset.Close
datBOM1.Database.Close
datBOM2.Recordset.Close
datBOM2.Database.Close
Error_Handler:
If Err.Number = 91 Then Resume Next
End Sub

Hammer
12-10-2002, 07:40 PM
Doesn't your debugger help you?

Do you have something like:
On Error Goto valueerror