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


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

Re: Scrollbar 'Freeze'

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From "Bob Butler" <bob_butler@cox.invalid>
Newsgroups comp.lang.basic.visual.misc
Subject Re: Scrollbar 'Freeze'
Date Tue, 24 Jan 2012 08:59:54 -0800
Organization A noiseless patient Spider
Lines 151
Message-ID <jfmo66$fi1$1@dont-email.me> (permalink)
References <906f3a4b-3563-41e5-9143-0d861848058a@c8g2000yqc.googlegroups.com> <jflhvg$ff8$1@dont-email.me> <55866321-5e7f-4e51-a15d-575d6d24f83f@w4g2000vbc.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="iso-8859-1"; reply-type=original
Content-Transfer-Encoding 7bit
Injection-Date Tue, 24 Jan 2012 17:01:58 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="f+uu5lAFQHkCzTgLejqQBQ"; logging-data="15937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19t8+SV9ko6Rd4yj1oLsYFnmPRrNyQ7dvQ="
X-MimeOLE Produced By Microsoft MimeOLE V6.0.6002.18463
In-Reply-To <55866321-5e7f-4e51-a15d-575d6d24f83f@w4g2000vbc.googlegroups.com>
X-Newsreader Microsoft Windows Mail 6.0.6002.18197
Cancel-Lock sha1:nb0ZGJUy8n143vBNU7fu2w+Dq2o=
X-Priority 3
X-MSMail-Priority Normal
Xref x330-a1.tempe.blueboxinc.net comp.lang.basic.visual.misc:719

Show key headers only | View raw


"xyzzy" <xyzzy1974@gmail.com> wrote in message 
news:55866321-5e7f-4e51-a15d-575d6d24f83f@w4g2000vbc.googlegroups.com...
> 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:

"correct" is often a matter of opinion; I made changes that conformed to 
ways that have worked well for me.

> > > Option Explicit
> > > Private mbUnload As Boolean
> > > Private mbRestart As Boolean
>
> What does the mb signify? Something-boolean presumably.

module-level boolean value; I use a modified 'hungarian' notation that 
specifies the scope and the type


> > > 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?

That all depends on what type of math you need; use integers if you only 
need integer math and floating point if you need that.  You can use the \ 
operator to do integer division with floating points where appropriate.

> > > 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

You would not need to unload in the unload event -- it is already happening.
The problem is that your loop repeatedly references the form properties so 
if that happens after the form unloads VB will happily reload a new instance 
of the form.

> > 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?

As a general best practice I would say yes; encapsulation prevents unwanted 
side effects when you start re-using variables in other routines.  In a 
short,simple app it may not matter but if you always do it then it becomes a 
habit and you avoid problems in bigger apps.

> > 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.

I find it a lot easier to read

> > Me.PSet (BallX, BallY)
> > Me.Refresh
>
> Is it necessary in VB6 to use 'Me' if you have only one form?

No, but looking at your code I was getting confused with which things were 
properties and which were variables.  I also just always like being specific 
so I know exactly what the intention is.

> >   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?

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

> > 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?

It can but your post didn't mention that so in trying to duplicate your 
results I had to play around with the properties of the form.  I like 
setting things on code as much as possible so that I don't have to look in 
multiple places and don't forget to mention important factors.  I should 
have also added the scrollbar min/max/value settings.

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