Source language: Translate to:

validate float number

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Postby dec » Sun Oct 09, 2011 10:14 am

Hi,

Maybe another ways are availables (some specific text entry mask for example), but, I wanted to put here what to do using the npRexp plugin:

Code: Select all
npRexpSearch "^[#91]-+[#93]?[#91]0-9[#93]*\.?[#91]0-9[#93]+$" "[TextEntry]" "[Result]"


The "Result" variable store "True" if the "[TextEntry]" variable value can be considerer a valid float number, or "False" if not. Note the regular expresion is in fact this:

Code: Select all
^[-+]?[0-9]*\.?[0-9]+$


But to use directly with the action above we change the "[" "and "]" with the appropiate ASCII values, in order to avoid NeoBook variables collisions.

P.S. Sorry if you dont want an answer that implied to use a NeoBook commercial plugin Abdullah.
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Postby dec » Wed Oct 12, 2011 4:28 pm

Hi,

Maybe some mate can put here a Text Entry Mask or another possible solution in order to achieve your need. ;)
Last edited by dec on Thu Oct 13, 2011 1:04 am, edited 1 time in total.
.
Enhance your NeoBook applications!
.
57 plugins, 1113 actions and 230 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: validate float number

Postby andybrock » Thu Oct 13, 2011 12:39 am

Abdullah wrote:Hi everybody,

I am trying to ensure that my clients only be allowed to enter a float value into a textentry , i tried many solutions like set allowed chars into a variable and search for it with loop , but I can bypass this method when i enter mass chars quickly !

thanks for you time
Abdullah


For the odd case where someone did put mass numbers in quickly why not just check for that later on and if they have managed to 'break' it then send them back to that text entry box with a message?

Andy
User avatar
andybrock
 
Posts: 181
Joined: Mon Apr 20, 2009 1:38 pm
Location: Somerset, UK

Postby Gaev » Thu Oct 13, 2011 5:44 am

Abdullah:
I am trying to ensure that my clients only be allowed to enter a float value into a textentry
... can you describe in English (not Regexese) what you mean by float value ... i.e. what characters are allowed, maximum number of characters allowed etc.
i tried many solutions like set allowed chars into a variable and search for it with loop , but I can bypass this method when i enter mass chars quickly !
... perhaps you can post your routine here so others might be able to optimize it ... also, whenever I have had the need to develop a Text Change routine, I design it to work on the current content (not the last character entered) ... so entering mass chars quickly would not matter ... not that I have had to write any routine that would take longer than a person (me) typing characters via the keyboard.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

May Be...

Postby virger » Thu Oct 13, 2011 10:32 am

