Results 1 to 5 of 5

Thread: VBScript run halfway

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    6

    VBScript run halfway

    Hi, everyone I am taking the scripting class in school and I have problem to run the scripts. It is running up until this line "Display All IP Address Y/N? all the way to the end. Here is my script and anyone can help me with this I will be very appreciate.

    ' 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)
    dim intRoom
    dim intComp
    dim ans

    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"

    ' Prompt user for room number.
    Do Until intRoom >= 100 And intRoom =< 105
    intRoom = InputBox("Please enter the room number (100-105)....")
    WScript.Echo chr(7)
    WScript.Echo chr(7)
    If intRoom < 100 Or intRoom > 105 Then MsgBox("You must enter a value between 100 and 105!")
    Loop

    ' Promt user for computer number.
    Do Until intComp >= 1 And intComp <= 4
    intComp = InputBox("Please enter the computer number (1-4)....")
    WScript.Echo chr(7)
    WScript.Echo chr(7)
    If intComp < 1 Or intComp > 4 Then MsgBox("You must enter a value between 1 and 4!")
    Loop

    MsgBox("Room: " & intRoom & " Computer: " & intComp & " IP Address: " & ipaddress(intRoom - 100, intComp - 1))

    ' Display All IP Address Y/N?
    Do Until ans = Y Or y And ans = N Or n
    ans = InputBox("Do you wish to Display all of the IP Address (Y/N) ...... ")
    WScript.Echo chr(7)
    WScript.Echo chr(7)
    If ans < Y And ans < y Or ans > N And ans > n Then MsgBox("Error, Y,y,N,n response Only!!!")
    Loop
    If ans = "Y" And ans = "y" Then
    WScript.StdOut.WriteBlankLines(1)
    For intRoom = 100 to 105
    For intComp = 1 to 4
    WScript.Echo("The IP Address in Room " & intRoom+100 & " for Computer " & intComp+1 & " is" & ipAddress(intRoom, intComp))
    Next
    WScript.Echo vbCrlf

    Next
    End If

    Thank you
    Peter

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: VBScript run halfway

    See if updating that section with this does it.
    Code:
            ' Display All IP Address Y/N?
            Do
                ans = InputBox("Do you wish to Display all of the IP Address (Y/N) ...... ")
                ans = LCase(ans)
                WScript.Echo(Chr(7))
                WScript.Echo(Chr(7))
                If ans <> "y" And ans <> "n" Then
                    MsgBox("Error, Y,y,N,n response Only!!!")
                End If
            Loop Until ans = "y" Or ans = "n"
    
            If ans = "y" Then
                WScript.StdOut.WriteBlankLines(1)
                For intRoom = 100 To 105
                    For intComp = 1 To 4
                        WScript.Echo("The IP Address in Room " & intRoom + 100 & " for Computer " & intComp + 1 & " is" & ipAddress(intRoom, intComp))
                    Next
                    WScript.Echo(vbCrLf)
                Next
            End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    6

    Re: VBScript run halfway

    Thank you for your response. I try it and it is giving me an error on this line WScript.Echo("The IP Address in Room " & intRoom + 100 & " for Computer " & intComp + 1 & " is" & ipAddress(intRoom, intComp)) saying VBScript runtime error: Subscript out of rang: '100'. What's that mean since the room number is 100-105.

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2012
    Posts
    6

    Re: VBScript run halfway

    HI MarkT, I figure out what the problem is. I have to change '100 to 105' to '0 to 5' and '1 to 4' to '0 to 3' and it is working. Thank you for your help.

  5. #5
    New Member
    Join Date
    Jan 2013
    Posts
    1

    Re: VBScript run halfway

    ' ===================================
    ' 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.

    Option Explicit
    Dim ipAddress(5,3)
    Dim intRoom
    Dim intComp
    Dim ans

    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"

    'Prompt user for room number.
    Do Until intRoom >= 100 And intRoom =< 105
    intRoom = InputBox("Please enter the room number (100-105)...")
    If intRoom < 100 Or intRoom > 105 Then MsgBox("You must enter a value between 100 and 105!")
    WScript.Echo(Chr(7))
    Loop
    'Promt user for computer number.
    Do Until intComp >= 1 And intComp <= 4
    intComp = InputBox("Please enter the computer number (1-4)...")
    If intComp < 1 Or intComp > 4 Then MsgBox("You must enter a value between 1 and 4!")
    Loop

    MsgBox("Room: " & intRoom & vbNewLine & "Computer: " & intComp & vbNewLine & "IP Address: " & ipAddress(intRoom - 100, intComp - 1))


    'Display all IP Addresses
    Do
    ans = InputBox("Do you wish to Display all of the IP Address (Y/N) ...... ")
    ans = LCase(ans)
    WScript.Echo(Chr(7))
    WScript.Echo(Chr(7))
    If ans <> "y" And ans <> "n" Then
    MsgBox("Error, Y,y,N,n response Only!!!")
    End If
    Loop Until ans = "y" Or ans = "n"

    If ans = "y" Then
    WScript.StdOut.WriteBlankLines(1)
    For intRoom = 0 To 5
    For intComp = 0 To 3
    WScript.Echo("The IP Address in Room " & intRoom + 100 & " for Computer " & intComp + 1 & " is" & ipAddress(intRoom, intComp))
    Next
    WScript.Echo(vbCrLf)
    Next
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width