473,569 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Someone pls help with my program

2 New Member
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 overflowExcepti on. 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(txtAN umber.Text) = True Then

FirstNumber = txtANumber.Text

ElseIf IsNumeric(txtAN umber.Text) = False Then

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

End If



If IsNumeric(txtBN umber.Text) = True Then

SecondNumber = txtBNumber.Text

ElseIf IsNumeric(txtBN umber.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.Te xt

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 1344
willakawill
1,646 Top Contributor
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 Contributor
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
1916
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 interested, we can supply you a link to our unfinished program to see if you could finish it or take a look at it and our current forum program to see...
0
1487
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 document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download Format is better on the above link. I'm looking for...
3
2021
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 some MySQL to create the first table: the players table. It will need to include (as a minimum): - ID (unique)
9
4981
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++ programs with source codes on linux? i.e. It parses any sized C or C++ project to help reverse engineer, document, draw UML diagram and understand it...
2
2106
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 my other includes then I get lots of errors like C2011: 'fd_set' : 'struct' type redefinition warning C4005: 'FD_CLR' : macro redefinition which I...
2
1591
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 to give us difficult assignments with out any help. Here is the assignment: Write a class named 'Player' that has two attributes, 'name' (which...
40
2296
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
2029
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 prompt output from raw_input goes to stderr. Consider the following test program: === Start test.py === import sys
30
2236
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
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.