Welcome !
         

 How do I do to identify one of those "else" and perform an action?

Author Message
igorvieira

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 10/19/2015
  • Status: offline
How do I do to identify one of those "else" and perform an action? Monday, October 19, 2015 9:51 AM (permalink)
0
Hi Guys!
 
I want to identify if some of these 3 variables have "Not working". If yes, I want to perform Response.Write " Some is Not Working ". Can you help me with?
 
 
 
 
 
 
Set metric1 = server.Createobject("MSXML2.ServerXMLHTTP.6.0")
metric1.open "GET", "https://mysite1.com",false
metric1.send("")

If metric1.Status >= 404
  Response.Write " Not Working "
Else
  Response.Write " Working "
End If



Set metric2 = server.Createobject("MSXML2.ServerXMLHTTP.6.0")
metric2.open "GET", "https://mysite2.com",false
metric2.send("")

If metric2.Status >= 404
  Response.Write " Not Working "
Else
  Response.Write " Working "
End If
 

Set metric3 = server.Createobject("MSXML2.ServerXMLHTTP.6.0")
metric3.open "GET", "https://mysite3.com",false
metric3.send("")

If metric3.Status >= 404
  Response.Write " Not Working "
Else
  Response.Write " Working "
End If
 
#1
    chancity

    • Total Posts : 224
    • Scores: 46
    • Reward points : 0
    • Joined: 6/24/2014
    • Status: offline
    Re:How do I do to identify one of those "else" and perform an action? Tuesday, October 20, 2015 4:15 AM (permalink)
    0
    Not entirely sure what you're looking for but you left out "Then" in all of your if statements.
    Dim HTTPGet : Set HTTPGet = Createobject("MSXML2.ServerXMLHTTP.6.0") 
     HTTPGet.open "GET", "http://www.visualbasicscript.com/asdfgfhhj",false 
     HTTPGet.send("") 
       
     If HTTPGet.Status >= 404 then 
       WScript.Echo " Not Working " 
     Else 
       WScript.Echo " Working " 
     End If 
       
     HTTPGet.open "GET", "http://www.visualbasicscript.com/asdfgfhhj",false 
     HTTPGet.send("") 
       
     If HTTPGet.Status >= 404 then 
       WScript.Echo " Not Working " 
     Else 
       WScript.Echo " Working " 
     End If 
       
     HTTPGet.open "GET", "http://www.visualbasicscript.com/asdfgfhhj",false 
     HTTPGet.send("") 
       
     If HTTPGet.Status >= 404 then 
       WScript.Echo " Not Working " 
     Else 
       WScript.Echo " Working " 
     End If
    Here's another way to do it that could possibly be better at handling errors.
     Dim Request1 : Request1 = HTTPGet("http://www.visualbasicipt.com/asdfgfhhj") 'BAD URL
     Dim Request2 : Request2 = HTTPGet("http://www.google.com") 'GOOD URL
      
     If Request1(0) Then 'BAD URL
                     If Request1(1).Status >= 404 then
                                     WScript.Echo " Not Working "
                     Else
                                     WScript.Echo " Working "
                     End If
     Else
                     WScript.Echo Request1(1) 'vbscript error message
     End If
      
     If Request2(0) Then 'GOOD URL
                     If Request2(1).Status >= 404 then
                                     WScript.Echo " Not Working "
                     Else
                                     WScript.Echo " Working "
                     End If
     Else
                     WScript.Echo Request2(1) 'vbscript error message
     End If
      
     Private Function HTTPGet(URL)
                     On Error Resume Next
                     Dim GetReturn(2)
      
                     Dim GetRequest : Set GetRequest = Createobject("MSXML2.ServerXMLHTTP.6.0")
                     GetRequest.open "GET", URL, False
                     GetRequest.send("")
      
                     If Err.Number <> 0 Then
                                     GetReturn(0) = False
                                     GetReturn(1) = Err.Description
                                     Err.Clear
                     Else
                                     GetReturn(0) = True
                                     Set GetReturn(1) = GetRequest
                     End If
      
                     HTTPGet = GetReturn
     End Function

     
    <message edited by chancity on Tuesday, October 20, 2015 4:30 AM>
     
    #2
      igorvieira

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 10/19/2015
      • Status: offline
      Re:How do I do to identify one of those "else" and perform an action? Wednesday, October 21, 2015 1:35 AM (permalink)
      0
      Hi! Thank you for your time
       
       
      Does HTTPGet is a function?
      I see like a global variable, I liked it
       
      #3
        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2017 ASPPlayground.NET Forum Version 3.9