Novice question - Controlling one control with another 
Author Message
 Novice question - Controlling one control with another

I'm stumbling through my first week of programming with Visual Basic 5.
What I want to do must be pretty easy, but I can't for the life of me see
how to do it.

I have a form with two command buttons.  I want to be able to click on one
and start a counter.  When I click on the other I want the counter to stop.

I think the problem is that once the program gets in the loop that does the
counting it doesn't give focus back to the command buttons.  How do I do
that?

Very confused and getting frustrated in Philadelphia,

Michael Tordoff



Tue, 08 Jan 2002 03:00:00 GMT  
 Novice question - Controlling one control with another

Quote:

>I'm stumbling through my first week of programming with Visual Basic 5.
>What I want to do must be pretty easy, but I can't for the life of me see
>how to do it.

>I have a form with two command buttons.  I want to be able to click on one
>and start a counter.  When I click on the other I want the counter to stop.

>I think the problem is that once the program gets in the loop that does the
>counting it doesn't give focus back to the command buttons.  How do I do
>that?

Michael,
    Try putting a DoEvents inside the body of the counting loop.
- Jim

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/vb         The website for VB programmers.



Tue, 08 Jan 2002 03:00:00 GMT  
 Novice question - Controlling one control with another
Add a timer to your form (Timer1).  Set it interval to 1000 (= 1 sec), and set
Enabled = False.
cmd_Start is your start button name, cmd_Stop is your stop button name (rename
them).
In cmd_Start_Click add the code Timer1.Enabled = True
In cmd_Stop_Click add the code Timer1.Enabled = False
In the Timer1_Timer add the code...
static Count as Long
Count = Count + 1
Label1.Caption = Cstr(Count) '//The current count is displayed in Label1....add
a Label to the Form.

I guess that you put the Count inside a loop, which is why once you started it
nothing else happens.
The loop does not let any other events in your program occur causing program to
crash or "Hang".
VB is event oriented, instead of sequence oriented.

Quote:

> I'm stumbling through my first week of programming with Visual Basic 5.
> What I want to do must be pretty easy, but I can't for the life of me see
> how to do it.

> I have a form with two command buttons.  I want to be able to click on one
> and start a counter.  When I click on the other I want the counter to stop.

> I think the problem is that once the program gets in the loop that does the
> counting it doesn't give focus back to the command buttons.  How do I do
> that?

> Very confused and getting frustrated in Philadelphia,

> Michael Tordoff



Wed, 09 Jan 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Novice VB4 Data Control question...

2. Run-time creation of controls - novice question

3. Novice Data Control question...

4. Novice Question: VB controls and C or Pascal code

5. more mouse control, and keeping the focus on ONE control

6. How to select one type of control in control collection

7. SSTab Control problem-vb 4.0 (controls doesnt appear except on one tab )

8. How to put only one control per control

9. Tree control / List view in ONE control?

10. How to put only one control per control

11. (Novice) Speaker volume control

12. VB5: Changing one control to another one.

 

 
Powered by phpBB® Forum Software