Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading Caption

Status
Not open for further replies.

Maxi15

Programmer
Feb 24, 2004
5
US
i have a progressbar that loads, while its loading i want it to display a caption at the top of the form that says loading, but for it to keep adding a period, like some other loading programs. for example loading loading. loading.. loading... loading loading. loading.. loading...

someone please help me
how can i do this?
 
You can adjust the caption when the progressbar's .value property is adjusted or add a timer and change the caption at regular intervals until the form is finished loading. Depends if you want the progress bar and caption to be in sync.

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
Maxi15,
You can try something like this to make the caption change like you mentioned:

Dim x As Byte

Private Sub Form_Load()
x = 0
End Sub

Private Sub Timer1_Timer()

Dim strcaption As String
Dim z As Byte

strcaption = "Loading"

' if x = 0 then don't add to the "Loading" string, else add one " ." for each count of x
For z = 1 To x
strcaption = strcaption & " ."
Next z

' set the form's caption = to the string variable
Me.Caption = strcaption

' increment x, and if it's > 3 then reset it to 0
x = x + 1
If x > 3 Then x = 0

End Sub

Hope this helps,

Don
 
can someone please explain this more to me i ont get it and i pasted the code and it doesnt work
 
Maxi15,
To test the code above, create a new project in VB. To the default form1, add a timer control. Sorry I forgot to mention adding the timer earlier. For this example, set the interval of the timer to 500 (half a second).

After adding the timer, then paste in the code exactly as it is above.

I don't mean to oversimplify things, but if you're new to VB, this explanation may help:

Dim x as Byte -- this is a general declaration, so x is a public variable used to control how many dots "." are in the caption. This variable is initialized to 0 when the form loads.

The code on the timer-
Dim strcaption as string -- Declare a string variable strcaption

Dim z as byte -- Declare a byte variable (bytes can be any number from 0 to 255) for use in the "for" loop below

strcaption = "Loading" -- make the default string = "Loading" (with no dots after it)

For z = 1 to x
strcaption = strcaption & " ."
Next z


This for loop is setting the string that will become the actual caption for the form. It appends the appropriate number of spaces and dots to "Loading", depending on the value of x.
If x = 0 then strcaption will be "Loading"
If x = 1 then strcaption will be "Loading ."
If x = 2 then strcaption will be "Loading . ."
If x = 3 then strcaption will be "Loading . . ."
If x > 3 then it will be reset to 0, and will start over again

Me.caption = strcaption -- This sets the forms caption to whatever the string variable strcaption contains

x = x + 1 -- Each time the timer event fires, x will be incremented, and the variable strcaption will be modified as described above.

If x > 3 then x = 0 -- If the most recent timer event set the caption to "Loading . . ." (where x = 3), then when it tries to increment it to 4, this will tell it to set it back to 0. When the timer event fires the next time, the caption will be back to just "Loading"

I hope this is what you're looking for. Just try this sample code, and when you understand it, you can add it to your existing form with the progressbar, etc.

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top