Having an issue with VBScript for a class, help appreciated!
Hi everyone, I am currently enrolled in an Intro to Scripting class, and am admittedly very much a novice to this. I am currently having an issue with VBScript resulting in an error when I try to run my code, and was hoping someone here could look at the code I am attempting to run and tell me where, if anywhere, there is an error. The script below is typed out verbatim as instructed in the class.
Quote:
' VBScript: IP_Array.vbs
' Written by:
' Date:
' Class:
' Professor:
' ===================================
' This initializes a 2-dimension array
' of IP Address. The first index +100
' is the room# and the second index+1
' is the computer# in the room.
dim ipAddress(5,3)
ipAddress(0,0)="192.168.10.11"
ipAddress(0,1)="192.168.10.12"
ipAddress(0,2)="192.168.10.13"
ipAddress(0,3)="192.168.10.14"
ipAddress(1,0)="192.168.10.19"
ipAddress(1,1)="192.168.10.20"
ipAddress(1,2)="192.168.10.21"
ipAddress(1,3)="192.168.10.22"
ipAddress(2,0)="192.168.10.27"
ipAddress(2,1)="192.168.10.28"
ipAddress(2,2)="192.168.10.29"
ipAddress(2,3)="192.168.10.30"
ipAddress(3,0)="192.168.10.35"
ipAddress(3,1)="192.168.10.36"
ipAddress(3,2)="192.168.10.37"
ipAddress(3,3)="192.168.10.38"
ipAddress(4,0)="192.168.10.43"
ipAddress(4,1)="192.168.10.44"
ipAddress(4,2)="192.168.10.45"
ipAddress(4,3)="192.168.10.46"
ipAddress(5,0)="192.168.10.51"
ipAddress(5,1)="192.168.10.52"
ipAddress(5,2)="192.168.10.53"
ipAddress(5,3)="192.168.10.54"
' Define Script Variables
roomStr=""
compStr=""
room=0
computer=0
DO
Display Prompt "Please Enter the Room Number (100-105) ...... "
Get StdIn Console Input and assign string value to roomStr
room = CInt(roomStr)
If room < 100 OR room > 105 Then
Use StdOut to Beep Speaker twice with chr(7) and
Display ErrMsg "Error, 100 to 105 Only!!!"
Skip 1 Line
End If
Loop While room < 100 OR room > 105
Do
Display Prompt "Please Enter the Computer Number (1-4) ...... "
Get StdIn Console Input and assign string value to compStr
computer = CInt(compStr)
If computer < 1 OR computer > 4 Then
Use StdOut to Beep Speaker twice with chr(7) and
Display ErrMsg "Error, 1 to 4 Only!!!"
Skip 1 line
End If
Loop While computer < 1 OR computer > 4
Display message " The IP Address in Room " & room & " for computer " & computer & " is " & ipAddress(room-100,computer-1)
' Display All IP Address Y/N?
Do
Display Message
"Do you wish to Display all of the IP Addresses (Y/N) ..... "
Get User Response and assign it to variable ans
If ans <> "Y" & ans <> "y" & ans <> "N" & ans <> "n" Then
Beep Speaker Twice and
Display Msg "Error, Y,y,N,n response Only!!!" & skip line
End If
Loop While ans <> "Y" & ans <> "y" & ans <> "N" & ans <> "n"
If ans = "Y" OR ans = "y" Then
skip line
For room = O to 5
For computer = 0 to 3
Display "The IP Address in Room " room+100 " for Computer "
computer+1 " is " ipAddress(room,computer)
Next
Next
End If
When running the script, I get the following error:
Quote:
C:\Program Files\Notepad++\IP_Array.vbs(42, 17) Microsoft VBScript compilation error: Expected end of statement
Any help would be GREATLY appreciated.
Re: Having an issue with VBScript for a class, help appreciated!
Sorry, apparently using quotes messes with the formatting of the code.
' VBScript: IP_Array.vbs
' Written by:
' Date:
' Class:
' Professor:
' ===================================
' This initializes a 2-dimension array
' of IP Address. The first index +100
' is the room# and the second index+1
' is the computer# in the room.
dim ipAddress(5,3)
ipAddress(0,0)="192.168.10.11"
ipAddress(0,1)="192.168.10.12"
ipAddress(0,2)="192.168.10.13"
ipAddress(0,3)="192.168.10.14"
ipAddress(1,0)="192.168.10.19"
ipAddress(1,1)="192.168.10.20"
ipAddress(1,2)="192.168.10.21"
ipAddress(1,3)="192.168.10.22"
ipAddress(2,0)="192.168.10.27"
ipAddress(2,1)="192.168.10.28"
ipAddress(2,2)="192.168.10.29"
ipAddress(2,3)="192.168.10.30"
ipAddress(3,0)="192.168.10.35"
ipAddress(3,1)="192.168.10.36"
ipAddress(3,2)="192.168.10.37"
ipAddress(3,3)="192.168.10.38"
ipAddress(4,0)="192.168.10.43"
ipAddress(4,1)="192.168.10.44"
ipAddress(4,2)="192.168.10.45"
ipAddress(4,3)="192.168.10.46"
ipAddress(5,0)="192.168.10.51"
ipAddress(5,1)="192.168.10.52"
ipAddress(5,2)="192.168.10.53"
ipAddress(5,3)="192.168.10.54"
' Define Script Variables
roomStr=""
compStr=""
room=0
computer=0
DO
Display Prompt "Please Enter the Room Number (100-105) ...... "
Get StdIn Console Input and assign string value to roomStr
room = CInt(roomStr)
If room < 100 OR room > 105 Then
Use StdOut to Beep Speaker twice with chr(7) and
Display ErrMsg "Error, 100 to 105 Only!!!"
Skip 1 Line
End If
Loop While room < 100 OR room > 105
Do
Display Prompt "Please Enter the Computer Number (1-4) ...... "
Get StdIn Console Input and assign string value to compStr
computer = CInt(compStr)
If computer < 1 OR computer > 4 Then
Use StdOut to Beep Speaker twice with chr(7) and
Display ErrMsg "Error, 1 to 4 Only!!!"
Skip 1 line
End If
Loop While computer < 1 OR computer > 4
Display message " The IP Address in Room " & room & " for computer " & computer & " is " & ipAddress(room-100,computer-1)
' Display All IP Address Y/N?
Do
Display Message
"Do you wish to Display all of the IP Addresses (Y/N) ..... "
Get User Response and assign it to variable ans
If ans <> "Y" & ans <> "y" & ans <> "N" & ans <> "n" Then
Beep Speaker Twice and
Display Msg "Error, Y,y,N,n response Only!!!" & skip line
End If
Loop While ans <> "Y" & ans <> "y" & ans <> "N" & ans <> "n"
If ans = "Y" OR ans = "y" Then
skip line
For room = O to 5
For computer = 0 to 3
Display "The IP Address in Room " room+100 " for Computer "
computer+1 " is " ipAddress(room,computer)
Next
Next
End If
Re: Having an issue with VBScript for a class, help appreciated!
...or I'm just not able to post it here with indentations and the like included. Sorry for triple posting :(
Re: Having an issue with VBScript for a class, help appreciated!
Your code is a combination of VBScript and pseudocode, so it's not surprising that it doesn't work.
Quote:
Originally Posted by
rtrotsfield
When running the script, I get the following error:
C:\Program Files\Notepad++\IP_Array.vbs(42, 17) Microsoft VBScript compilation error: Expected end of statement
The error says that the problem is on line 42, which is:
Code:
Display Prompt "Please Enter the Room Number (100-105) ...... "
This isn't a valid VBScript statement - use the InputBox function to get user input. Go through the rest of your code making similar corrections (searching for VBScript and the pseudocode words should find the VBScript equivalent). Also put Option Explicit at the top of your code, which forces you to define (Dim) all the variables and help you to fix syntax errors with the code.
When posting code, please put it within [ CODE ] [ /CODE ] tags (without the spaces) to preserve the indentation.