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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a status bar 2

Status
Not open for further replies.

emik

MIS
Jul 24, 2006
80
CA
Hi guys,

I've created a percent counter by using this code in a loop, so with each iteration i and j get increased and a percentage is shown.

Dim strFormat as String
j = j + 1
Total_progress = j / i
strFormat = Format(Total_progress, "0%")
txtPercent.value = strFormat
Me.Refresh

The only way this works is if txtPercent has the focus, the problem is that it is always flickering and blue (like when you select the text in a box it first goes blue to select the whole word). I want it to look like a solid number without it constantly selecting the number and turning it blue. Is there anyway to do this?

Thanks
 
Try using a label instead and show the results in the Caption.
 
What happens if you replace this:
Me.Refresh
with this ?
DoEvents

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How are ya emik . . .
emik said:
[blue]The only way this works is if txtPercent has the focus, . . .[/blue]
This makes no sense as its the [blue]Text[/blue] property (not the value property) of a textbox that requires the control to have the focus. In fact the [blue]Value[/blue] property is the default returned property and is not needed:
Code:
[blue]    txtPercent = strFormat[/blue]
Also note: you need to explicitly identify controls:
Code:
[blue]    Me!txtPercent.value = strFormat
   or
    Me!txtPercent = strFormat[/blue]
To fix this you first need to [blue]get the focus off the control[/blue] by setting it somewhere else at the very beginning of your code. Making your code look like:
Code:
[blue]   Dim strFormat As String
    
   [green]'Beginning of code before your loops[/green]
   Me!SomeOtherTextboxName.[purple][b]SetFocus[/b][/purple]
   [green]' Your Code![/green]
   j = j + 1
   Total_progress = j / i
   strFormat = Format(Total_progress, "0%")
   [purple][b]Me!txtPercent[/b][/purple] = strFormat
   [purple][b]DoEvents[/b][/purple][/blue]
DoEvents is the suggestion by [blue]PHV[/blue] and allows events & processes to complete allowing the control to update more thoroughly.

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hey it works! Thanks for all the suggestions.

A few follow up questions, why do I need to explicitly identify controls?

eg: why is Me!txtPercent different from just txtPercent since it's on the current form?

Lastly what exactly does "DoEvents" do? If the code is running, why is it necessary to have this?

Thank you again. I also got rid of another problem (with the original code, if i clicked the screen while the counter was going the program would freeze.).
 
what exactly does "DoEvents" do?
Put the cursor inside this word in your code and press the F1 key.
 
Yes I did that, but it's in very technical terms. I'm looking for a more english translation on when I should be using it. Yielding control to the operating system and returning a value of open VB forms doesn't help me understand why it works in this particular instance.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top