VScroll1 thinks it's enabled when it's disabled.

VScroll1 thinks it's enabled when it's disabled.

Post by Guy » Tue, 04 Dec 2007 04:25:35


Is there something I am missing? Why does the Beep statement execute after
I disable the scroll bar and manually change it's value? I'm using VB5.
Any info would be greatly appreaciated.
G.Doucet


Private Sub Command1_Click()
VScroll1.Enabled = False
End Sub

Private Sub Command2_Click()
VScroll1.Value = VScroll1.Value + 1
End Sub

Private Sub VScroll1_Change()
If (VScroll1.Enabled = True) Then
Beep
End If
End Sub
 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by Mike Willi » Tue, 04 Dec 2007 04:37:06


But you're not manually changing its Value. You are changing it in
code. If you look at the help files you'll se that the Enabled
property "Returns or sets a value that determines whether a form or
control can respond to user-generated events". In other words, setting
the Scroll Bar (or Text Box or just about any other control) Enabled
property to False only stops the user from changing it. But you can
still change it in code. That's just the way it works, and it's
exactly the same in VB6.

Mike

 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by Guy » Tue, 04 Dec 2007 05:03:03


XXXX@XXXXX.COM ...


Thanks again. I'm glad you're still here. What you say makes sense, and so
I can understand why the Change event is executed when I change its value
(even though the control is disabled). But still, the "Change Event" code
checks the "Enabled" property before Beeping, and it still beeps. I guess
it's not too important - I decided to set a Flag variable before changing
the value of the scroll bar.

Private Sub VScroll1_Change()
If (VScroll1.Enabled = True) Then
Beep
End If
End Sub

Guy
 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by Mike Willi » Tue, 04 Dec 2007 06:09:54


Oh right. I see what you mean now. I never noticed that. Very odd. I
get exactly the same behaviour in VB6. It appears that VB temporarily
sets the Enabled property back to True when your code alters its Value
property, and it remains True until after the ScrollBar's Change event
has finished, and then it reverts to False again. Weird one, that.

The same sort of thing does not happen with a TextBox. It seems to be
just the ScrollBar that behaves in that way (from the few tests I've
carried out so far). Interesting. Curiouser and curiouser, as Alice
would have said ;-)

So, it's not just you going daft. Not at all. Either VB is daft, or
we're both daft ;-)

Mike
 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by Guy » Tue, 04 Dec 2007 06:16:37

Thanks again,
Guy


XXXX@XXXXX.COM ...
 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by san7 » Thu, 06 Dec 2007 16:51:01

hello everybody


'please add this here instead of vscroll1_change event
If (VScroll1.Enabled = True) Then

endif


it will work but certainly vscroll should be daft.

regards
s.an
 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by Mike Willi » Thu, 06 Dec 2007 18:59:03


I think you've misunderstood the purpose of the question. The example
is not *real* code that the OP intends to actually use. It is just
some test code to demonstrate an apparent problem that he came across.
What the OP wants to know is why a disabled ScrollBar (Enabled =
False) apparently temporarily changes its Enabled property back to
True when you change its Value property in code and then immediately
changes it back to False again. Other controls do not behave in a
similar way and the OP was not expecting a ScrollBar to behave in that
way either, but it appears to actually be standard behaviour for a
ScrollBar in both VB5 and VB6.

Mike
 
 
 

VScroll1 thinks it's enabled when it's disabled.

Post by san7 » Fri, 07 Dec 2007 16:33:10


oh, ok thanks for your explanation mr.mike

br
s.an