mikesx4911
In Runtime
- Messages
- 356
- Location
- chicago, IL
Well this week my class got thrown into the deep end and its either sink or swim and I'm confused as hell still I do not get most of this. Here is what I have so far
Objective
In this lab, students will complete the following objectives:
Create a VBScript Program using NotePad++.
Access a two-dimensional array
Use a Nested For Loop to display array contents
Use Do/While Loops for Error-Handling
Use CStr( ), CInt( ) and chr( ) functions
Task 1: Open IP_Array_start.vbs in NotePad++
Download the file IP_Array_start.zip from Doc Sharing in eCollege. Extract the file IP_Array_start.vbs and open it in NotePad++.
Modify the Programmer Header as needed. and Save As the file with the new name of IP_Array.vbs.
The line dim ipAddress(5,3) declares a 6x4 2-dimensional array. The 5 and 3 give the maximum index value. Since indices always start at 0, this is 6x4 array.
The lines that follow initilize the array locations with IP addresses. The first index (0..5) represents the rooms 100 through 105. The second index (0..3) represent the 4 computers in each room.
The IP address of the 3rd computer in room 104 can be found in the array element or component ipAddress(4,2). This value is “192.168.10.45â€. Look at the array carefully to determine the meaning of the index values.
Now that you have an initialized 2-dimensional array, it will be your job to query the array for the IP address for any computer (1-4) in any room (100-105).
Task 2: Define Program Variables and Query Array for IP Addresses
Let's start by defining our program variables. We need two sets of variables: string variables : roomStr and compStr and number variables: room and computer. We string variables are needed for input and the number variables are used as indices for the ipAddress array.
Prompt the user for the room number (100-105). We need to make sure that the user doesn't enter a value less than 100 or greater than 105. We will use a Do/Loop/While loop to error-handle this value. Look at the Pseudocode shown below and write the required VBScript statement that implement the Pseudocode task. Real code that is correct as written will be in bold.
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
Use StdOut to Beep Speaker twice with chr(7)
Display ErrMsg “Error, 100 to 105 Only!!!â€
endif
Loop While room < 100 OR room > 105
Now we prompt the user for the computer number (1-4). We need to make sure that the user doesn't enter a value less than 1 or greater than 4. We will again use a Do/Loop/While loop to error-handle this value. Look at the Pseudocode shown below and write the required VBScript statement that implement this Pseudocode task. Real code that is correct as written will be in bold.
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
Use StdOut to Beep Speaker twice with chr(7)
Display ErrMsg “Error, 1 to 4 Only!!!â€
endif
Loop While computer < 1 OR computer > 4
Now that we have a valid room number 100-105 and a valid computer number 1-4, let's display the IP address for the specified room and computer as follows:
Display the message “ The IP Address in Room ### for computer # is ###.###.##.##:
Note: For room 102, Computer 2, the IP Address is found at ipAddress(2,1). How do you convert room 102 to index 2 and Computer 2 to index 1?
This is my script so far :
' VBScript: IP_Array_start.vbs
' Written by: Michael Ikezoe
' Date: Today's Date
' Class: COMP230
' Professor: Professor Name
' ===================================
' This initialize 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
Loop While room <100 Or room > 105
Here is what I have so far
' VBScript: IP_Array_start.vbs
' Written by: Michael Ikezoe
' Date: Today's Date
' Class: COMP230
' Professor: Professor Name
' ===================================
' This initialize 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=105
computer=3
Do
Loop While room <100 Or room > 105
My first question is when defining a variable above should it be if I want to use room 105 computer 3 IP:192.168.10.54
' Define Script Variables
roomStr=" ipAddress(5,3)"
compStr="192.168.10.54"
room=105
computer=3
I'm a little confused as to wth this really means, whats the difference betwee the str and the bottom part that just says room and computer.
Objective
In this lab, students will complete the following objectives:
Create a VBScript Program using NotePad++.
Access a two-dimensional array
Use a Nested For Loop to display array contents
Use Do/While Loops for Error-Handling
Use CStr( ), CInt( ) and chr( ) functions
Task 1: Open IP_Array_start.vbs in NotePad++
Download the file IP_Array_start.zip from Doc Sharing in eCollege. Extract the file IP_Array_start.vbs and open it in NotePad++.
Modify the Programmer Header as needed. and Save As the file with the new name of IP_Array.vbs.
The line dim ipAddress(5,3) declares a 6x4 2-dimensional array. The 5 and 3 give the maximum index value. Since indices always start at 0, this is 6x4 array.
The lines that follow initilize the array locations with IP addresses. The first index (0..5) represents the rooms 100 through 105. The second index (0..3) represent the 4 computers in each room.
The IP address of the 3rd computer in room 104 can be found in the array element or component ipAddress(4,2). This value is “192.168.10.45â€. Look at the array carefully to determine the meaning of the index values.
Now that you have an initialized 2-dimensional array, it will be your job to query the array for the IP address for any computer (1-4) in any room (100-105).
Task 2: Define Program Variables and Query Array for IP Addresses
Let's start by defining our program variables. We need two sets of variables: string variables : roomStr and compStr and number variables: room and computer. We string variables are needed for input and the number variables are used as indices for the ipAddress array.
Prompt the user for the room number (100-105). We need to make sure that the user doesn't enter a value less than 100 or greater than 105. We will use a Do/Loop/While loop to error-handle this value. Look at the Pseudocode shown below and write the required VBScript statement that implement the Pseudocode task. Real code that is correct as written will be in bold.
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
Use StdOut to Beep Speaker twice with chr(7)
Display ErrMsg “Error, 100 to 105 Only!!!â€
endif
Loop While room < 100 OR room > 105
Now we prompt the user for the computer number (1-4). We need to make sure that the user doesn't enter a value less than 1 or greater than 4. We will again use a Do/Loop/While loop to error-handle this value. Look at the Pseudocode shown below and write the required VBScript statement that implement this Pseudocode task. Real code that is correct as written will be in bold.
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
Use StdOut to Beep Speaker twice with chr(7)
Display ErrMsg “Error, 1 to 4 Only!!!â€
endif
Loop While computer < 1 OR computer > 4
Now that we have a valid room number 100-105 and a valid computer number 1-4, let's display the IP address for the specified room and computer as follows:
Display the message “ The IP Address in Room ### for computer # is ###.###.##.##:
Note: For room 102, Computer 2, the IP Address is found at ipAddress(2,1). How do you convert room 102 to index 2 and Computer 2 to index 1?
This is my script so far :
' VBScript: IP_Array_start.vbs
' Written by: Michael Ikezoe
' Date: Today's Date
' Class: COMP230
' Professor: Professor Name
' ===================================
' This initialize 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
Loop While room <100 Or room > 105
Here is what I have so far
' VBScript: IP_Array_start.vbs
' Written by: Michael Ikezoe
' Date: Today's Date
' Class: COMP230
' Professor: Professor Name
' ===================================
' This initialize 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=105
computer=3
Do
Loop While room <100 Or room > 105
My first question is when defining a variable above should it be if I want to use room 105 computer 3 IP:192.168.10.54
' Define Script Variables
roomStr=" ipAddress(5,3)"
compStr="192.168.10.54"
room=105
computer=3
I'm a little confused as to wth this really means, whats the difference betwee the str and the bottom part that just says room and computer.