dataDAD Posted February 14, 2006 Posted February 14, 2006 I have all my computer names in a standard format LOC-DEP-XXX the first three characters represent the location the next 3 numerics are department codes and the final three are the computer number e.g. VAN-220-001 would be Vancouver - Payroll - computer 1. What I am looking for is a way to extract the first 3 characters from the computer name and apply location specific mappings and printers, then I would like to extract characters 5,6,7 for the department (there is a hyphan seperating each set of three) and apply drive and printer mappings specific to the department. Can somone please assist me. Thank you in advance
dataDAD Posted February 14, 2006 Author Posted February 14, 2006 I was thinking of using the "split" does this sound right?? I am not a programmer but know enough to cause damage, can some one help.Dim MyString, MyArray, MsgMyString = "VAN-220-001"MyArray = Split(MyString, "-", -1, 1)' MyArray(0) contains "VAN".' MyArray(1) contains "220".' MyArray(2) contains "001".Msg = MyArray(0) & " " & MyArray(1)Msg = Msg & " " & MyArray(2)MsgBox Msg
gunsmokingman Posted February 15, 2006 Posted February 15, 2006 You have to us Instr to match the string.Example This Looks for the letters RW This is the line that it checks for the RWMyPos = Instr(1, SearchString, "RW")On Error Resume NextDim Act, SearchString, SearchChar, MyPosstrComputer = "."Set Act = CreateObject("Wscript.Shell")Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive") For Each objItem in colItems SearchString = objItem.Caption MyPos = Instr(1, SearchString, "RW") If MyPos = 1 Then MsgBox "This Is Not A CD-RW", 0 + 32, "Not A CD-RW" Else SearchChar = "Caption: " & objItem.Caption & vbCrLf & "Name: " & objItem.Name & vbCrLf MsgBox SearchChar, 0 + 32, "Confirm CD-RW" Exit For End If NextThis is what you posted, plus I added 2 more spots to check forThen using Instr I have it popup each part of the array contentsSorry about the length of the script I made it that way for you to use as a template.On Error Resume Next Dim Act : Set Act = CreateObject("Wscript.Shell") Dim MyString,MyString1,MyString2,MyString3,Chk1,Chk2,Chk3, EndReport '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' MyString = Array("VAN-220-001","Delta-330-002", "New Westmister-110-003") '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS LOC Chk1 = InStr(MyString(1),1,"Delta") : MyString1 = Split(MyString(1),"-") If Chk1 = 1 Then Act.Popup "This Is Not LOC" & MyString1(0), 5, "Wrong", 0 + 48 Else Act.Popup "LOC " & MyString1(0), 5, "Correct", 0 + 64 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS DEP Chk1 = InStr(MyString(1),1,"330") : MyString1 = Split(MyString(1),"-") If Chk1 = 1 Then Act.Popup "This Is Not DEP " & MyString1(1), 5, "Wrong", 0 + 48 Else Act.Popup "DEP " & MyString1(1), 5, "Correct", 0 + 64 End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS XXX Chk1 = InStr(MyString(1),1,"002") : MyString1 = Split(MyString(1),"-") If Chk1 = 1 Then Act.Popup "This Is Not XXX " & MyString1(2), 5, "Wrong", 0 + 48 Else Act.Popup "XXX " & MyString1(2), 5, "Correct", 0 + 64 End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Chk1 = MyString1(0) & vbTab & MyString1(1) & vbTab & MyString1(2) '''' VARIBLE 1 FOR ENDREPORT End If '''' END THE FIRST IF STATEMENT '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS LOC Chk2 = InStr(MyString(0),1,"Van") : MyString2 = Split(MyString(0),"-") If Chk2 = 1 Then Act.Popup "This Is Not LOC " & MyString2(0), 5, "Wrong", 0 + 48 Else Act.Popup "LOC " & MyString2(0), 5, "Correct", 0 + 64 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS DEP Chk2 = InStr(MyString(0),1,"220") : MyString2 = Split(MyString(0),"-") If Chk2 = 1 Then Act.Popup "This Is Not DEP " & MyString2(1), 5, "Wrong", 0 + 48 Else Act.Popup "DEP " & MyString2(1), 5, "Correct", 0 + 64 End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS XXX Chk2 = InStr(MyString(0),1,"001") : MyString2 = Split(MyString(0),"-") If Chk2 = 1 Then Act.Popup "This Is Not XXX " & MyString2(2), 5, "Wrong", 0 + 48 Else Act.Popup "XXX " & MyString2(2), 5, "Correct", 0 + 64 End If Chk2 = MyString2(0) & vbTab & MyString2(1) & vbTab & MyString2(2) '''' VARIBLE 2 FOR ENDREPORT End If '''' END THE FIRST IF STATEMENT '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Chk3 = InStr(MyString(2),1,"New Westmister") : MyString3 = Split(MyString(2),"-") If Chk3 = 1 Then Act.Popup "This Is Not LOC " & MyString3(0), 5, "Wrong", 0 + 48 Else Act.Popup "LOC " & MyString3(0) , 5, "Correct", 0 + 64 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS DEP Chk3 = InStr(MyString(2),1,"110") : MyString2 = Split(MyString(2),"-") If Chk3 = 1 Then Act.Popup "This Is Not DEP " & MyString3(1), 5, "Wrong", 0 + 48 Else Act.Popup "DEP " & MyString3(1), 5, "Correct", 0 + 64 End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' CHECKS XXX Chk3 = InStr(MyString(2),1,"003") : MyString3 = Split(MyString(2),"-") If Chk3 = 1 Then Act.Popup "This Is Not XXX " & MyString3(2), 5, "Wrong", 0 + 48 Else Act.Popup "XXX " & MyString3(2), 5, "Correct", 0 + 64 End If Chk3 = MyString2(0) & vbTab & MyString2(1) & vbTab & MyString2(2) '''' VARIBLE 3 FOR ENDREPORT End If '''' END THE FIRST IF STATEMENT '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' EndReport = Chk1 & vbCrLf & Chk2 & vbCrLf & Chk3 Act.Popup "This Is The Things" & vbCrLf & "The Insta looks For" & vbCrLf & EndReport, 15, "All Checks", 0 + 32
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now