473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Someone pls help with my program

Can someone pls help me with some validation that im having a few technical problems with in my program.

First of all, I will explain to you a little about what my program is suppose to do. It consists of a form with two text boxes that allow the user to enter numbers. These numbers will either be added, subtracted, divided or multiplied by each other. The user will type which operant that they wish to use by using an additional text boxed provided on the form. The user will then click the calculate button which will display the result in another text box.

I want to add validation to stop the user from dividing a number by zero so that it stops the program from crashing and giving me a warning message about overflowException. I have copied and pasted my code for you to view. Thanks

Dim Total As Integer 'Declaration of Variables
Dim FirstNumber As Double
Dim SecondNumber As Double
Dim Operation As String

If IsNumeric(txtANumber.Text) = True Then

FirstNumber = txtANumber.Text

ElseIf IsNumeric(txtANumber.Text) = False Then

MsgBox("Please Enter a Numeric Value!", 48)

End If



If IsNumeric(txtBNumber.Text) = True Then

SecondNumber = txtBNumber.Text

ElseIf IsNumeric(txtBNumber.Text) = False Then

MsgBox("Please Enter a Numeric Value!", 48)



End If

If SecondNumber <= 0 Then

MsgBox("Please Enter a Numeric Greater than 0!", 48)


End If


Operation = txtOperation.Text

If Operation = "add" Then
Total = FirstNumber + SecondNumber
txtCurrentTotal.Text = Total


End If

If Operation = "subtract" Then
Total = FirstNumber - SecondNumber
txtCurrentTotal.Text = Total

End If

If Operation = "multiply" Then
Total = FirstNumber * SecondNumber
txtCurrentTotal.Text = Total
End If

If Operation = "divide" Then
Total = FirstNumber / SecondNumber
txtCurrentTotal.Text = Total

End If



End Sub
Nov 10 '06 #1
2 1339
willakawill
1,646 1GB
Can someone pls help me with some validation that im having a few technical problems with in my program.
Hi. This should work:
Expand|Select|Wrap|Line Numbers
  1. Dim Total As Integer 'Declaration of Variables
  2. Dim FirstNumber As Double
  3. Dim SecondNumber As Double
  4. Dim Operation As String
  5.  
  6. If IsNumeric(txtANumber.Text) Then
  7.     FirstNumber = CDbl(txtANumber.Text)
  8. Else
  9.     MsgBox "Please Enter a Numeric Value!", 48
  10.     txtANumber.Text = ""
  11.     txtANumber.SetFocus
  12.     Exit Sub
  13. End If
  14.  
  15.  
  16.  
  17. If IsNumeric(txtBNumber.Text) Then
  18.     SecondNumber = CDbl(txtBNumber.Text)
  19. Else
  20.     MsgBox "Please Enter a Numeric Value!", 48
  21.     txtBNumber.Text = ""
  22.     txtBNumber.SetFocus
  23.     Exit Sub
  24. End If
  25.  
  26. If SecondNumber = 0 AND txtOperation.Text = "divide" Then
  27.     MsgBox "Please Enter a number other than 0!", 48
  28.     txtBNumber.Text = ""
  29.     txtBNumber.SetFocus
  30.     Exit Sub
  31. End If
  32.  
  33.  
  34. Operation = txtOperation.Text
  35.  
  36. Select Case Operation
  37.     Case "add"
  38.         Total = FirstNumber + SecondNumber
  39.         txtCurrentTotal.Text = Total
  40.  
  41.     Case "subtract"
  42.         Total = FirstNumber - SecondNumber
  43.         txtCurrentTotal.Text = Total
  44.  
  45.     Case "multiply"
  46.         Total = FirstNumber * SecondNumber
  47.         txtCurrentTotal.Text = Total
  48.  
  49.     Case "divide"
  50.         Total = FirstNumber / SecondNumber
  51.         txtCurrentTotal.Text = Total
  52.  
  53.     Case Else
  54.         MsgBox "Unknown operator"
  55. End Select
  56.  
Nov 10 '06 #2
albertw
267 100+
Hi. This should work:
Expand|Select|Wrap|Line Numbers
  1. Dim Total As Integer 'Declaration of Variables
  2. Dim FirstNumber As Double
  3. Dim SecondNumber As Double
  4. Dim Operation As String
  5.  
  6. If IsNumeric(txtANumber.Text) Then
  7.     FirstNumber = CDbl(txtANumber.Text)
  8. Else
  9.     MsgBox "Please Enter a Numeric Value!", 48
  10.     txtANumber.Text = ""
  11.     txtANumber.SetFocus
  12.     Exit Sub
  13. End If
  14.  
  15.  
  16.  
  17. If IsNumeric(txtBNumber.Text) Then
  18.     SecondNumber = CDbl(txtBNumber.Text)
  19. Else
  20.     MsgBox "Please Enter a Numeric Value!", 48
  21.     txtBNumber.Text = ""
  22.     txtBNumber.SetFocus
  23.     Exit Sub
  24. End If
  25.  
  26. If SecondNumber <= 0 Then
  27.     MsgBox "Please Enter a Numeric Value!", 48
  28.     txtBNumber.Text = ""
  29.     txtBNumber.SetFocus
  30.     Exit Sub
  31. End If
  32.  
  33.  
  34. Operation = txtOperation.Text
  35.  
  36. Select Case Operation
  37.     Case "add"
  38.         Total = FirstNumber + SecondNumber
  39.         txtCurrentTotal.Text = Total
  40.  
  41.     Case "subtract"
  42.         Total = FirstNumber - SecondNumber
  43.         txtCurrentTotal.Text = Total
  44.  
  45.     Case "multiply"
  46.         Total = FirstNumber * SecondNumber
  47.         txtCurrentTotal.Text = Total
  48.  
  49.     Case "divide"
  50.         Total = FirstNumber / SecondNumber
  51.         txtCurrentTotal.Text = Total
  52.  
  53.     Case Else
  54.         MsgBox "Unknown operator"
  55. End Select
  56.  
additionally, comparisons are case sensitive
might use
Select Case UCase(Operation) of select Case LCase(Operation) instead
to avoid plain typing errors
Nov 10 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: blockhead | last post by:
We are looking for someone to either complete a php forum program or create one for us. There isn't really anything that is available that suits our needs and we have specific wants. If you are...
0
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this...
3
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create...
9
by: TCMA | last post by:
I am looking for some tools to help me understand source code of a program written in C++ by someone else. Are there any non-commercial, open source C or C++ tools to reverse engineer C or C++...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
2
by: shblack | last post by:
Please can someone help me with this program. I am in a JAVA programming class and I am having a heck of a time. I am still having a problem with the basic concepts of JAVA but the teacher continues...
40
by: aslamhenry | last post by:
please key in any 5 digits number : 56789 and the ouput is 5678 9 567 89 56 789 5 6789
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
30
by: Anarki | last post by:
The following is the program i am trying to compile //restrict.c #include <stdio.h> int main() { char arr = "Qualifiers" char * restrict p = arr; int i = 0; for(; i < 10; ++i)
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.