Page 1 of 2 12>
Topic Options
#111950 - 2004-01-16 11:10 PM Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Ok, I've looked at the board and didn't find my issue, of course there are many ways to describe it, so I'll just do that and hope some one might know where to point me.

I need to strip a string and verify it meets a certain criteria....


Code:
 $node = "L1A3456789"
$sAsset=SubStr($node,2,6)
Select
Case $sAsset >= "000001" AND $sAsset <= "999999"
? $sAsset
EndSelect


I want to make sure the first 6 'characters' are numbers only. Since there is no separator I can't use the split command so I am uncertain how to get this completed. Can someone help?
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111951 - 2004-01-16 11:17 PM Re: Spliting a String
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Code:

IF $sAsset=val($sAsset)
? $sAsset
ENDIF

_________________________
There are two types of vessels, submarines and targets.

Top
#111952 - 2004-01-16 11:20 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
I totally over looked that... thanx
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111953 - 2004-01-16 11:58 PM Re: Spliting a String
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Given your example, I do not think that VAL is a suitable solution.

$node = "L1A3456789"
$sAsset=SubStr($node,2,6)

yields "1A3456" which is not 6 consecutive number and yields a value of only 1 (one).

My recommendation would be to use regular expressions, but first you need to clarify your example and your data strings.

See: RFC: Regular Expression UDFs

The code below accepts your input and return the first characters that match 6 consecutive digits.

Result: Match = 345678

Code:
$node = "L1A3456789"

$RegExPattern = '(\d{6})'

$Matches = RegExpFind($RegExPattern, $node, 1, 0)
? "Match = " + $Matches[0][0]

Function RegExpFind($Pattern, $String, $IgnoreCase, $Global)

Dim $regEx, $Match, $Matches, $i, $j, $k ; Create variable.
Dim $Results[0]
$regEx = createobject("VBscript.RegExp") ; Create a regular expression.

$regEx.Pattern = $Pattern ; Set pattern.
$regEx.IgnoreCase = val($IgnoreCase) ; Set case insensitivity.
$regEx.Global = val($Global) ; Set global applicability.

$Matches = $regEx.Execute($String) ; Execute search.

$k=0
For Each $Match in $Matches ; Iterate Matches collection.
Dim $MatchValue[0]
ReDim Preserve $Results[$k]

$MatchValue[0] = $Match.Value

if $Match.Submatches.count > 0
for $i=0 to $Match.Submatches.count
ReDim Preserve $MatchValue[$i+1]
$MatchValue[$i+1] = $Match.Submatches($i)
next
endif
$Results[$k] = $MatchValue
$k=$k+1
Next
$RegExpFind = $Results
EndFunction

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#111954 - 2004-01-17 04:52 PM Re: Spliting a String
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hoby, I thought he just wanted to check if it is all numbers or not.
with val returning 1 in this case, he knows that it ain't pure numbers only.
_________________________
!

download KiXnet

Top
#111955 - 2004-01-17 05:34 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Here's the scenario, all corp pcs are named (W/L)123456(asset tag). The asset tag is a unique number and therefore duplicates are virtually impossible, if the techs do their jobs correctly. We want the logon script to run on pc's that meet a very specific criteria, in this case to check if the first letter is a w or l and then verify that there are 6 numbers following the w/l. Somewhere along the line we have gotten a 7th number or an a or b following the normal naming convention. So the name must meet the criteria before the logo script continues. This is to help prevent non-company machines to be affected by things we’ve placed in the logon script.
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111956 - 2004-01-17 06:33 PM Re: Spliting a String
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
From your last post I would then change the RegEx pattern to "^(W|L)(\d{6})" to match

Quote:

to check if the first letter is a w or l and then verify that there are 6 numbers following the w/l.




If you have other patterns that need to be found, I would be happy in assisting you with the pattern.


Since you are not wanting to extract the pieces of the string like your first post seemed to indicate, I would suggest using a different UDF to just verify that match exists.

