Problem with Instr to find a space

O

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

Daniel Crichton

OldDog wrote on Wed, 17 Jun 2009 07:54:16 -0700 (PDT):
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.
 
B

Bob Barrows

OldDog said:
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 ...?
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top