IP Address Array VBScript Program Lab

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 the array contents;

·  use Do-While Loops for error handling; and

·  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 click Save As to save the file with the new name IP_Array.vbs.

·  The line dim ipAddress(5,3) declares a 6x4, two-dimensional array. The 5 and 3 give the maximum index value. Because indices always start at 0, this is a 6x4 array.

·  The lines initially follow the array locations with IP addresses. The first index (0..5) represents the rooms 100 through 105. The second index (0..3) represents the four computers in each room.

·  The IP address of the third computer in room 104 can be found in the array element or in the 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, 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 an Array for IP Addresses

·  Let’s start by defining our program variables.

·  First, we need to 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-While Loop to error handle this value. Look at the pseudocode shown below and write the required VBScript statement to implement the pseudocode task.
Do
Display Prompt “Please Enter the Room Number (100-105) ...... “
Get StdIn Console Input and assign string value to roomStr
If intval(roomStr)<100 Or intval(roomStr)>105
Use StdOut to Beep Speaker twice with chr(7)
Display ErrMsg “Error, 100 to 105 Only!!!”
else
room = inval(roomStr)-100
endif
While intval(roomStr)<100 OR intval(roomStr)>105

·  Now, we need to 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-While loop to error handle this value. Look at the pseudocode shown below and write the required VBScript statement to implement this pseudocode task.
Do
Display Prompt “Please Enter the Computer Number (1-4) ...... “
Get StdIn Console Input and assign string value to compStr
If intval(compStr)<1 Or intval(compStr)>4
Use StdOut to Beep Speaker twice with chr(7)
Display ErrMsg “Error, 1 to 4 Only!!!”
else
room = inval(compStr)-1
endif
While intval(compStr)<1 OR intval(compStr)>105

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 ###.###.##.##:
Task 3: Prompt the User to Display all the IP Addresses in an Array

·  Now, write the code that follows the pseudocode shown below to prompt the user to specify if he or she wants to display the entire table of IP addresses.
' 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 NOT "Y" & "y" & "N" & "n" Then

Beep Speaker Twice

Display Msg "Error, Y,y,N,n response Only!!!"

EndIf

While ans NOT "Y" & "y" & "N" & "n"

If ans is "Y" OR ans is "y" Then

For room = 0 to 5

For computer = 0 to 3

Display "The IP Address in Room " toString(room+100) “for Computer "

toString(computer+1) " is " ipAddress(room,computer)

EndFor

EndFor

EndIf
Task 4: Finish the Program and Run it Showing Error Handling

·  Finishing writing your program. Include comments, as needed, and use proper rules for indentation. Run your program so that error handling for Room Number, Computer Number, and Y/N is tested. Make sure that your submitted run displays the IP address of a selected room and computer and displays the entire array of IP addresses.

·  Copy and paste your final program source code and your final RUN into the spaces provided in your lab-report document. Submit your completed lab-report document and to the iLab Dropbox for this week.

2

IP_Array_Lab.docx Revision Date: 1103