Various patterns:
"^(W|L)(\d{6})" matches beginning of string; could have other characters after the 6th digit.
"^(W|L)(\d{6})$" matches explicit 7 character string. "^" beginning of string; "$" end of string.


Code:
break ON

$nodes = "L1A3456789", "L123456789"
$RegExPattern = "^(W|L)(\d{6})"

for each $node in $nodes
if RegExpTest($RegExPattern, $node, 1)
? "-Found match: " + $node
else
? "-No Match found: " + $node
endif
next

Function RegExpTest($Pattern, $String, $IgnoreCase)

Dim $regEx, $Match, $Matches ; Create variable.

$regEx = createobject("VBscript.RegExp") ; Create a regular expression.

$regEx.Pattern = $Pattern ; Set pattern.
$regEx.IgnoreCase = val($IgnoreCase) ; Set case insensitivity.

$RegExpTest = $regEx.Test($String) ; Execute test search.
EndFunction

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#111957 - 2004-01-18 01:05 AM Re: Spliting a String
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I must wonder...
do you allow non-company machines to be part of your domain?
and even set their logonscript the same as company machines?

that is so weird...
_________________________
!

download KiXnet

Top
#111958 - 2004-01-18 04:02 AM Re: Spliting a String
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Weird... unless they are Wintendos or you setup trusts or they join the domain, non-company machine cannot logon.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111959 - 2004-01-18 07:21 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
We do allow other workstations on the domain, mainly employees that do work from home on occasion, but not often enough to issue a laptop. We also have venders that do work regularly within the office, they are normally renamed and joined to the domain. In the past everyone had the same style logon script regardless of ‘owner’, there was some minor name checking but many of the non-company machines were still getting the script.

Machine types that are allowed:
Sxxx(Y)xx
(W/L)xxxxxx

Possible Ys: S, N, K, E, H, M, R, L
All ‘x’: Numbers

What I have so far (still working things out):
Code:
$sType=SubStr(@WKSTA,1,1)

Select
Case $sType = "S"
$sLocation=SubStr(@WKSTA,2,4)
$sFunction=SubStr(@WKSTA,6,1)
$sNode=SubStr(@WKSTA,7,2)
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case $sFunction >= "A" AND $sFunction <= "z"
Select
Case $sNode >= "01" AND $sNode <= "99"
$computername = "Store" ; One of the above
EndSelect
EndSelect
EndSelect
Case $sType = "W" OR $sType = "L"
$sAsset=SubStr(@WKSTA,2,6)
Select
Case $sAsset=Val($sAsset)
If $sAsset >= "000001" AND $sAsset <= "999999"
$computername = "Corp"
EndIf
EndSelect
EndSelect

Return
Exit



I’m just trying to clean this up a little more being specific of the node names. I still am testing so the ‘A – Z’ is about to be changed next, I was just using that for testing to ensure I was in the ‘right’ path.
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111960 - 2004-01-18 08:07 PM Re: Spliting a String
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Just wondering... Have you read my posts? You seem to be doing it the hard way.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#111961 - 2004-01-18 08:25 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
I have been reading your posts, it would appear you've created a patterned matching UDF based on perl's pattern matching. I didn't want to use a UDF because I'm the main person who knows kix and would be the only person capable of understanding the concepts. Most of our other scripts are in perl, which just about everyone in my dept knows. We don't use perl for the logon script because we add new features regularly, not every pc has perl so on and on...
I was trying to keep the kix scripts as simple as possible to allow anyone who looks at it to understand. The rest of the knuckleheads seem to be fearful of kix, therefore I became primary. Because of their fears I have to keep things as simple as possible, incase I'm gone and someone needs to make changes.
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111962 - 2004-01-19 01:56 AM Re: Spliting a String
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The script uses the VBS regular expression engine (WSH 5.5 or better) via COM.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#111963 - 2004-01-19 05:54 AM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
I do appreciate all the help, thou it may not seem like it by not using your examples or so forth.

