#101527 - 2003-05-27 04:27 PM
expressions above 99 does not work?
|
dm330
Fresh Scripter
Registered: 2003-05-27
Posts: 16
Loc: Netherlands
|
Hello...
I am working on a logon script for laptops with a ras connection.
We use these laptops for LAN, ISDN and RAS so i have to check on ip to run the script only if the RAS connection is up...
Here is a sample of the script:
$RASsub = Ltrim(Substr($DhcpIPAddress,10,14)) If ($RASsub>=1 and $RASsub<=39) $done=1 Goto endloop Endif
The IP address must be within 1 and 39 So when the ip addres is 99 all is oke, but when the ip address is 100 or more it looks like it reads 10 instead of 100 ??? beats me ??? why this is but if i set the $RASsub to "$RASsub = 100" manually it works oke?
does anyone know if this is a bug or?
I use Kix4.20
_________________________
greetz dm330, from the Netherlands
|
|
Top
|
|
|
|
#101529 - 2003-05-27 04:32 PM
Re: expressions above 99 does not work?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
How are you getting the $DHCPaddress value? You do not show us. I suspect that you substr in wrong. I would recommend using val(split($DHCPaddress,".")[3]) for the last octet.
|
|
Top
|
|
|
|
#101530 - 2003-05-27 04:36 PM
Re: expressions above 99 does not work?
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Your Substr() command is starting at offset 10 and retrieving the next 14 characters.
quote:
SUBSTR ("string", start, length) String The string from which to extract a substring.
Start
Numeric value representing the offset (from the left) in the string where the substring begins.
Length
Optional numeric value representing the length of the substring. If omitted or if there are fewer than Length characters in the text (including the character at start), all characters from the start position to the end of the string are returned.
|
|
Top
|
|
|
|
#101531 - 2003-05-27 04:40 PM
Re: expressions above 99 does not work?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Howards solution will work.
Your problem is the substring. The resultant data is of type "string", and when you do your comparisons the numeric data is also converted to a string so you get a string comparison.
You could have re-ordered your comparison to force a cast to integer type like so:
code:
If(39>=$RASsub AND 1<=$RASsub) ... EndIf
This would also have worked. However, explicity casting (or coercing) the type is far more readable.
{EDIT} Hmmm. After re-reading I may have been looking at a more subtle problem than is present. {/EDIT} [ 27. May 2003, 16:44: Message edited by: Richard H. ]
|
|
Top
|
|
|
|
#101532 - 2003-05-27 05:02 PM
Re: expressions above 99 does not work?
|
dm330
Fresh Scripter
Registered: 2003-05-27
Posts: 16
Loc: Netherlands
|
Hay
Here is the whole script as of now:
mmmh my mistake ($DhcpIPAddress,10,14) but if i set 14 to 3 it still does not work...
$IPinterface = ENUMKEY("$HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $Index)
Loop while not end of index. ; While @ERROR <> "259" ; $IPinterface = ENUMKEY("$HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $Index) ; ? ? "IPinterface = $IPinterface" ; ; If @ERROR = 259 Goto EndLoop Endif ; ; $Index = $Index + 1 ; $DhcpIPAddress=ReadValue("$HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\$IPinterface","DhcpIPAddress") ; $RASsub = Ltrim(Substr($DhcpIPAddress,10,3)) ; ? "RASsub = _ $RASsub _" ; ; $RASip = Ltrim(Substr($DhcpIPAddress,1,8)) ; ? "RASip = _ $RASip _" ; ; If $RASip = "10.252.1" ; If ($RASsub>=1 and $RASsub<=39) ; $Done = "1" ; Goto EndLoop ; Endif ; Endif ; Loop ; ; :EndLoop ;Loop
_________________________
greetz dm330, from the Netherlands
|
|
Top
|
|
|
|
#101533 - 2003-05-27 05:06 PM
Re: expressions above 99 does not work?
|
dm330
Fresh Scripter
Registered: 2003-05-27
Posts: 16
Loc: Netherlands
|
Woeps can't post html tags error or something, this includes the beginning to... sorry for that
$Teller = 0 While $Done <> "1" $Index = 0 $Teller = $Teller + 1 $IPinterface = ENUMKEY("$HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $Index) ;Loop while not end of index. While @ERROR <> "259" $IPinterface = ENUMKEY("$HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $Index) ? ? "IPinterface = $IPinterface"
If @ERROR = 259 Goto EndLoop Endif $Index = $Index + 1 $DhcpIPAddress=ReadValue("$HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\$IPinterface","DhcpIPAddress") $RASsub = Ltrim(Substr($DhcpIPAddress,10,3)) ? "RASsub = _ $RASsub _"
$RASip = Ltrim(Substr($DhcpIPAddress,1,8)) ? "RASip = _ $RASip _" If $RASip = "10.252.1" If ($RASsub>=1 and $RASsub<=39) $Done = "1" Goto EndLoop Endif Endif Loop :EndLoop Loop
_________________________
greetz dm330, from the Netherlands
|
|
Top
|
|
|
|
#101534 - 2003-05-27 05:08 PM
Re: expressions above 99 does not work?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I already gave you a solution.
|
|
Top
|
|
|
|
#101535 - 2003-05-27 05:22 PM
Re: expressions above 99 does not work?
|
dm330
Fresh Scripter
Registered: 2003-05-27
Posts: 16
Loc: Netherlands
|
Yes i have seen your solution but was still testing it when i posted my reply...
It worked great tnx Howard...
Gonna try Richard's solution to...
Tnx you all for the fast replies...
_________________________
greetz dm330, from the Netherlands
|
|
Top
|
|
|
|
#101536 - 2003-05-27 05:26 PM
Re: expressions above 99 does not work?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If your substr is wrong then Richard's string to numeric suggestion still will not help you. Try printing out the value of $DHCPaddress and the result of your substr to see to verify that you are getting the proper text (last octet) before you apply Richard's suggestion. [ 27. May 2003, 17:27: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#101537 - 2003-05-27 05:36 PM
Re: expressions above 99 does not work?
|
dm330
Fresh Scripter
Registered: 2003-05-27
Posts: 16
Loc: Netherlands
|
Yes the substr is oke now... and the printout to...
I will try both the solutions...
Tnx for the help Howard
_________________________
greetz dm330, from the Netherlands
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|