Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with Substring.......Please! 1

Status
Not open for further replies.
Apr 27, 2011
4
US
I am trying to find a way to pull the Adobe reader version, no matter x32 or x64. The code below makes sense to me, but doesn't seem to work. They way I read it is that it is pulling the objSoftware.Name and is starting at character 1 and reading through character 12 and if it = or "reads" Adobe Reader then it pulls the objSoftware.Version. Am I off base? I have tried to put this together using Google b/c I am not very good with this stuff. Any help would be appreciated!!

Code:
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Check Adobe Reader Versions
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim colSoftware, objSoftware
        Dim Name As String
        Dim Parse As String
        objSoftware = Nothing
        strComputer = "."
        objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")
        Name = objSoftware.Name
        Parse = Name.Substring(1, 12)
        If Parse = "Adobe Reader" Then
            Label20.Text = ("Adobe Reader Version: " & objSoftware.Version)
        End If
 
You posted in the VBScript forum, but the code looks like VB.net. If it is indeed VBScript you are after, this link would be a good place to start:
If you are working with VB.net, you may want to post your question in forum796. The VB languages look very similar, but there are enough differences that code written for 1 will not work in the other without some tweaking.
 
A. Objects need to be [green]set[/green], otherwise, they are nothing.

B. Type definitions are not used in VBS.

C. Setting an object to nothing is not necessary until it is something.

D. You have a collection (colSoftware) of software but are using the undefined objSoftware. Iterate through the collection to get each software object.

E. Substring is not an object method and Name is not an object. use the native functions left, mid, or right to get a substring.

F. I assume Lable20 is a markup element? I changed it to a msgbox to test.

Code:
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Check Adobe Reader Versions
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim colSoftware, objSoftware
B       Dim Name [red][s]As String[/s][/red]
B       Dim Parse [red][s]As String[/s][/red]

C        [red][s]objSoftware = Nothing[/s][/red]

        strComputer = "."
A       [green]set[/green] objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
A       [green]set[/green] colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")
D       [green]for each objSoftware in colSoftware[/green]
            Name = objSoftware.Name
            [red][s]Parse = Name.Substring(1, 12)[/s][/red]
E           [green]Parse = left(Name, 12)[/green]
            If Parse = "Adobe Reader" Then
F                [red][s]Label20.Text = ("Adobe Reader Version: " & objSoftware.Version)[/s][/red]
F                msgbox "Adobe Reader Version: " & objSoftware.Version
            End If
        [green]next[/green]

become

Code:
dim colSoftware, objSoftware
        
strComputer = "."

set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")

for each objSoftware in colSoftware
	if (left(objSoftware, 12)  = "Adobe Reader") then
		msgbox "Adobe Reader Version: " & objSoftware.Version
	end if
next

It's obvious that you aren't familiar with VBS but may be familiar with coding in general. here is a good resource to learn from (at least for me)

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
oops, change to
Code:
if (left(objSoftware[green].Name[/green], 12)  = "Adobe Reader") then

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks for the help! I am not very familiar with VBS......I can make do with some simple scripts, but nothing more than that. I am trying to figure it out on my own. I am beginning to think that I need to slow down just a bit. :)
 
Actually, this script seems to be a good one to learn from. There were several mistakes (understandably). I may just be speculating, but I would guess you had no problem understanding why errors in the original script were errors at all and how to remedy then. I hope you are successful in VBS.

-Geates



"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top