Page 1 of 1 1
Topic Options
#101527 - 2003-05-27 04:27 PM expressions above 99 does not work?
dm330 Offline
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
#101528 - 2003-05-27 04:31 PM Re: expressions above 99 does not work?
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Could you tell us what the format of $DHCPaddress is???
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#101529 - 2003-05-27 04:32 PM Re: expressions above 99 does not work?
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#101530 - 2003-05-27 04:36 PM Re: expressions above 99 does not work?
Chris S. Offline
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 Offline
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 Offline
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 Offline
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 Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I already gave you a solution. [Confused]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#101535 - 2003-05-27 05:22 PM Re: expressions above 99 does not work?
dm330 Offline
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 Offline
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#101537 - 2003-05-27 05:36 PM Re: expressions above 99 does not work?
dm330 Offline
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
#101538 - 2003-05-27 09:15 PM Re: expressions above 99 does not work?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please read TCP/IP Primer, Part I - IP Addresses in the FAQ Forum.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.076 seconds in which 0.037 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