|Scooped by Brazilwoolard|
VBScript IP Array Lab
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.
Element K Network Connections
For this lab, we will only need to connect to vlab-PC1. The computer vlab-PC1 is the computer on the left side while vlab-PC2 is on the right. If you leave the cursor on the PC icon for a few seconds, a tool-tip message will appear indicating the hostname of the PC. Open vlab-PC1 and log in as Administrator with the password password.
Note: All captures must be text only—DO NOT capture the NotePad++ application window or the command prompt window. Use copy and paste of text only.
Task 1: Open IP_Array_start.vbs
· Open NotePad++ and use File/Open to open IP_Array_start.vbs in the C:\Scripts directory. Modify theProgrammer Header as needed. and Save As the file with the new name of IP_Array.vbs.
· The line dim ipAddress(5,3) declares a 6×42-dimensional array. The 5 and 3 give the maximum index value. Since the index starts at 0, this is a 6×4 array.
· The lines that follow initialize the array locations with IP addresses. The first index (0..5) represents the rooms 100 through 105. The second index (0..3) represent the four computers in each room.
· The IP address of the third computer in room 104 can be found in the array element or component Address(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 two-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. 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.
Display Prompt “Please Enter the Room Number (100-105) …… “
Get StdIn Console Input and assign string value to roomStr
If room < 100 OR room > 105Then
Use StdOut to Beep Speaker twice with chr(7) and
Display ErrMsg “Error, 100 to 105 Only!!!”
Skip 1 Line
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.
Display Prompt “Please Enter the Computer Number (1-4) …… “
Get StdIn Console Input and assign string value to compStr
If computer < 1 OR computer > 4Then
Use StdOut to Beep Speaker twice with chr(7) and
Display ErrMsg “Error, 1 to 4 Only!!!”
Skip 1 line
Loop Whilecomputer < 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 message ” The IP Address in Room ” & room & ” for computer ” & computer & ” is ” & ipAddress(room-100,computer-1)
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?
Task 3: Prompt User to Display All IP Addresses in Array
· Now write the code that follows the pseudocode shown below to prompt the user if they would like to display the entire table of IP addresses. Real code that is correct as written will be in bold.
‘ Display All IP Address Y/N?
“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
Loop While ans <> “Y” & ans <> “y” & ans <> “N” & ans <> “n”
If OR Then
For to 5
For to 3
Display “The IP Address in Room ” room+100 “ for Computer ”
computer+1 ” is ” ipAddress(room,computer)
Note: Nested For/Next loops are required to access all the elements of a two-dimensional array.
Task 4: Finish Program and Run it Showing Error-Handling
· Finishing writing your program. Include comments as needed and use proper rules for indentation. Run your program using <F6> in NotePad++ using cscript IP_Array.vbs. so that error-handling for Room, Computer, and ans input is tested. Make sure your submitted run displayed the IP Address of a selected room and computer and displays the entire array of IP addresses. A sample run is shown on the next page.