;;
;;======================================================================
;;
;;FUNCTION GetStr()
;;
;;ACTION returns a string, according to defined rules
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 1.0 / 2001/11/14
;;
;;SYNTAX GetStr(Count, [Secure],[Allowed])
;;
;;PARAMETERS Count - REQUIRED - specifies how many chars can be accepted
;; Secure - OPTIONAL - Char to display instead of the chars typed
;; Allowed - Optional - a string defining which chars will be accepted.
;;
;;REMARKS
;;
;;RETURNS String
;;
;;DEPENDENCIES none
;;
;;TESTED WITH W2K, WXP, W2K3
;;
;;EXAMPLES
;;
Function GetStr($_Count, Optional $_Secure, OPTIONAL $_Allowed)
Dim $_CC, $_SF, $_PC
$_CC = 0 ; character count
$GetStr = '' ; init return string
$_SF = 1 ; string flag
; include backspace and return in string of allowed characters
If $_Allowed <> ''
$_Allowed = $_Allowed + Chr(8) + Chr(13)
EndIf
While $_SF ; loop until done
Get $_PC ; get 1 character
If $_Allowed <> '' ; If allowed string is defined
If InStr($_Allowed, $_PC) = 0 ;And ($_PC <> Chr(13) or $_PC <> Chr(8))
$_PC = '' ; char must be one of allowed
EndIf
EndIf
Select
Case $_PC = Chr(8) ; handle backspace
Chr(8) + ' ' + Chr(8) ; erase character
$_CC = $_CC - 1 ; reduce count
If $_CC > 0 ; shorten or clear string
$GetStr = Left($GetStr, $_CC)
Else
$GetStr = ''
EndIf
Case $_PC = Chr(13) ; handle Return
$_SF = 0
Case $_PC = '' ; handle non-allowed chars
Beep
Case 1 ; got a char
If $_Secure
$_Secure ; print alt char if secure
Else
$_PC ; otherwise print the char
EndIf
$GetStr = $GetStr + $_PC ; add it to the string
$_CC = $_CC + 1 ; increment char count
EndSelect
; Exit if character-count is reached
If $_Count > 0 and $_CC = $_Count
$_SF = 0
EndIf
Loop
Exit 0
EndFunction