Ok so i'm trying to validate numeric input through the use of input boxes. I'm trying to use a try catch statement to catch anything thats non numeric and it works fine. But the only problem i'm having is looping through the array. For example an input box pops up asking John for hours worked, enters 20 and clicks ok. Then loops to the next inputbox asking Jake for hours worked, enters 30 clicks ok. Now when the next question comes up for 'Jeff' If he clicks 'ok' 'cancel' or enters a non integer it catches it, displays 'Please enter a numeric value' then goes to the next person. Once it catches an error I need the loop to reask that same question to the same person before proceeding to the next. Anyone give me any tips? Theres a lot more code to it, but i just included the arrays and the subprocedure to get the hours worked. -
-
Dim names() As String = {"John", "Jake", "Jeff", "Juan", "Leo", _
-
"Sally", "Tom", "James", "Brandon", "Julius"}
-
-
Dim amount(9) As Integer
-
-
Sub getEachName()
-
-
Dim intCount As Integer 'loop counter
-
'Add header to list box
-
lstTotals.Items.Add("Name and Hours Worked")
-
-
'Get the total hours and put them in a list box with name
-
-
For intCount = 0 To 9
-
Try
-
amount(intCount) = CInt(InputBox("Enter amount of hours" _
-
& vbLf & names(intCount)))
-
lstTotals.Items.Add(names(intCount) & " " & amount(intCount))
-
Catch Exception As SystemException
-
MessageBox.Show("Please enter a numeric value.")
-
-
------> ????????????????
-
-
End Try
-
Next intCount
-
-
End Sub
-
4 3431
Try this: -
Private Sub Form_Load()
-
-
Dim names(9) As String
-
-
Dim amount(9) As Integer
-
-
names(0) = "John"
-
names(1) = "Jake"
-
names(2) = "Jeff"
-
names(3) = "Juan"
-
names(4) = "Leo"
-
names(5) = "Sally"
-
names(6) = "Tom"
-
names(7) = "James"
-
names(8) = "Brandon"
-
names(9) = "Julius"
-
-
Dim intCount As Integer 'loop counter
-
-
Dim TempNum As String
-
-
'Add header to list box
-
lstTotals.AddItem "Name and Hours Worked"
-
-
'Get the total hours and put them in a list box with name
-
For intCount = 0 To 9
-
TempStr = InputBox("Enter amount of hours" & vbLf & names(intCount))
-
If TempStr = vbNullString Then
-
Exit For
-
ElseIf Not IsNumeric(TempStr) Then
-
MsgBox ("Please enter a numeric value.")
-
intCount = intCount - 1
-
Else
-
amount(intCount) = CInt(TempStr)
-
lstTotals.AddItem names(intCount) & " " & amount(intCount)
-
End If
-
Next intCount
-
-
End Sub
-
This code was adapted for Visual Basic 6, but should still work in VB.NET.
Alright so with a few changes i got that part working. Now my next problem i've come across. I got the highest hours worked to display the persons name and hours worked in the label. Now when i'm trying to do it for fewest hours worked, the name of the person with the fewest hours wont display. Anyone point me in the right direction? -
Sub fewesthours()
-
Dim intCount As Integer
-
Dim intMinimum As Integer = hours(0)
-
Dim strName As String
-
-
For intCount = 0 To (hours.Length - 1)
-
If hours(intCount) < intMinimum Then
-
intMinimum = hours(intCount)
-
strName = names(intCount).ToString()
-
End If
-
Next intCount
-
-
lblfewhours.Text = "Fewest Hours Worked:" & strName & intMinimum
-
-
End Sub
-
Hi,
You have not assigned strName with the Names(0)...
You code will not work if the first array element is Least..
anyway, check this modified code.. -
Sub fewesthours()
-
Dim intCount As Integer
-
Dim intMinimum As Integer = hours(0)
-
Dim strName As String = names(0).ToString()
-
-
For intCount = 0 To (hours.Length - 1)
-
If hours(intCount) < intMinimum Then
-
intMinimum = hours(intCount)
-
strName = names(intCount).ToString()
-
End If
-
Next intCount
-
-
lblfewhours.Text = "Fewest Hours Worked:" & strName & intMinimum
-
-
End Sub
-
Regards
Veena
wow... lol thanks qveen. ;)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: The Plankmeister |
last post by:
Hi...
What's the best method of validating input characters? I would like to
prevent users submitting exotic characters (such as those acquired on
Windows Systems by pressing ALT+) and thought...
|
by: Gleep |
last post by:
Hi PHP coders,
I've got an issue I'm stuck with. Imagine there is a large form that has 5 columns and 20 rows.
In each row there is a check box - then 4 input fields. I already have the code...
|
by: Mark |
last post by:
Hi,
Im trying to validate a form, all the validating works apart from one field.
This particular field must consist of the first 2 characters as letters, &
the following 5 as numbers. And if it...
|
by: Lüpher Cypher |
last post by:
Hi,
I have a form:
<form .. onSubmit="return onFormSubmit(this)">
<input type="checkbox" name="a" value="1" />
<input type="checkbox" name="a" value="2" />
...
<input type="checkbox" name="a"...
|
by: platostoteles |
last post by:
Hallo NG,
I am new to JavaScript and would really appreciate any help to solve my
problem.
I am using the blow code in my form to validate form fields. What I
would like to accomplish is that...
|
by: stathis gotsis |
last post by:
Hello everyone,
I am tying to come up with an elegant way to process some input data that
come from a form. When the user hits the 'Submit' button, i want the form to
appear again with the...
|
by: chuck |
last post by:
I need some help with validating user input. I am writing a C computer
program for an intro to C course. Here is the situation. I am
creating an application that will do currency conversions. ...
|
by: Advo |
last post by:
Hi there. Having a few issues and cannot see a way to actually do the
following.
ive duplicated a simple questionnaire as shown here:
http://www.hackeradio.com/questionnaire.html
meaning...
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first...
|
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: 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...
|
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: 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....
|
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...
| |