![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Trouble with finding a space useing Instr Hi, I am trying to use Instr to find the model number of seveal different types of computers. I am getting and error at strC. Here is the code: 'Determine the model number of the PC Set CompSys = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) For Each sysItem In CompSys fmfg = Trim(sysItem.Manufacturer) fmm = Trim(sysItem.Model) Wscript.Echo fmm arrComputers = Array("D420","D430","D620","D630", _ "E4300","E6400","745","755", _ "760","490","690", _ "M4300","M4400","M65","T3400", _ "T5400","T7400","dc7600","dc7700", _ "dc7800","T60","T61") For Each strA In arrComputers strB = Instr(1,fmm,strA) strC = Instr(strB,fmm,(CHr(32))) <---- Error is here strD = Mid(fmm,strB,strC) Wscript.Echo strD And here is the error: Microsoft VBScript runtime error: Invalid procedure call or argument: 'Instr' Any help would be appriciated. |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Trouble with finding a space useing Instr OldDog schrieb: Quote: > Hi, > > I am trying to use Instr to find the model number of seveal different > types of computers. I am getting and error at strC. > > > Here is the code: > > > 'Determine the model number of the PC > Set CompSys = objWMIService.ExecQuery("Select * from > Win32_ComputerSystem",,48) > For Each sysItem In CompSys > fmfg = Trim(sysItem.Manufacturer) > fmm = Trim(sysItem.Model) > Wscript.Echo fmm > > > arrComputers = Array("D420","D430","D620","D630", _ > "E4300","E6400","745","755", _ > "760","490","690", _ > "M4300","M4400","M65","T3400", _ > "T5400","T7400","dc7600","dc7700", _ > "dc7800","T60","T61") > For Each strA In arrComputers variable names are guilty of type prefix fraud. Quote: > strB = Instr(1,fmm,strA) Quote: > strC = Instr(strB,fmm,(CHr(32))) <---- Error is here of 0. ---- Quote: Quote: >> nPos = Instr( 0, "x", "y" ) >> Error Description: Ungültiger Prozeduraufruf oder ungültiges Argument (invalid procedure call or invalid argument) Quote: Quote: >> quit You need something like: For Each strA In arrComputers nStart = Instr( 1, fmm, strA ) If 0 < nStart Then nEnd = Instr( nStart, fmm, " " ) If 0 < nEnd Then ' cut Else ' surprise End If Else ' try next End If Next Quote: > strD = Mid(fmm,strB,strC) > > > Wscript.Echo strD > > > And here is the error: > > > Microsoft VBScript runtime error: Invalid procedure call or argument: > 'Instr' > > > Any help would be appriciated. > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Trouble with finding a space useing Instr On Jun 17, 10:56*am, OldDog <mikef2...@xxxxxx> wrote: Quote: > Hi, > > I am trying to use Instr to find the model number of seveal different > types of computers. I am getting and error at strC. > > Here is the code: > > 'Determine the model number of the PC > Set CompSys = objWMIService.ExecQuery("Select * from > Win32_ComputerSystem",,48) > For Each sysItem In CompSys > * * * * fmfg = Trim(sysItem.Manufacturer) > * * * * fmm = Trim(sysItem.Model) > * * * * Wscript.Echo fmm > > arrComputers = Array("D420","D430","D620","D630", _ > * * * * * * * * "E4300","E6400","745","755", _ > * * * * * * * * "760","490","690", _ > * * * * * * * * "M4300","M4400","M65","T3400", _ > * * * * * * * * "T5400","T7400","dc7600","dc7700", _ > * * * * * * * * "dc7800","T60","T61") > For Each strA In arrComputers > * * *strB = Instr(1,fmm,strA) > * * *strC = Instr(strB,fmm,(CHr(32))) <---- Error is here > * * *strD = Mid(fmm,strB,strC) > > Wscript.Echo strD > > And here is the error: > > Microsoft VBScript runtime error: Invalid procedure call or argument: > 'Instr' > > Any help would be appriciated. their names are misleading. That may also be a part of your problem, in that I think your logic is faulty. Specifically, the result of the first search returns the value zero, if the search fails. Since strings are not zero based, the second search fails with the error message you cite. Therefore, you need to test the result and skip the rest if it is zero, that is if the computer under test does not match the content of strA. I must presume the contents of the loop variable, strA, does not represent the entire string you are searching for. Otherwise, the rest of the parsing makes no sense. However, the next problem will arise, in there is no trailing space after the starting point you have located. The solution, I generally use is to just past a space at the end of the string under test to make sure that doesn't happen, maybe something like this ... For Each strA In arrComputers numB = Instr(1, fmm, strA) if numB <> 0 then numC = Instr(numB, fmm & " ", Chr(32)) - 1 strD = Mid(fmm,numB,numC) Wscript.Echo strD end if '... next ' strA Tom Lavedas *********** |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Trouble with finding a space useing Instr On Jun 17, 10:42*am, T Lavedas <tglba...@xxxxxx> wrote: Quote: > On Jun 17, 10:56*am, OldDog <mikef2...@xxxxxx> wrote: > > > > > Quote: > > Hi, Quote: > > I am trying to use Instr to find the model number of seveal different > > types of computers. I am getting and error at strC. Quote: > > Here is the code: Quote: > > 'Determine the model number of the PC > > Set CompSys = objWMIService.ExecQuery("Select * from > > Win32_ComputerSystem",,48) > > For Each sysItem In CompSys > > * * * * fmfg = Trim(sysItem.Manufacturer) > > * * * * fmm = Trim(sysItem.Model) > > * * * * Wscript.Echo fmm Quote: > > arrComputers = Array("D420","D430","D620","D630", _ > > * * * * * * * * "E4300","E6400","745","755", _ > > * * * * * * * * "760","490","690", _ > > * * * * * * * * "M4300","M4400","M65","T3400", _ > > * * * * * * * * "T5400","T7400","dc7600","dc7700", _ > > * * * * * * * * "dc7800","T60","T61") > > For Each strA In arrComputers > > * * *strB = Instr(1,fmm,strA) > > * * *strC = Instr(strB,fmm,(CHr(32))) <---- Error is here > > * * *strD = Mid(fmm,strB,strC) Quote: > > Wscript.Echo strD Quote: > > And here is the error: Quote: > > Microsoft VBScript runtime error: Invalid procedure call or argument: > > 'Instr' Quote: > > Any help would be appriciated. > First strA and strB are not strings, but rather they are numbers - so > their names are misleading. *That may also be a part of your problem, > in that I think your logic is faulty. > > Specifically, the result of the first search returns the value zero, > if the search fails. *Since strings are not zero based, the second > search fails with the error message you cite. *Therefore, you need to > test the result and skip the rest if it is zero, that is if the > computer under test does not match the content of strA. > > I must presume the contents of the loop variable, strA, does not > represent the entire string you are searching for. *Otherwise, the > rest of the parsing makes no sense. *However, the next problem will > arise, in there is no trailing space after the starting point you have > located. *The solution, I generally use is to just past a space at the > end of the string under test to make sure that doesn't happen, maybe > something like this ... > > For Each strA In arrComputers > * * *numB = Instr(1, fmm, strA) > * * *if numB <> 0 then > * * * *numC = Instr(numB, fmm & " ", Chr(32)) - 1 > * * * *strD = Mid(fmm,numB,numC) > > * * * *Wscript.Echo strD > * * end if > '... > next ' strA > > Tom Lavedas > ***********- Hide quoted text - > > - Show quoted text - well. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| BSoD - trouble finding solution... | Vista General | |||
| trouble finding sata driver | Drivers | |||
| Trouble Finding Text in Windows Mail | Vista mail | |||
| Finding Used Memory Address Space; Maximum amount of RAM | Vista hardware & devices | |||
| Finding Used Memory Address Space; Maximum amount of RAM | Vista performance & maintenance | |||