wait function
wait function
wait function
wait function
wait function
wait function wait function wait function wait function wait function wait function wait function wait function
wait function wait function
wait function
Go Back  Xtreme Visual Basic Talk > > > wait function


Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2012, 09:41 AM
bobbyb bobbyb is offline
Newcomer
 
Join Date: Aug 2008
Location: Sheffield, UK
Posts: 9
Question wait function


I'm not sure if this is the right place.

I'm having some trouble doing a wait function, i have searched all over Google and many people offering advice.

I'm using Microsoft Visual Studio Ultimate 2012. every option i try an use just brings up an error. the code that im using is:

Code:
Private Sub Wait(p1 As Integer)
        Throw New NotImplementedException
        Dim Target As Date

        Target = Now + (1.0# / 24.0# / 60.0# / 60.0# * Seconds)

        While Target > Now
            DoEvents()
        End While
    End Sub
and this is what i'm trying to do with it

Code:
Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ProgressBar1.Minimum = 0
        ProgressBar1.Maximum = 30
        ProgressBar1.Value = 0

        Label1.Text = "D A T A   L I N K   C O N N E C T I N G"
        ProgressBar1.Increment(10)
        Wait(10)
        Label1.Refresh()
        Label1.Text = "Loading Main Core Files..."
        ProgressBar1.Increment(10)
        Wait(10)
        Label1.Refresh()
        Label1.Text = "Launching Access Control"
        ProgressBar1.Increment(10)

        If ProgressBar1.Value = 100 Then
            Form2.Show()
            Me.Hide()
        End If
    End Sub
but when i run my project these are the 2 errors i keep getting

Error 1 'Seconds' is not declared. It may be inaccessible due to its protection level.

Error 2 'DoEvents' is not declared. It may be inaccessible due to its protection level.


any ideas on this?
Reply With Quote
  #2  
Old 10-15-2012, 09:59 AM
Gruff's Avatar
Gruffwait function Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

bobby,

There is an API declaration called Sleep. It is meant for inserting delays.

'--- In a bas module ---
Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)


Working with a database and a progress bar is always a problem as database mining is a high priority process.

A better approach is to either write an ActiveX EXE that runs a compiled progress bar as a separate thread or spawn a separate thread at run-time.

A third option is to allow progress feedback from the database, however this can slow down your database processing significantly.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 10-15-2012, 10:50 AM
bobbyb bobbyb is offline
Newcomer
 
Join Date: Aug 2008
Location: Sheffield, UK
Posts: 9
Default

its not actually loading anything from a database its basically for show to make it look like its doing something when in fact its not.

what i'm trying to achieve is as the progress bar gets to certain points the label will change the text that's being displayed. I want it to wait around about 3 seconds before it updates the label again with something else.

does that make any sense?
Reply With Quote
  #4  
Old 10-15-2012, 12:37 PM
passel's Avatar
passelwait function passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Part of the problem might be that you're using the latest "Visual Studio Ultimate 2012" .Net version of Visual Studio, but you're posting in a forum for Legacy VB, the last which is VB6 came out in 1998.
You're also trying to use 14 year old, i.e. VB6, code.

You should be able to show your form, create a timer to send you periodic ticks, update your progress bar in the timer event, and when you reach 100%, dispose of your timer, show your second form, and hide the current form.
No reason to loop your code and wait.

I'll move this to the appropriate side of the forum, which would be the .Net side.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 10-15-2012, 12:44 PM
PlausiblyDamp's Avatar
PlausiblyDampwait function PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Given the very first line of the routine throws an exception it isn't really surprising that you are getting an error when using it.

Also of you are trying to introduce a delay then you really don't want to just use a loop as it will simple eat CPU cycles to achieve nothing, .Net provides a System.Threading.Thread.Sleep method as a means of pausing execution.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #6  
Old 10-15-2012, 02:26 PM
passel's Avatar
passelwait function passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

The problem with Thread.Sleep is keeping the GUI responsive in an easy manner.
You can use short periods of sleep repeatedly, but would still need to DoEvents to handle Paint events, etc.
Using a timer would be the best approach, I think, for this particular situation. Along the lines of:
Code:
Public Class SplashScreen1
  Dim WithEvents waittime As New Timer

  Private Sub SplashScreen1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ProgressBar1.Minimum = 0
    ProgressBar1.Maximum = 30
    ProgressBar1.Value = 0

    Label1.Text = "D A T A   L I N K   C O N N E C T I N G"
    ProgressBar1.Increment(10)
    AddHandler waittime.Tick, AddressOf waitTime_tick
    waittime.Interval = 3000   '3 secoonds between ticks
    waittime.Start()           'Start the timer
  End Sub

  Private Sub waitTime_tick(sender As System.Object, e As System.EventArgs)
    Static eventCnt As Integer                            'Make it static so it retains its value between ticks

    eventCnt += 1                                         'Count the ticks

    Select Case eventCnt
      Case 1                                              'First tick
        Label1.Text = "Loading Main Core Files..."
        ProgressBar1.Increment(10)

      Case 2                                              'Second tick
        Label1.Text = "Launching Access Control"
        ProgressBar1.Increment(10)

      Case 3                                              'Last tick
        waittime.Stop()                                   'Stop the timer
        waittime.Dispose()                                'Dispose of it, we don't need it any longer
        Me.Hide()                                         'hide this form (but because it is the main form)
        Form2.ShowDialog()                                'Show the new form modal so it doesn't exit with the unloading of this form.
        Me.Close()                                        'This won't happen until Form2 is closed

    End Select
  End Sub
End Class
Normally, your splash screen would be a secondary form that you show, and then you would display the main form. This allows the secondary form to be shown normally, and then exit when no longer needed. Using the starting form for the splash screen means it has to stick around until the application exits.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
function, wait


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
wait function
wait function
wait function wait function
wait function
wait function
wait function wait function wait function wait function wait function wait function wait function
wait function
wait function
 
wait function
wait function
 
-->