Help with code

Author Message
mathew

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 1/6/2012
  • Status: offline
Help with code Friday, January 06, 2012 10:30 AM (permalink)
0
I have done my best but can seem to get my loop to stop. I am trying to make it run every 5 minutes on the hour. Any help would be great
 
strComputer = "."
Set objNetwork = CreateObject("Wscript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
Dim objNet
On Error Resume Next 
Set objNet = CreateObject("WScript.NetWork") 
Dim strInfo
strInfo = objNet.UserName 
strComputer = objNetwork.ComputerName
myLogOn = DateAdd ("n", 0, Time())
myEndTime = DateAdd ("n", 1, Time())
Do
If myLogOn > myEndTime Then
Wscript.Echo myLogOn & " is after " & myEndTime
'Exit Do

ElseIf myLogOn < myEndTime Then
'If last = Minute(current) Then
MsgBox "Please respond to the following message! Press OK"
MsgBox "This is a message from Information Services. We have recognized that this PC " & strComputer & " has not been migrated to the domain." & vbNewLine & "Please call Mathew in Information Services by dialing. " & vbNewLine & "Or please leave Voice Message with the following information: " & vbNewLine & strInfo & vbNewLine & strComputer & vbNewLine &"myLogOn Location of your PC " & vbNewLine & "Contact Number"
End If
Loop While myLogOn < myEndTime
 
 
#1
    59cobalt

    • Total Posts : 972
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: online
    Re:Help with code Friday, January 06, 2012 2:32 PM (permalink)
    0
    mathew
    myLogOn = DateAdd ("n", 0, Time())
    myEndTime = DateAdd ("n", 1, Time())
    Do
     '...
    Loop While myLogOn < myEndTime
    Neither myLogOn nor myEndTime ever change. And since you defined myEndTime as myLogOn + 1 min the condition "myLogOn < myEndTime" is always true. Thus your loop never terminates.
     
    #2
      mathew

      • Total Posts : 4
      • Scores: 0
      • Reward points : 0
      • Joined: 1/6/2012
      • Status: offline
      Re:Help with code Friday, January 06, 2012 3:05 PM (permalink)
      0
      Then how would you suggest the change? Thanks for your time!
      Mat
       
      #3
        59cobalt

        • Total Posts : 972
        • Scores: 91
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: online
        Re:Help with code Saturday, January 07, 2012 2:51 AM (permalink)
        0
        That depends on what you actually want to do. If you merely want the loop to terminate after 5 minutes, you need to check if the current time is greater than myEndTime. I'd recommend to use timestamps (including the date) rather than just Time for this, because otherwise you might run into issues when the date changes.
        myEndTime = DateAdd ("n", 5, Now)
        Do
         '...
        Loop While Now < myEndTime
        However, if you want to run some task every 5 minutes, It's probably more appropriate to remove the loop entirely and set up a scheduled task that runs the script every 5 minutes.
         
        #4
          mathew

          • Total Posts : 4
          • Scores: 0
          • Reward points : 0
          • Joined: 1/6/2012
          • Status: offline
          Re:Help with code Saturday, January 07, 2012 8:12 AM (permalink)
          0
          wow, something that simple. What was the logic behind that fix? Does Now automatically populate with current time and checks itself against the declared end time?
          Thanks for your help
           
          #5
            59cobalt

            • Total Posts : 972
            • Scores: 91
            • Reward points : 0
            • Joined: 7/17/2011
            • Status: online
            Re:Help with code Saturday, January 07, 2012 8:51 AM (permalink)
            0
            Yes, the builtin functions Time, Date and Now always return the current date and/or time.
             
            #6

              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-2012 ASPPlayground.NET Forum Version 3.9