For some reason, my program is running in a loop and the condition is being ignored.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alc21321
    New Member
    • Apr 2013
    • 1

    For some reason, my program is running in a loop and the condition is being ignored.

    I am trying to make a view bot. Just for recreational/personal use. The problem is I am trying to make it so it will only open 20 windows at a time. It won't work for some reason. I also want it to wait 2000 milliseconds before closing the process it generates and go into a loop. I have co1unt as an integer. Anyone help please?
    Code:
    Dim Co1unt As Integer = 0
    Public Sub Refreshlist()
        Dim p As Process, co1unt As Integer, MyProgram As String = "iexplore"
        For Each p In Process.GetProcesses
            If p.ProcessName = MyProgram Then
                co1unt = co1unt + 1
                TextBox1.Text = co1unt
            End If
        Next
    End Sub
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Refreshlist()
        Do
            Refreshlist()
            If Co1unt < 20 Then
                Dim webAddress As String = ""
                Dim p1 As Process = Process.Start(webAddress)
                System.Threading.Thread.Sleep(2000)
                p1.Kill()
            End If
        Loop
    
    End Sub
    Last edited by Rabbit; Apr 1 '13, 06:18 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Are you sure the process name is "iexplore"? On my task manager, it shows "iexplore.e xe *32"

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Actually you have a simple variable-scope bug, very easy to do, and very easy to miss.

      Variable Co1unt is defined (with different capitalisation, which VB doesn't really care about) both at the module level and within the sub Refreshlist. The variable you're adding 1 to only exists for the moment that you're in that sub (from line 3 to line 10).

      Thus the module-level variable doesn't change, and so will never reach 20.

      Comment

      Working...