Page 1 of 1 1
Topic Options
#45341 - 2003-09-04 12:13 AM Form alpha numeric
Johan van Huyssteen_dup1 Offline
Fresh Scripter

Registered: 2003-08-28
Posts: 22
Loc: RSA
[Moderator (Sealeopard): Moved thread from 'Scripts' to 'Starters' forum due to lack of script in body]

I need a user interface during the login process that will ask the user office numbers. It must be 3 to 4 numbers and a selection of a,b,c,d or e example 430 c can anyone help ????

[ 17. September 2003, 19:20: Message edited by: sealeopard ]

Top
#45342 - 2003-09-04 12:17 AM Re: Form alpha numeric
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
User input can be accepted by the GET and GETS commands, an example is in the manual.

GET:
quote:

Accepts a single character from the keyboard and stores the character in a variable.

GETS:
quote:

Reads a line of characters from the keyboard until the ENTER key is pressed, and stores the result in a variable.

For an actual user interface I’d use kixforms, www.kixforms.org

[ 03. September 2003, 12:22: Message edited by: R2D2 ]
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#45343 - 2003-09-04 12:25 AM Re: Form alpha numeric
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
if you have excel in your company, you can use

$input=XLSInputBox()
$room=Split($input)
if $room[0]>'400' and $room[0]<'500' and $room[1]>' ' and $room[1]<'e'
...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#45344 - 2003-09-03 01:38 PM Re: Form alpha numeric
Johan van Huyssteen_dup1 Offline
Fresh Scripter

Registered: 2003-08-28
Posts: 22
Loc: RSA
I want to force the users to fill in numeric values first and then alpha values
Top
#45345 - 2003-09-03 02:05 PM Re: Form alpha numeric
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
This is pretty ugly, but it seems to work.

code:
do
$gotIt = 0
cls
gets $x
select
case len($x) = 4
if val(substr($x, 1, 3)) >= 100 and val(substr($x, 1, 3)) < 1000 and instr("abcde", substr($x, 4, 1))
$gotIt = 1
endif
case len($x) = 5
if val(substr($x, 1, 4)) >= 1000 and val(substr($x, 1, 4)) < 10000 and instr("abcdef", substr($x, 5, 1))
$gotIt = 1
endif

case(1)
;nothing
endselect
until $gotIt

_________________________
Eric

Top
#45346 - 2003-09-04 10:34 AM Re: Form alpha numeric
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Another console method...


Break ON
$gNull=SetOption("Explicit","ON")

Dim $sRoomNumber,$iRoomNumberLen,$sErrorMessage,$sNumberPart

$sErrorMessage="ERROR: Room number must be 3 or 4 digits, followed by a letter a-e e.g. 405b"+@CRLF

While Not $sRoomNumber
"Enter a room number (e.g. 401e): " GetS $sRoomNumber
$sRoomNumber=LCase($sRoomNumber)
$iRoomNumberLen=Len($sRoomNumber)
Select
Case $iRoomNumberLen=4 OR $iRoomNumberLen=5
If Not InStr("abcde",Right($sRoomNumber,1))
$sErrorMessage
$sRoomNumber=""
Else
$sNumberPart=Left($sRoomNumber,$iRoomNumberLen-1)
If Not $sNumberPart=Cstr(Val($sNumberPart))
$sErrorMessage
$sRoomNumber=""
EndIf
EndIf
Case "LengthIsInvalid"
$sErrorMessage
$sRoomNumber=""
EndSelect
Loop

"Valid room number entered:" $sRoomNumber ?

Exit 0


Top
#45347 - 2003-09-04 01:27 PM Re: Form alpha numeric
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
I think in this case GET would be better option as to control over each character as they are typed.
_________________________
!

download KiXnet

Top
#45348 - 2003-09-04 01:56 PM Re: Form alpha numeric
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Then you'd have to deal with backspace, and the fact that the response may be 999x or 9999x.

What it actually needs is a good generic regular expression udf, so you can do:
code:
While Not $sRoomNumber
"Enter room number: " GetS $sRoomNumber
If Not Matches($sRoomNumber,"999[a-e]|9999[a-e]")
"Room number is invalid." ?
$sRoomNumber=""
EndIf
Loop

Oops. Hijacked thread [Embarrassed]

Top
#45349 - 2003-09-04 02:34 PM Re: Form alpha numeric
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Haven't mastered it yet, but something like this might work. This considers "000a" to be a valid room number.

code:
$o = createobject("vbscript.regexp")
$o.pattern = "^(\d{3,4})[a-e]"
if $o.test($roomNumber)
? "Match"
else
? "No Match"
endif

_________________________
Eric

Top
#45350 - 2003-09-04 03:11 PM Re: Form alpha numeric
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Hmm. Try:
quote:
"^[1-9](\d{2,3})[a-e]$$"

Top
#45351 - 2003-09-10 09:05 AM Re: Form alpha numeric
Johan van Huyssteen_dup1 Offline
Fresh Scripter

Registered: 2003-08-28
Posts: 22
Loc: RSA
Thanks richard tested the code and its working 100%.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 895 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.063 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org