VBScript - Must be first statement on the line

Soldato
Joined
25 Oct 2009
Posts
6,682
Location
Caerphilly
Hi,
Keep getting this error:
Code:
C:\Documents and Settings\All Users\Application Data\CentraStage\Packages\587ab1a3-fea6-48ce-8451-24f81a801662#\command.vbs(12, 94) Microsoft VBScript compilation error: Must be first statement on the line
This is the script:
Code:
On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim strSimsVersion
strSimsVersion = ""

Select Case GetOSArch()
    Case 32
        strSimsVersion = objFSO.GetFileVersion("C:\Program Files\SIMS\SIMS .Net\pulsar.exe")
    Case 64
        strSimsVersion = objFSO.GetFileVersion("C:\Program Files (x86)\SIMS\SIMS .Net\pulsar.exe") End Select

Set WshShell = WScript.CreateObject("WScript.Shell")

If strSimsVersion = "" Then
    WScript.Echo "SIMS not detected"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", 'Not Installed', "REG_SZ" Else
    WScript.Echo "SIMS version: " & strSimsVersion
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", strSimsVersion, "REG_SZ"
End If

Function GetOSArch()
    GetOSArch = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").AddressWidth
End Function

Any ideas guys? I'm stumped.
 
Change:

Code:
strSimsVersion = objFSO.GetFileVersion("C:\Program Files (x86)\SIMS\SIMS .Net\pulsar.exe") End Select

To

Code:
strSimsVersion = objFSO.GetFileVersion("C:\Program Files (x86)\SIMS\SIMS .Net\pulsar.exe")
End Select


(End Select should be on a new line, you have it at the end of one)
 
Thanks Pho. Did that but im now getting this:

C:\Documents and Settings\All Users\Application Data\CentraStage\Packages\587ab1a3-fea6-48ce-8451-24f81a801662#\command.vbs(19, 97) Microsoft VBScript compilation error: Must be first statement on the line

It was 19, 94 but now 19, 97
 
I think you need to move your ELSE to the start of the next line?

PHP:
On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim strSimsVersion
strSimsVersion = ""

Select Case GetOSArch()
    Case 32
        strSimsVersion = objFSO.GetFileVersion("C:\Program Files\SIMS\SIMS .Net\pulsar.exe")
    Case 64
        strSimsVersion = objFSO.GetFileVersion("C:\Program Files (x86)\SIMS\SIMS .Net\pulsar.exe") 
End Select

Set WshShell = WScript.CreateObject("WScript.Shell")

If strSimsVersion = "" Then
    WScript.Echo "SIMS not detected"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", 'Not Installed', "REG_SZ" 
Else
    WScript.Echo "SIMS version: " & strSimsVersion
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", strSimsVersion, "REG_SZ"
End If

Function GetOSArch()
    GetOSArch = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").AddressWidth
End Function
 
Thanks Pho. Did that but im now getting this:

C:\Documents and Settings\All Users\Application Data\CentraStage\Packages\587ab1a3-fea6-48ce-8451-24f81a801662#\command.vbs(19, 97) Microsoft VBScript compilation error: Must be first statement on the line

It was 19, 94 but now 19, 97

12,94 and 19,97

Line and column numbers in your script - if you check those locations in a text editor, it'll take you straight to the problem.
 
Cheers guys, I've copied it into word but column 97 doesn't exist on line 19, line wo only has a maximum of column 34.

I moved the else to the next line but no different...
 
Code:
On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim strSimsVersion
strSimsVersion = ""

Select Case GetOSArch()
    Case 32
        strSimsVersion = objFSO.GetFileVersion("C:\Program Files\SIMS\SIMS .Net\pulsar.exe")
    Case 64
        strSimsVersion = objFSO.GetFileVersion("C:\Program Files (x86)\SIMS\SIMS .Net\pulsar.exe") 
    End Select

Set WshShell = WScript.CreateObject("WScript.Shell")

If strSimsVersion = "" Then
    WScript.Echo "SIMS not detected"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", "Not Installed", "REG_SZ" 
Else
    WScript.Echo "SIMS version: " & strSimsVersion
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", strSimsVersion, "REG_SZ"
End If

Function GetOSArch()
    GetOSArch = GetObject("winmgmts:root\cimv2:Win32_Processor='cpu0'").AddressWidth
End Function

You had 'Not Installed' instead of "Not Installed" and as already said, the 'Else' statement needs a new line

Seems to work ok on my machine.
 
Last edited:
Code:
 WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage\Custom4", 'Not Installed', "REG_SZ" [color=orange]Else[/color]
123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456[color=orange]7[/color]
         1         2         3         4         5         6         7         8         [color=orange]9[/color]

That's line 19 from your post above (substituting the leading tab with a single space), with number markers for the columns (digits and tens), starting at position 97 is the word 'Else'. Do not use Word for editing code, use something like Notepad++ instead.
 
Back
Top Bottom