473,327 Members | 1,892 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,327 software developers and data experts.

If Statements

15
I have a program that allows the user to enter data I am using if statements that only will allow the user to enter integers and numbers if its greater than other and that works fine if the number or value is incorrect then a msg box appears. I have it so that if the number is wrong it takes the invalid number out of the test box.. I need to have it so that the user can enter the values over and over again. so the text boxes need to be cleared after the enter button is clicked. I have it now so that every time enter is clicked it clears the txt boxes but i only want them emptied once all the values are correct. I dont know how to do this with a if statement. I dont know how to tell it that the values are correct.. this is the code i am using
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2.  
  3.     strRepTree(j, 1) = cboSpecies.Text
  4. If Val(txtAge) <> Int(Val(txtAge)) Or Not IsNumeric(txtAge) Then
  5.     MsgBox " Invalid Age"
  6.     txtAge = ""
  7. Else
  8.     strRepTree(j, 2) = txtAge
  9. End If
  10.  
  11. If Not IsNumeric(txtHeight) Or Val(txtHeight) < Val(txtBLC) Then
  12.     MsgBox "BLC value can not be greater than Height value "
  13.     txtHeight = ""
  14. Else
  15.     strRepTree(j, 3) = txtHeight
  16. End If
  17.  
  18. If Not IsNumeric(txtBLC) Then
  19.     MsgBox "Enter correct BLC value"
  20.     txtBLC = ""
  21. Else
  22.     strRepTree(j, 4) = txtBLC
  23. End If
  24.  
  25. If Not IsNumeric(txtDia) Then
  26.     MsgBox "Enter Correct Diameter"
  27.     txtDia = ""
  28. Else
  29.     strRepTree(j, 5) = txtDia
  30. End If
  31.  
  32.     frmStandVolume.lstRepTreeSum.AddItem strRepTree(j, 1) & "," & strRepTree(j, 2) & "," & strRepTree(j, 3) & "," & strRepTree(j, 4) & "," & strRepTree(j, 5)
  33.    j = j + 1
  34.  
  35. '****************** This is where I believe my if statements needs to go to see if all the numbers are correct************* 
  36.     intRepTreeRecs = j - 1
  37.     optHwd.Value = False
  38.     optSwd.Value = False
  39.     cboSpecies.Clear
  40.     txtAge = ""
  41.     txtHeight = ""
  42.     txtBLC = ""
  43.     txtDia = ""
Dec 23 '09 #1
2 1659
dawn123
15
Nevermind. I got it working..
Dec 23 '09 #2
Guido Geurs
767 Expert 512MB
dear,

The first IF's are checking for a valid value.
if the value is wrong, just quit the SUB in each If like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2.  
  3.     strRepTree(j, 1) = cboSpecies.Text
  4.     If Val(txtAge) <> Int(Val(txtAge)) Or Not IsNumeric(txtAge) Then
  5.         MsgBox " Invalid Age"
  6.         txtAge = ""
  7.         Exit Sub
  8.     Else
  9.         strRepTree(j, 2) = txtAge
  10.     End If
  11.  
  12.     If Not IsNumeric(txtheight) Or Val(txtheight) < Val(txtblc) Then
  13.         MsgBox "BLC value can not be greater than Height value "
  14.         txtheight = ""
  15.         Exit Sub
  16.     Else
  17.         strRepTree(j, 3) = txtheight
  18.     End If
  19.  
  20.     If Not IsNumeric(txtblc) Then
  21.         MsgBox "Enter correct BLC value"
  22.         txtblc = ""
  23.         Exit Sub
  24.     Else
  25.         strRepTree(j, 4) = txtblc
  26.     End If
  27.  
  28.     If Not IsNumeric(txtdia) Then
  29.         MsgBox "Enter Correct Diameter"
  30.         txtdia = ""
  31.         Exit Sub
  32.     Else
  33.         strRepTree(j, 5) = txtdia
  34.     End If
  35.  
  36.     frmStandVolume.lstRepTreeSum.AddItem strRepTree(j, 1) & "," & _
  37.                                         strRepTree(j, 2) & "," & _
  38.                                         strRepTree(j, 3) & "," & _
  39.                                         strRepTree(j, 4) & "," & _
  40.                                         strRepTree(j, 5)
  41.    j = j + 1
  42.  
  43. '****************** This is where I believe my if statements needs
  44. 'to go to see if all the numbers are correct*************
  45.  
  46.         intRepTreeRecs = j - 1
  47.         optHwd.Value = False
  48.         optSwd.Value = False
  49.         cboSpecies.Clear
  50.         txtAge = ""
  51.         txtheight = ""
  52.         txtblc = ""
  53.         txtdia = ""
  54. End Sub
Or you can check if all the textboxes have a value (the are correct because they are checked by the previous IF's.
So you can enter in your exist code:

Expand|Select|Wrap|Line Numbers
  1.     If cboSpecies <> "" And txtAge <> "" And txtheight <> "" And _
  2.         txtblc <> "" And txtdia <> "" Then
  3.         frmStandVolume.lstRepTreeSum.AddItem strRepTree(j, 1) & "," & _
  4.                                         strRepTree(j, 2) & "," & _
  5.                                         strRepTree(j, 3) & "," & _
  6.                                         strRepTree(j, 4) & "," & _
  7.                                         strRepTree(j, 5)
  8.    j = j + 1
  9.  
  10. '****************** This is where I believe my if statements needs
  11. 'to go to see if all the numbers are correct*************
  12.  
  13.         intRepTreeRecs = j - 1
  14.         optHwd.Value = False
  15.         optSwd.Value = False
  16.         cboSpecies.Clear
  17.         txtAge = ""
  18.         txtheight = ""
  19.         txtblc = ""
  20.         txtdia = ""
  21.     End If
br,
Dec 23 '09 #3

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

Similar topics

6
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
9
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
39
by: slogging_away | last post by:
Hi - I'm running Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32, and have a script that makes numerous checks on text files, (configuration files), so discrepancies can be reported. The script...
0
by: Fuzzyman | last post by:
Hello all, The following is a copy of a blog entry. It's asking a question about future statements and the built in compile function. I'd appreciate any pointers or comments about possible...
20
by: Neroku | last post by:
Hello, i would like to know what the serious definition of statements and expressions is: i know an expression are evaluated to a value, i.e: 1 == 2 5+7 foo( 1,2) and a statement is...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
3
by: Dmitri | last post by:
Hello! I have a developer that is playing around with some SQL statements using VB.NET. He has a test table in a SQL 2000 database, and he has about 2000 generated INSERT statements. When the...
0
by: Gary Herron | last post by:
Ohad Frand wrote: There is no way you can consider 'elif', 'else', 'except', and 'from' statements. However, as someone pointed out, the kwlist from the keyword module is the closest thing we...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
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: 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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.