Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Whats wrong with this code?

Do While X = 0

strAns2 = InputBox _

("Enter IP Address of the Server:","Create File")

If strAns2 = "" Then

elseif Left(strAns2, 3) > "255" then

Wscript.Echo "Please enter a valid first octet Address."

elseif Mid(strAns2, 3, 3) > "255" then

Wscript.Echo "Please enter a valid second octet Address."

elseif Mid(strAns2, 6, 3) > "255" then

Wscript.Echo "Please enter a valid third octet Address."

elseif Right(strAns2, 3) > "255" then

Wscript.Echo "Please enter a valid fourth octet Address."

Exit Do

End If

Loop

Update:

The problem is defining the anything beyond the second octet. My input box allows me to enter an unformated IP Address and checks each octet for validity.....Well I would like it to anyway. The loop is to prevent you from bypassing this information in the event it is not entered or an invalid address range.

It check the first octet fine by fails on the second octet whether the octets range is valid or not.

GSun - the condition is that strAns2 is not nul

Lucien - The syntax for strAns2 is correct

Phillip B - Good try but your code produces the same error

3 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    where is the condition for the if strAns2="" ????

    what type of error is it giving you?

  • 1 decade ago

    well there looks to be a couple of things wrong with this code....

    I don't think you need a while loop to do this. if you only want to check to see if the server's IP address is formatted correctly, just use an if statement. There is no need for a while loop.

    Code I would use to check the input:

    strAns2 = InputBox _

    ("Enter IP Address of the Server:","Create File")

    If strAns2 = "" Then

    elseif Left(strAns2, 3) > "255" then

    Wscript.Echo "Please enter a valid first octet Address."

    elseif Mid(strAns2, 3, 3) > "255" then

    Wscript.Echo "Please enter a valid second octet Address."

    elseif Mid(strAns2, 6, 3) > "255" then

    Wscript.Echo "Please enter a valid third octet Address."

    elseif Right(strAns2, 3) > "255" then

    Wscript.Echo "Please enter a valid fourth octet Address."

    End If

    Hope this helps.

  • 1 decade ago

    In most languages there is a difference between '=' and '=='.

    Th first is an assignation operator, the second compares things.

    So I think your

    If strAns2 = ""

    should be

    If strAns2 == ""

Still have questions? Get your answers by asking now.