Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Control Help 1

Status
Not open for further replies.

ecugrad

MIS
Apr 17, 2001
191
0
0
US
If have ths piece of code below that I need some help putting some error control around.

If (ID=11744) or (ID = 1215) or (ID=1217) or (ID=1218) or (ID=1219) Then
arrTime = Split(ItemsWorked, ":")
Itemsworked = arrTime(0) * 60 + arrTime(1)
End If

The users should enter in numbers in the format of 12:13, if they do the code work and sums up fine. If they enter nothing or just one value such as 12 and does'nt ":" then it throws and error
 
For your version:
str = ItemsWorked
ra = arrTime

Code:
<%
	str = "22:19"
	ra = split(str,":")
	' check to see if there are exacty two items in the array - remember the arrays are zero based.
	if ubound(ra) <> 1 then
		response.write "error - to many or not enough colons"
	' if passed, check to ensure both values are numeric
	elseif not isNumeric(ra(0)) or not isNumeric(ra(1)) then
		response.write "error - hours and minutes must be numeric values"
	' if passed, check to ensure each item in the array is exactly 2 digits (i.e. 2:19 should be 02:19)
	elseif len(ra(0)) <> 2 or len(ra(1)) <> 2 then	
		response.write "error - hours and minutes must be exactly 2 digits"
	' if passed, check to ensure a valid hour and minute was entered
	elseif (ra(0) < 0 or ra(0)  > 23) or (ra(1) < 0 or ra(1)  > 59) then
		response.write "error - invalid hours or minutes"
	' if passed everything above, quote Homer Simpson
	else
		response.write "WOO HOO"
	end if
%>

Of course using a regEx would be best, I'm not the best at giving examples - but there are lots of people on these forums who know them well and may offer up an example as well (it will be A LOT shorter than what I wrote above)

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top