CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Need help in running progress bar and other code parallely on click event in VB6.0

    I am facing one issue; on the button click event see the code in red color, I have a timer and I am invoking qtp and also running a qtp test. What I am trying to do is till the system loads the qtp, I want to run the progress bar. The code is correct but the progress bar does not run in parallel with the qtp invoking code. If I comment the invoking part and run then the progress bar shows progress. Please help
    Private Sub Ok_Click()
    If update.Value = True Then
    WinExec "Explorer.exe " & "C:\ ", 10
    ElseIf copy.Value = True Then
    WinExec "Explorer.exe " & "C:\ ", 10
    ElseIf run.Value = True Then
    Main.Timer1.Enabled = True
    Set obj = CreateObject("QuickTest.Application") 'Creates an instance of the QTP
    Sleep 100
    obj.Launch
    obj.Visible = True
    obj.WindowState = "Maximized" 'Maximizes the application window of the QTP
    obj.Open "C:\<path>" 'Opens the script from in an editable mode
    obj.Test.run 'Runs the script
    obj.Quit 'Quits the QTP application
    End If
    End Sub
    Private Sub Timer1_Timer()
    If Timer1.Enabled = True Then
    ProgressBar1.Value = ProgressBar1.Value + 2
    End If
    If ProgressBar1.Value = 100 Then
    Main.Timer1.Enabled = False
    Main.ProgressBar1.Value = 0
    End If
    End Sub

  2. #2
    Join Date
    Apr 2012
    Posts
    3

    Re: Need help in running progress bar and other code parallely on click event in VB6.

    I am facing one issue; on the button click event see the code in red color, I have a timer and I am invoking qtp and also running a qtp test. What I am trying to do is till the system loads the qtp, I want to run the progress bar. The code is correct but the progress bar does not run in parallel with the qtp invoking code. If I comment the invoking part and run then the progress bar shows progress. Please help
    Private Sub Ok_Click()
    If update.Value = True Then
    WinExec "Explorer.exe " & "C:\ ", 10
    ElseIf copy.Value = True Then
    WinExec "Explorer.exe " & "C:\ ", 10
    ElseIf run.Value = True Then
    Main.Timer1.Enabled = True
    Set obj = CreateObject("QuickTest.Application") 'Creates an instance of the QTP
    Sleep 100
    obj.Launch
    obj.Visible = True
    obj.WindowState = "Maximized" 'Maximizes the application window of the QTP
    obj.Open "C:\<path>" 'Opens the script from in an editable mode
    obj.Test.run 'Runs the script
    obj.Quit 'Quits the QTP application
    End If
    End Sub
    Private Sub Timer1_Timer()
    If Timer1.Enabled = True Then
    ProgressBar1.Value = ProgressBar1.Value + 2
    End If
    If ProgressBar1.Value = 100 Then
    Main.Timer1.Enabled = False
    Main.ProgressBar1.Value = 0
    End If
    End Sub

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Need help in running progress bar and other code parallely on click event in VB6.

    You could try to use the Timer API. Her is how to do it:
    You have to put the following code in a Module. It does not run within a Form.
    Code:
    Option Explicit
    
    Public Declare Function SetTimer Lib "user32" ( _
           ByVal hwnd As Long, ByVal nIDEvent As Long, _
           ByVal uElapse As Long, ByVal lpTimerFunc As Long _
      ) As Long
    
    Public Declare Function KillTimer Lib "user32" ( _
           ByVal hwnd As Long, ByVal nIDEvent As Long _
      ) As Long
    
    Private TimerID As Long
    
    Public Sub StartTimer(IntervalTime as Long)
    
      TimerID = SetTimer(0, 0, IntervalTime, AddressOf TimerEvent)
    
    End Sub
    
      
    Public Sub TimerEvent(hwnd As Long, msg As Long, idTimer As Long, dwTime As Long)
      'timed code goes here
      Main.ProgressBar1.Value = Main.ProgressBar1.Value + 2
      If Main.ProgressBar1.Value = 100 Then KillTimer 0, TimerID
    End Sub
    To start the timer you call StartTimer 500 (for interval of 500msec)
    The Timer API calls repeatedly the sub TimerEvent, in which you increment your Progressbar.
    Timer API works in most cases also there, where the Timer control locks out.

  4. #4
    Join Date
    Apr 2012
    Posts
    3

    Re: Need help in running progress bar and other code parallely on click event in VB6.

    Thanks WoF, I will try this out.

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

Featured