Author: dpayer
Subject: NB function: evaluate string as alphanumeric
Posted: Thu Jul 19, 2012 1:46 pm (GMT -7)
Topic Replies: 0
I struggled for nearly 2 hours trying to get several different ‘canned’ VB and JScript scripts to do a check for a string to see if it is alphanumeric (no non alphanumeric characters ex: !@#$ %^&*() etc.).
Then I realized how easy it would be to do in NB. It took less than 10 min to put it together along with a demo app!
Here is the Neobook function you can save as a text file and save in your \functions folder under the NB install. There are two parameters: variable with string to be evaluated & result.
| Code: |
{NeoBook Function}
Version=5.70
Param=[%1]|Variable|Variable with strring to be evaluated
Param=[%2]|Variable|NB Variable to show True/False (False return includes position of non alphanumeric character
{End}
SetVar "[AlphaNumList]" "abcdefghijklmnopqrstuvwxyz1234567890"
StrLen "[%1]" "[ThisStrLen]"
Loop "1" "[ThisStrLen]" "[WILL_Alpha]"
SubStr "[%1]" "[WILL_Alpha]" "1" "[testthis]"
.StickyNote "-1" "-1" "Testing [testthis]" "500"
SearchStr "[testthis]" "[AlphaNumList]" "[where_non_alphanum]" ""
If "[where_non_alphanum]" "=" "0"
SetVar "[%2]" "False,[WILL_Alpha]"
ExitLoop
Else
SetVar "[%2]" "True"
Endif
Endloop
|
Here is a demo pub that calls the function with the name ‘isAlphaNumeric’
| Code: |
NBW Publication Source File
(C)1993-2011 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.70
ScreenColors=16777216
ScreenWidth=320
ScreenHeight=200
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
CompiledName=
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
FontsToCompile=|
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
Variables=[%1]¶[AlphaNumList]¶[result]¶[TextEntry1]¶[ThisStrLen]¶
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That’s not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That’s not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files…
L_SENDEMAIL=Sending Mail…
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait…
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=9
Name=TextEntry1
X=32
Y=8
W=256
H=120
Anchor=0
VarName=[TextEntry1]
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=3
Name=PushButton1
X=88
Y=136
W=152
H=48
Anchor=0
Text=Alphnumeric?
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=Call "isAlphaNumeric" "[TextEntry1]" "[AlphanumTestResult]"¶AlertBox "Test Result" "[AlphanumTestResult]"¶SetVar "[TextEntry1]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
|
NeoSoft Support Forum