But you're assuming these workstations have WHS, especially 5.6... If it requires WSH 5.6, then that would mean someone needs to install it on the target computers, correct? Now Win98 should have ver 1, Win2K should have ver 2. NT 4.0 and Win95 requires someone to manually install WSH of any version. Now if this is all true, I know none of the target machines have 5.6 and a little less than half have any version of WSH installed. That would mean I can't use your example because my target workstations do not meet the requirements.

I didn’t attempt to use your example simply because I have to keep in mind there are other people who, at the very least need to be able to look at the script and understand it without having to spend time examining it. I have to admit Kix is a very simple and yet powerful, but none of us are programmers, especially anywhere close your level. So I have to work within my limitations, right or wrong.

_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111964 - 2004-01-19 07:01 AM Re: Spliting a String
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I can understand your position and the issues you have now that you mentioned the older OS's.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#111965 - 2004-01-19 11:24 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Ok, I think I've got the concept down, but its pretty ugly to look at. There's a couple of way I could go to 'clean' it up a bit, a sub or a function. I don't think the function will work correctly, the sub will most likely work better, but I'd like few opinions first. Keep in mind I'm covering all the OS's starting with Win95 to Win2K. WSH has not been installed unless the OS has it built in. The possible workstation names are "SxxxxYxx" or "(W/L)xxxxxx".

Code:
 $machine = "W094562a154"
$computername = "Failed"

$sType=SubStr($machine,1,1)

Select
Case $sType = "S"
$sLocation=SubStr($machine,2,4)
$sFunction=SubStr($machine,6,1)
$sNode=SubStr($machine,7,2)
$sLocation2=Val($sLocation)
Select
Case Len($sLocation2) = 1
$sLocation3 = SubStr($sLocation,4)
If $sLocation2=$sLocation3
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case $sFunction = "N" OR $sFunction = "L" OR $sFunction = "R" OR $sFunction = "H"
OR $sFunction = "E" OR $sFunction = "K" OR $sFunction = "S" OR $sFunction = "V"
Select
Case $sNode >= "01" AND $sNode <= "99"
$computername = "Store"
EndSelect
EndSelect
EndSelect
EndIf
Case Len($sLocation2) = 2
$sLocation3 = SubStr($sLocation,3)
If $sLocation2=$sLocation3
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case $sFunction = "N" OR $sFunction = "L" OR $sFunction = "R" OR $sFunction = "H"
OR $sFunction = "E" OR $sFunction = "K" OR $sFunction = "S" OR $sFunction = "V"
Select
Case $sNode >= "01" AND $sNode <= "99"
$computername = "Store"
EndSelect
EndSelect
EndSelect
EndIf
Case Len($sLocation2) = 3
$sLocation3 = SubStr($sLocation,2)
If $sLocation2=$sLocation3
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case $sFunction = "N" OR $sFunction = "L" OR $sFunction = "R" OR $sFunction = "H"
OR $sFunction = "E" OR $sFunction = "K" OR $sFunction = "S" OR $sFunction = "V"
Select
Case $sNode >= "01" AND $sNode <= "99"
$computername = "Store"
EndSelect
EndSelect
EndSelect
EndIf
EndSelect
Case $sType = "W" OR $sType = "L"
$sAsset=SubStr($machine,2,6)
$sAsset2=Val($sAsset)
If Len($sAsset2) < 6
$sAsset = SubStr($machine,3,5)
EndIf
Select
Case $sAsset=$sAsset2
If $sAsset >= "000001" AND $sAsset <= "999999"
$computername = "Corp"
EndIf
EndSelect
EndSelect

? $computername

Any one?
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111966 - 2004-01-19 11:52 PM Re: Spliting a String
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
This
Code:

Case $sFunction = "N" OR $sFunction = "L" OR $sFunction = "R" OR $sFunction = "H"
OR $sFunction = "E" OR $sFunction = "K" OR $sFunction = "S" OR $sFunction = "V"
;...
Case $sNode >= "01" AND $sNode <= "99"


can be shortened e.g. to
Code:

CASE INSTR('NLRHEKSV',$sFunction)
;...
Case $sNode=VAL($sNode)



