Home All Groups Group Topic Archive Search About

Problem with Instr to find a space

Author
17 Jun 2009 2:54 PM
OldDog
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.

Author
17 Jun 2009 3:44 PM
Daniel Crichton
OldDog wrote  on Wed, 17 Jun 2009 07:54:16 -0700 (PDT):

> 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.

>      strC = Instr(strB,fmm,(CHr(32))) <---- Error is here

If strB is zero then this won't work because the first value must be a
number greater than zero. Try this:

For Each strA In arrComputers
     strB = Instr(1,fmm,strA)
    If strB > 0 Then
     strC = Instr(strB,fmm,(CHr(32)))

        If strC > 0 Then
         strD = Mid(fmm,strB,strC)

        WScript.Echo strD

        End If
    End If
Next



Also note that InStr is case sensitive unless you provide the 4th parameter
with the constant vbTextCompare, so you may need to amend your InStr calls
if you need case-insenstive checks.

--
Dan
Are all your drivers up to date? click for free checkup

Author
17 Jun 2009 3:46 PM
Bob Barrows
OldDog wrote:
> 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.

Is this client-side code? You should probably have posted it to
m.p.scripting.vbscript.
>
> 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

Echo?? Maybe you actually did mean to post this in
m.p.scripting.vbscript ...?

Show quoteHide 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)
>
> Wscript.Echo strD
>
> And here is the error:
>
> Microsoft VBScript runtime error: Invalid procedure call or argument:
> 'Instr'
>
> Any help would be appriciated.


Well, it must be an invalid procedure call. Echo (or Response.Write if
this is really an asp question) each argument value you are passing to
see why. If this does not reveal the problem to you, show us one of the
set of argument values that produces the error.
--
HTH,
Bob Barrows

Bookmark and Share