|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can somebody help me?
Ok. I have a slight problem...
The code i have is not based on any type of coding it just is a rough so that i can later re-encode it to work in a different language but i am struggling to get the correct err(). The function err(1) to err(5) is either true or false depending on what has been entered in the first place. The code is really simple its just i can't get my head round which way will it be correct or false. here is my code: Code:
1 Input code; length = Len(code) 2 For index = 1 To 5; err(index) = False; Next index 3 error = False 4 If length = 0 Then 5 Output “Empty string is not allowed” 6 error = True 7 Else 8 If length <> 5 Then 9 Output “The string should be 5 characters long” 10 error = True 11 Else 12 ch1 = 1st character of code; ch2 = 2nd character of code 13 ch3 = 3rd character of code; ch4 = 4th character of code 14 ch5 = 5th character of code 15 If ch1 < “0” Or ch1 > “9” Or ch2 < “0” Or ch2 > “9” Then 16 err(1) = True 17 If ch1 < “A” Or ch1 > “Z” Or ch2 < “A” Or ch2 > “Z” Then 18 err(2) = True 19 End If 20 Else 21 err(2) = True 22 End If 23 If ch3 < “0” Or ch3 > “9” Then err(3) = True End If 24 If ch4 < “0” Or ch4 > “9” Then err(4) = True End If 25 If ch5 < “0” Or ch5 > “9” Then err(5) = True End If 26 If err(1) And err(2) Then 27 Output “Invalid country” 28 error = True 29 Else 30 If err(1) Then 31 Output “Overseas Centre” 32 Else 33 Output “UK Centre” 34 End If 35 End If 36 For i = 3 To 5 37 If err(i) Then 38 Output “Invalid”, i, “th character” 39 error = True 40 End If ok so for example if i input MV394 i will get the following (i think please do tell if i am going wrong) err(1) is True err(2) is False err(3) is False err(4) is False err(5) is False and the variable error will be: error = False Now i am not sure this is correct because i am still kinda confused.... Some dude wanted me to have a look at it to help him but i am baffled (just a little bit of a n00b i know..) so my question to you is what would be the output considering the code is case sensitive for: K93621 (i think its all false apart from the error var as it needs to be True) and Ab149 (Same here.. But am not sure... Please help) I thank thee in advance, THANK YOU!! xelo Last edited by Lafinboy : May 12th, 2007 at 03:37 AM. Reason: Added code tags |
|
#2
|
||||
|
||||
|
--moved to the general Programing Help forum, that's not ASP nor VB.
hello and welcome to aspfree, here is more readable version of the code with indentation: Code:
Input code; length = Len(code); For index = 1 To 5 err(index) = False; Next index error = False If length = 0 Then Output “Empty string is not allowed” error = True Else If length <> 5 Then Output “The string should be 5 characters long” error = True Else ch1 = 1st character of code; ch2 = 2nd character of code ch3 = 3rd character of code; ch4 = 4th character of code ch5 = 5th character of code If ch1 < “0” Or ch1 > “9” Or ch2 < “0” Or ch2 > “9” Then err(1) = True If ch1 < “A” Or ch1 > “Z” Or ch2 < “A” Or ch2 > “Z” Then err(2) = True End If Else err(2) = True End If If ch3 < “0” Or ch3 > “9” Then err(3) = True End If If ch4 < “0” Or ch4 > “9” Then err(4) = True End If If ch5 < “0” Or ch5 > “9” Then err(5) = True End If If err(1) And err(2) Then Output “Invalid country” error = True Else If err(1) Then Output “Overseas Centre” Else Output “UK Centre” End If End If For i = 3 To 5 If err(i) Then Output “Invalid”, i, “th character” error = True End If Next i End If End If for the input of "K93621" it's really obvious: as it's not 5 letters you'll get output "The string should be 5 characters long" and error will be true. with "Ab149" it's bit more tricky: err(1) will be True because "A" is not between 0 and 9 and err(2) will be True because "b" is not between "A" and "Z". the rest are digits, thus err(3) to err(5) will all stay False. final output will be "Invalid country" and error will be true. all in all, this pseudo code analyze input string and expect it would start with two big case letters (A to Z) followed by 3 digits. hope this now makes more sense. ![]() |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Can somebody help me? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|