Yo hice este segmento de programa como 3 años atras, quiza te sirva.
Deje solo la parte creo te ayudara.
++++++++++++++++++++
NBW Publication Source File
(C)1993-2011 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.70
ScreenColors=16777216
ScreenWidth=640
ScreenHeight=480
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
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=InTx
X=134
Y=9
W=494
H=318
Anchor=0
VarName=[tx]
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=15268080
FillPattern=0
Font=Arial
FontSize=14
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=3
Name=BtF1
X=10
Y=13
W=102
H=32
Anchor=0
Text=Pulsar `
Align=2
Key=192
ImageStyle=0
XPTheme=Yes
ObjAction=.visible si/no el TexEntry 'InNum'¶GetObjectInfo "InNum1" "Visible" "[vis]"¶if "[vis]" "=" "True"¶ MoveObject "InNum1" "10" "50"¶ hideobject "InNum1" "" ""¶ .incluye el dato numerico digitado¶ StrIns "[num]" "[tx]" "[px]" "[tx]"¶ FocusObject "InTx"¶else¶ .posicion actual del cursor en el TexEntry 'InTx'¶ GetObjectInfo "InTx" "CursorPosition" "[px]"¶ MoveObject "InNum1" "160" "30"¶ showobject "InNum1" "" ""¶ FocusObject "InNum1"¶endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14213368
FillPattern=0
Font=Arial
FontSize=16
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=9
Name=InNum1
X=10
Y=50
W=109
H=26
Anchor=0
VarName=[num]
EditLen=0
ObjAction=.[num] variable del texentry¶¶.donde esta el cursor en el texto¶GetObjectInfo "InNum1" "CursorPosition" "[cpt]"¶¶.extrae el ultimo caracter que se tecleo¶substr "[num]" "[cpt]-1" "1" "[ch]"¶¶.busca si es caracter valido¶searchstr "[ch]" "1234567890.-" "[pc]"¶¶.define si el '-' existe o no y lo valida¶ifex "[pc]=12 AND [cpt]>2"¶ StrDel "[num]" "[cpt]-1" "1" "[num]"¶endif¶¶.define si el punto existe o no y lo valida¶ifex "[pc]=11 AND [pt]<>0"¶ StrDel "[num]" "[cpt]-1" "1" "[num]"¶endif¶searchstr "." "[num]" "[pt]"¶¶.valida el caracter tecleado¶if "[pc]" "=" "0"¶ StrDel "[num]" "[cpt]-1" "1" "[num]"¶endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14213368
FillPattern=0
Font=Arial
FontSize=14
FontStyle=0
FontCharset=1
TextColor=0
Visible=No
TabOrder=2
ObjectType=3
Name=BtF2
X=10
Y=103
W=102
H=32
Anchor=0
Text=Pulsar *
Align=2
Key=106
ImageStyle=0
XPTheme=Yes
ObjAction=.visible si/no el TexEntry 'InNum'¶GetObjectInfo "InNum2" "Visible" "[vis]"¶if "[vis]" "=" "True"¶ hideobject "InNum2" "" ""¶ MoveObject "InNum2" "10" "140"¶¶ .lo convierte numero con decimales definidos¶ math "[num]" "[dc]" "[num]"¶¶ .no hubo seleccion previa¶ if "[znum]" "=" ""¶ .incluye nuevo dato¶ StrIns "[num]" "[tx]" "[px]" "[tx]"¶ else¶ .sustituye dato existente¶ StrReplace "[tx]" "[znum]" "[num]" "[tx]" ""¶ endif¶ FocusObject "InTx"¶ setvar "[znum]" ""¶ setvar "[num]" ""¶else¶ .posicion actual del cursor en el TexEntry 'InTx'¶ GetObjectInfo "InTx" "CursorPosition" "[px]"¶¶ .dato seleccionado, puede incluir signo de colones (¢)/$¶ GetObjectInfo "InTx" "SelectedText" "[znum]"¶¶ .defino numerdo de decimales¶ setvar "[dc]" "2"¶¶ if "[znum]" "=" ""¶ .creo variable a usar en NUM¶ setvar "[dg]" "4"¶ substr "0000000000" "1" "[dg]" "[num]"¶ substr "0000000000" "1" "[dc]" "[dec]"¶ setvar "[num]" "[num].[dec]"¶ else¶ DefineVar "[num]" "Decimal" "[dc]" "Local" "[znum]"¶endif¶ showobject "InNum2" "" ""¶ FocusObject "InNum2"¶endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14213368
FillPattern=0
Font=Arial
FontSize=16
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=9
Name=InNum2
X=11
Y=140
W=110
H=26
Anchor=0
VarName=[num]
EditLen=0
ObjAction=.[num] variable del texentry¶¶.donde esta el cursor en el texto¶GetObjectInfo "InNum2" "CursorPosition" "[cpt]"¶¶.extrae el ultimo caracter que se tecleo¶substr "[num]" "[cpt]-1" "1" "[ch]"¶¶.busca si es caracter valido¶searchstr "[ch]" "1234567890.-" "[pc]"¶¶.define si el '-' existe o no y lo valida¶ifex "[pc]=12 AND [cpt]>2"¶ StrDel "[num]" "[cpt]-1" "1" "[num]"¶endif¶¶.define si el punto existe o no y lo valida¶ifex "[pc]=11 AND [pt]<>0"¶ StrDel "[num]" "[cpt]-1" "1" "[num]"¶endif¶searchstr "." "[num]" "[pt]"¶¶.valida el caracter tecleado¶if "[pc]" "=" "0"¶ StrDel "[num]" "[cpt]-1" "1" "[num]"¶endif¶¶.DefineVar "[xnum]" "Decimal" "2" "Local" "[num]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14213368
FillPattern=0
Font=Arial
FontSize=14
FontStyle=0
FontCharset=1
TextColor=0
Visible=No
TabOrder=1
+++++++++++++

Desde COSTA RICA
Con mucha lluvia
pero PURA VIDA

Mis respetos
User avatar
virger
 
Posts: 509
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Postby Gaev » Sun Oct 16, 2011 7:25 am

Abdullah:
I want to allow any number ( it is actually a price ) with two decimal like 999.99 or 9999.99
... so why not use the Validation Mask built into NeoBook's Text Entry Field Tool ? ... looks like ...
Code: Select all
99990.00
or
####0.00
... as a Validation Mask will do what you want.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Gaev » Sun Oct 16, 2011 9:02 am

Abdullah:
it may 999999.99 , i want the mask to validate any number with two decimals only .

So what is wrong with a mask of 999990.00 ? ... will allow ...

0.45
1.54
11.33
123.00
1234.56
etc.

from the Help documentation ...
0 Requires that a number (0-9) be entered.
9 Permits a number (0-9) to be entered, but does not require it.
#Permits a number (0-9) or a plus (+) or minus (-) sign to be entered.

You can make it easier for your user to enter numbers by pre-populating the field associated with the Text Entry Box with a value like 000000.00
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

THE TRICK IS SIMPLE/EL TRUCO ES SIMPLE

Postby virger » Sun Oct 16, 2011 9:57 am

Usando "http://translate.google.com"

1) Marque el texto que es el "pub"
2) Copie el texto con ctrl-c (copiar)
3) Abra un "notepad"
4) Presione las teclas "ctr-v" (pegar)
5) Salve como "ejemplo.pub" tipo "ansi"
6) Busque el "ejemplo.pub", abre el fuente haciendo "doble-click" sobre ese.
7)Se abrira en NeoBook
8) Ese es todo el "truco"
----------------------------

1) Enter the text that is the "pub"
2) Copy the text with ctrl-c (copy)
3) Open a "notepad"
4) Press the "ctr-v" (paste)
5) Save as "example.pub" type "ansi"
6) Look for the "example.pub" opens the source by "double-click" on that.
7) It will open in NeoBook
8) That's the whole "trick"
------------------------------
Desde Mi pequeño pais
PURA VIDA
COSTA RICA Es asi
User avatar
virger
 
Posts: 509
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 0 guests

cron