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 -
Private Sub cmdAdd_Click()
-
-
strRepTree(j, 1) = cboSpecies.Text
-
If Val(txtAge) <> Int(Val(txtAge)) Or Not IsNumeric(txtAge) Then
-
MsgBox " Invalid Age"
-
txtAge = ""
-
Else
-
strRepTree(j, 2) = txtAge
-
End If
-
-
If Not IsNumeric(txtHeight) Or Val(txtHeight) < Val(txtBLC) Then
-
MsgBox "BLC value can not be greater than Height value "
-
txtHeight = ""
-
Else
-
strRepTree(j, 3) = txtHeight
-
End If
-
-
If Not IsNumeric(txtBLC) Then
-
MsgBox "Enter correct BLC value"
-
txtBLC = ""
-
Else
-
strRepTree(j, 4) = txtBLC
-
End If
-
-
If Not IsNumeric(txtDia) Then
-
MsgBox "Enter Correct Diameter"
-
txtDia = ""
-
Else
-
strRepTree(j, 5) = txtDia
-
End If
-
-
frmStandVolume.lstRepTreeSum.AddItem strRepTree(j, 1) & "," & strRepTree(j, 2) & "," & strRepTree(j, 3) & "," & strRepTree(j, 4) & "," & strRepTree(j, 5)
-
j = j + 1
-
-
'****************** This is where I believe my if statements needs to go to see if all the numbers are correct*************
-
intRepTreeRecs = j - 1
-
optHwd.Value = False
-
optSwd.Value = False
-
cboSpecies.Clear
-
txtAge = ""
-
txtHeight = ""
-
txtBLC = ""
-
txtDia = ""
2 1659
Nevermind. I got it working..
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: - Private Sub cmdAdd_Click()
-
-
strRepTree(j, 1) = cboSpecies.Text
-
If Val(txtAge) <> Int(Val(txtAge)) Or Not IsNumeric(txtAge) Then
-
MsgBox " Invalid Age"
-
txtAge = ""
-
Exit Sub
-
Else
-
strRepTree(j, 2) = txtAge
-
End If
-
-
If Not IsNumeric(txtheight) Or Val(txtheight) < Val(txtblc) Then
-
MsgBox "BLC value can not be greater than Height value "
-
txtheight = ""
-
Exit Sub
-
Else
-
strRepTree(j, 3) = txtheight
-
End If
-
-
If Not IsNumeric(txtblc) Then
-
MsgBox "Enter correct BLC value"
-
txtblc = ""
-
Exit Sub
-
Else
-
strRepTree(j, 4) = txtblc
-
End If
-
-
If Not IsNumeric(txtdia) Then
-
MsgBox "Enter Correct Diameter"
-
txtdia = ""
-
Exit Sub
-
Else
-
strRepTree(j, 5) = txtdia
-
End If
-
-
frmStandVolume.lstRepTreeSum.AddItem strRepTree(j, 1) & "," & _
-
strRepTree(j, 2) & "," & _
-
strRepTree(j, 3) & "," & _
-
strRepTree(j, 4) & "," & _
-
strRepTree(j, 5)
-
j = j + 1
-
-
'****************** This is where I believe my if statements needs
-
'to go to see if all the numbers are correct*************
-
-
intRepTreeRecs = j - 1
-
optHwd.Value = False
-
optSwd.Value = False
-
cboSpecies.Clear
-
txtAge = ""
-
txtheight = ""
-
txtblc = ""
-
txtdia = ""
-
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: - If cboSpecies <> "" And txtAge <> "" And txtheight <> "" And _
-
txtblc <> "" And txtdia <> "" Then
-
frmStandVolume.lstRepTreeSum.AddItem strRepTree(j, 1) & "," & _
-
strRepTree(j, 2) & "," & _
-
strRepTree(j, 3) & "," & _
-
strRepTree(j, 4) & "," & _
-
strRepTree(j, 5)
-
j = j + 1
-
-
'****************** This is where I believe my if statements needs
-
'to go to see if all the numbers are correct*************
-
-
intRepTreeRecs = j - 1
-
optHwd.Value = False
-
optSwd.Value = False
-
cboSpecies.Clear
-
txtAge = ""
-
txtheight = ""
-
txtblc = ""
-
txtdia = ""
-
End If
br,
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
|
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...
| |