Edited by sealeopard (2004-01-19 11:54 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#111967 - 2004-01-20 09:33 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Thanks all for the adivise and minor code corrections. Here is my final result, which appears to work exactly how I need it to.

Code:
 Dim $sType, $sLocation, $sLocation2, $sLocation3, $sFunction, $sNode, $sAsset, $sAsset2, $sAsset2

$machine = "S0002N01"
$computername = "Failed"

$sType=SubStr($machine,1,1)

Select
Case $sType = "S"
$sLocation=SubStr($machine,2,4)
$sFunction=SubStr($machine,6,1)
$sNode=SubStr($machine,7,2)
$sLocation2=Val($sLocation)
Select
Case Len($sLocation2) = 1
$sLocation3 = SubStr($sLocation,4)
If $sLocation2=$sLocation3
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case InStr('NLRHEKSV',$sFunction)
$sNode2=Val($sNode)
Select
Case Len($sNode2) = 1
$sNode3 = SubStr($sNode,2)
If InStr('123456789',$sNode2) AND $sNode2=$sNode3
$computername = "Store"
EndIf
Case Len($sNode2) = 2
If $sNode=$sNode2 AND ($sNode >= "01" AND $sNode <= "99")
$computername = "Store"
EndIf
EndSelect
EndSelect
EndSelect
EndIf
Case Len($sLocation2) = 2
$sLocation3 = SubStr($sLocation,3)
If $sLocation2=$sLocation3
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case InStr('NLRHEKSV',$sFunction)
$sNode2=Val($sNode)
Select
Case Len($sNode2) = 1
$sNode3 = SubStr($sNode,2)
If InStr('123456789',$sNode2) AND $sNode2=$sNode3
$computername = "Store"
EndIf
Case Len($sNode2) = 2
If $sNode=$sNode2 AND ($sNode >= "01" AND $sNode <= "99")
$computername = "Store"
EndIf
EndSelect
EndSelect
EndSelect
EndIf
Case Len($sLocation2) = 3
$sLocation3 = SubStr($sLocation,2)
If $sLocation2=$sLocation3
Select
Case $sLocation >= "0002" AND $sLocation <= "0999"
Select
Case InStr('NLRHEKSV',$sFunction)
$sNode2=Val($sNode)
Select
Case Len($sNode2) = 1
$sNode3 = SubStr($sNode,2)
If InStr('123456789',$sNode2) AND $sNode2=$sNode3
$computername = "Store"
EndIf
Case Len($sNode2) = 2
If $sNode=$sNode2 AND ($sNode >= "01" AND $sNode <= "99")
$computername = "Store"
EndIf
EndSelect
EndSelect
EndSelect
EndIf
EndSelect
Case InStr('WL',$sType)
$sAsset=SubStr($machine,2,6)
$sAsset2=Val($sAsset)
If Len($sAsset2) < 6
$sAsset = SubStr($machine,3,5)
EndIf
Select
Case $sAsset=$sAsset2
If $sAsset >= "000001" AND $sAsset <= "999999"
$computername = "Corp"
EndIf
EndSelect
EndSelect

? $computername

Of Course, if any one has any suggestions they are always welcome.
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111968 - 2004-01-20 09:40 PM Re: Spliting a String
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Waddup with all those SELECT CASE constructs where there is only one or two CASEs? An IF ELSE ENDIF would do just as well.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111969 - 2004-01-20 10:06 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
I had no choice but to go that route, there are at least two 'cases' for every condition. By using an 'else' statement the check may not meet the requirements and therefore I would get the wrong result. There are specific requirements the checks need to meet, there is no true 'else' here. Otherwise I'd have to have an 'If' for almost every condition.
I know its an UGLY thing to look at, how do you think I feel.. I had to write it, test it and potentially use it. My target clients don't all meet 'requirements' for many of the UDF's that would work out SO much better. Sorry to say, if I had enough time and knew enough perl I'd just convert the entire logon script... (Sorry Kix), but again many workstations don't meet the desired requirements. I'm stuck in a hole.


Edited by ArchAngel96 (2004-01-20 10:07 PM)
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 837 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.08 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org