Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #718

Re: Scrollbar 'Freeze'

From xyzzy <xyzzy1974@gmail.com>
Newsgroups comp.lang.basic.visual.misc
Subject Re: Scrollbar 'Freeze'
Date 2012-01-24 04:19 -0800
Organization http://groups.google.com
Message-ID <55866321-5e7f-4e51-a15d-575d6d24f83f@w4g2000vbc.googlegroups.com> (permalink)
References <906f3a4b-3563-41e5-9143-0d861848058a@c8g2000yqc.googlegroups.com> <jflhvg$ff8$1@dont-email.me>

Show all headers | View raw


On Jan 24, 6:07 am, "Bob Butler" <bob_but...@cox.invalid> wrote:
.
.
.
This is very interesting, and thank you very much for your response. I
am going to print it out & study it to unlearn all those bad habits :
( & then relearn some correct programming procedure. Comments:

> > Option Explicit
> > Private mbUnload As Boolean
> > Private mbRestart As Boolean

What does the mb signify? Something-boolean presumably.

> > Option Explicit
> > Dim BallX, BallY, OldBallX, OldBallY, Gravity, Xmomentum, Ymomentum,
> > Mass, Time As Single, LeftToRight, Falling As Boolean
>
> The above declaration creates 9 variants, 1 single, and 1 boolean;I don't
> think that's what you want.  You have to use the "As" clause or a type
> suffix character on every variable to avoid using variants.

That's a revelation, I never knew that. For years I have been using
this method to declare multiple variables as the same datatype. Also,
am I correct in assuming that the Singles could be defined as
Integers, or, if any kind of division is used on the variables, Single
should be used?

> > Time = Timer
>
> 'Time' is a VB function; you can re-use the name as avariable but it makes
> the code harder to read
>
> > Do
> > DoEvents
> > Loop Until Timer - Time >= 2
>
> Using 'Timer' for a delay can cause problems if you happen to be running it
> when it resets

Good point.

> > Private Sub Form_Unload(Cancel As Integer)
> > End
> > End Sub
>
> Don't use END; there are situations where it does not allow applications to
> clean up correctly.  It is never needed and can result in memory/resource
> leaks.  Use another flag to tell your loops to shut down and let the form
> unload and the app exit gracefully.

Hm. As I understood it, in VB6 you could use END if you had only a
single form, and if you had multiple forms you should use UNLOAD ME.
Could I not use:

Private Sub Form_Unload(Cancel As Integer)
  Unload Me
End Sub

> It's too late now and I'm too tired to figure out exactly what this is
> supposed to be doing (the xmomentum seems to dampen way too much too fast)..

Yeah it's quick & dirty. I need to study proper gravity/momentum
routines.

> Private Sub Form_Activate()
> Dim dNow As Date
> Dim BallX!, BallY!, OldBallX!, OldBallY!, Gravity!, Xmomentum!, Ymomentum!,
> Mass As Single
> Dim LeftToRight As Boolean, Falling As Boolean

So variables should always be defined locally if they're not used
outside of that event procedure?

>     If Falling Then
>       Ymomentum = Ymomentum + Gravity * Mass
>     Else
>       Ymomentum = Ymomentum - Gravity * Mass
>     End If
>     If Ymomentum <= 0 Then Falling = True
>     If Falling Then
>       BallY = BallY + Ymomentum * Gravity
>     Else
>       BallY = BallY - Ymomentum * Gravity
>     End If

So I'm assuming It'd good programming practice to break up IF THEN
ELSE statements instead of having it all on one line.

>     Me.PSet (BallX, BallY)
>     Me.Refresh

Is it necessary in VB6 to use 'Me' if you have only one form?

>   dNow = Now
>   Do Until mbUnload Or mbRestart Or DateDiff("s", dNow, Now)

I am correct that pauses for 1 second? How would I make that say 3
seconds?

> Private Sub Form_Load()
> Me.AutoRedraw = True
> End Sub

Is it necessary to define the AutoRedraw property at run-time - can it
not be done at design time?

Again, thank you very much for your help.

Leo

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Scrollbar 'Freeze' xyzzy <xyzzy1974@gmail.com> - 2012-01-23 18:25 -0800
  Re: Scrollbar 'Freeze' "Bob Butler" <bob_butler@cox.invalid> - 2012-01-23 22:07 -0800
    Re: Scrollbar 'Freeze' xyzzy <xyzzy1974@gmail.com> - 2012-01-24 04:19 -0800
      Re: Scrollbar 'Freeze' "Bob Butler" <bob_butler@cox.invalid> - 2012-01-24 08:59 -0800
        Re: Scrollbar 'Freeze' xyzzy <xyzzy1974@gmail.com> - 2012-01-24 12:13 -0800

csiph-web