×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ON OFF SHAPE

ON OFF SHAPE

ON OFF SHAPE

(OP)
HI THERE:

I JUST WANT YO HAVE THIS SHAPE (CIRCLE) TO BE ON AND OFF 20 TIMES USING THE FOLLOWING CODE:
(WHEN THIS ROUTINE IS RAN THE SHAPE GOES ON (BLACK DEFAULT) AND NEVER GOES OFF. HELP, WHAT I AM DOING WRONG????
Private Sub cmdOnoff_click()
dim b
dim t
For b = 1 to 20
shpOnoff.visible = true
For t = 1 to 3000
picTimer.cls
picTimer.print t
next t
shpOnoff.visible = false
next b
end sub
THANKS IN ADVANCE. RAFAEL

Rafael

RE: ON OFF SHAPE

You have a delay loop after you turn the shape on, you need another delay loop after the line
"shpOnoff.visible = false"
because the next thing that happens is your loop turns the shape back on. The loop is executing so quickly that the shape never appears to turn off.

RE: ON OFF SHAPE

Slight aside from the actual question, but the FOR loop to create the time delay doesn't seem the best to me. During execution, it will "hog" the processor.

Why don't you use a timer, that is enabled by cmdOnOff_Click

RE: ON OFF SHAPE

(OP)
HI THERE

TO COWSKI:

FOR B = 1 TO 20
SHPONOFF.VISIBLE = TRUE  (IT IS FALSE IN DEFAULT PROP.)
FOR T = 1 TO 3000
NEXT T
SHPONOFF.VISIBLE = FALSE
FOR H = 1 TO 3000
NEXT H
NEXT B

First routine I sent had shponoff.visible = true in default properties and the shape was shown and never went off like you said it needed a delay loop at the end of shponoff.visible = false. So I made the above changes. Now the shape never show up. I am sure I am not considering something else here. Tomatge made the point to use a timer (will discussed later) but I still have the curiosity of why is not working with the For Next loops. Any help from you on this matter will be very appreciated.

To Tomatge:

I have tried this with a timer with this code

Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Timer1_Timer()
Shape1.Visible = True
Timer1.Enabled = False
Timer2.Enabled = True

End Sub

Private Sub Timer2_Timer()
Shape1.Visible = False
Timer2.Enabled = False
Timer1.Enabled = True
End Sub

I am trying to enable timer1 with the command button but once the form is loaded the timers start executing. Obviously I have something wrong in the way I am tryin to do this. Your hep again will be very appreciated.

Thanks to both in advance or whoever wants to help me on this.

Rafael

Rafael

RE: ON OFF SHAPE

Rafael,

You only need a single timer - turn it on with Command1 and off with Command2. The code in the timer function will be relatively simple - if the shape is visible, make it invisible and vice versa.

To keep track of the number of changes, you will need to define a variable as static within the function. Every time the shape is switched on, increment that variable.

RE: ON OFF SHAPE

electron,

Depending on the speed of your computer
For T=1 to 3000
next T
may not be a very long loop. You may need to increase this number (maybe try 30000 - getting close to the limit of an integer type, or switch to long type and go even higher). Also, you may want to put a DoEvents command in your loop as this will allow your computer to process other windows messages while you wait for your loop to finish.

Using the timer is an excellent idea, it will simplify things and the length of the delay will not be dependent on the speed of the computer that you run your program on.

RE: ON OFF SHAPE

electron,

I finally got a chance to test the loop code. It seems you need to have that DoEvents in the pause loops:
For T = 1 To 3000
DoEvents
Next T
as this will allow the form to update properly.

good luck

RE: ON OFF SHAPE

Would this work?
Copy and Paste into Code window to view comments

Private Sub cmdOnOff_Click()

    'this will change the caption on the command button
    'and be used as a flag to stop the timer prematurely
If cmdOnOff.Caption = "On" Then
    cmdOnOff.Caption = "Off"
    Timer1.Enabled = True
Else
    cmdOnOff.Caption = "On"
    Timer1.Enabled = False
End If
    'If the premature stop is not desired then remove
    'the timer1.enabled = true and
    'timer1.enabled = false and uncomment the line below
    'This will cause the timer to oscillate
    'each time the command is pressed
    
'Timer1.Enabled = Not Timer1.Enabled

End Sub

Private Sub Timer1_Timer()
Static icount As Integer

   icount = icount + 1
    'This will count how many times the timer fires
    'and will stop after showing the shape 20 times
    'The timer fires both when the shape is visible
    'and when it is not.
    If icount >= 39 Then
        'disable the timer and reset the counter
        Timer1.Enabled = False
        icount = 0
    End If
    
    'Each time the timer fires the shape will change from
    'being visible to NOT being visible
shpOnOff.Visible = Not shpOnOff.Visible

End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close