Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey guys, this is my first post here. I'm a newbie to Visual Basic in general and I need help with a very simple thing, I just can't quite figure it out on my own. I'm making a small program that consists of 1 picture box and 1 command box. When I click the command box it says "Hey guys" in the picture box. Now I have all of it up to here, but when I keep clicking the command button it keeps printing "Hey guys" in the picture box. What is the code for making it say it once, meaning even if I click the command button 300 times it will only print "Hey guys" once in the picture box. Thanks guys, a quick response would be appreciated.

There is problably a number of ways to do this but the most straight forward to me would be to create a boolean variable, initialize it to true and then set it to false when ever the command button is pressed. Finally, only allow the text to be sent/updated to the picture box when the boolean variable is true. To make it easy to recognize or remember you may want to call it something like FirstTime or something similar. In other words, use a boolean variable to track when the first time the button is clicked was and change that variable within the onclick method for the command button. Use the value of the boolean variable to determine if it is the first time through or not and go from their.
borelli34@cox.net

In your "on-click" event
Clear the contents of your picture box
then print "Hey Guy's"No matter how many times you click the button "Hey Guy's" will only show up once.
George

To: Borelli, I don't know what you're talking about, boolean variables and such, I'm a newbie. And to George, can you be more specific, it is sort of vague. Guys there is a much easier way to do this. It's simple, I just forgot the code, it's something with .Cls (ClearScreen)

hey danny
here is a very easy way
when the button is pressed
write the last line something like thiscommand1.enabled=false
And the user wont be able to press it more
than 1 timeSimple righ

========================================================================================
Danny,Sorry, about that. It can be easy to make certain assumptions sometimes. A boolean variable is a variable that can be one of only two values. Either true or false. As to clearing the contents of your picture box, that can create flicker and is a bad habit to get into programming wise. Besides, SP has the best (and most professional way) to do it. The line SP suggested (command1.enabled=false) will disable the command button after its first use as long as it is placed at the end of the on-click method. By the way, to get to the code for the on-click method simply double click the command button within the form disigner and it will jump you to the newly created on-click procedure for that command button.
borelli34@cox.net
========================================================================================

Guys, I don't want to lock the command button. I want to continue to press the command button, but the contents in the picture box will only appear once. I said it twice already, it has to do with .CLS (clear screen) Something like that. Again, I do not want to lock the command button, I want to be able to click it a hundred times and the contents in the picture box to only appear once. Thanks everyone.

Following is code for using either borelli's boolean idea or using the .cls that you mentioned:
Private Sub Command1_Click()Static flgPrinted As Boolean
If flgPrinted = False Then
Picture1.Print "text"
flgPrinted = True
End IfEnd Sub
Private Sub Command1_Click()
Picture1.Cls
Picture1.Print "text"End Sub

Private Sub Command1_Click()
Picture1.Cls
Picture1.Print "text"End Sub
That's all I wanted! Thanks a bunch HiJinx!

![]() |
What is wrong with this A...
|
Playing a CD clip on an h...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |