#111953 - 2004-01-16 11:58 PM
Re: Spliting a String
|
Howard Bullock
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
|
|
Top
|
|
|
|
#111956 - 2004-01-17 06:33 PM
Re: Spliting a String
|
Howard Bullock
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
|
|
Top
|
|
|
|
#111959 - 2004-01-18 07:21 PM
Re: Spliting a String
|
ArchAngel96
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
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.
|
|
Top
|
|
|
|
#111962 - 2004-01-19 01:56 AM
Re: Spliting a String
|
Howard Bullock
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.
|
|
Top
|
|
|
|
#111963 - 2004-01-19 05:54 AM
Re: Spliting a String
|
ArchAngel96
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
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.
|
|
Top
|
|
|
|
#111965 - 2004-01-19 11:24 PM
Re: Spliting a String
|
ArchAngel96
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
|
|
|
|
#111967 - 2004-01-20 09:33 PM
Re: Spliting a String
|
ArchAngel96
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 657 anonymous users online.
|
|
|