|
-
Feb 8th, 2000, 12:15 PM
#1
Thread Starter
Hyperactive Member
Hi Thanks for looking at this for me.
I'm trying to do this:
Y is a public variable in a .bas module
The code in the form increments Y by 1 each time a button is pressed up untill 10.When
Y=10 I want Y to de-increment by 1 untill "0"
then increment by one again and so forth...
My problem is Y bangs into itself at 9 when I try to de-increment.Is there a way to do this? (Y must stay global to all 5 forms).
(suedo code 
ButtonPress event()
If Y < 10 Then
Y=Y+1
'when Y = 10 forget previous code then do this
Y=Y-1
'When Y = 0 let's increment it again
Y=Y+1
End If
End Sub
I think you get the idea.Is there some method to make this happen?
-
Feb 8th, 2000, 12:30 PM
#2
Hyperactive Member
First thoughts are why not create a static boolean variable - call it something like 'increment' initialise it to true and when you reach 10 you can set it to false and vice versa.
-
Feb 8th, 2000, 12:36 PM
#3
Frenzied Member
In the declarations;
Dim YDif as Integer
In the load event;
YDif=1
On the click event
Y=Y+YDif
If Y=10 Or Y=0 Then YDif=-YDif
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
-
Feb 8th, 2000, 12:37 PM
#4
Lively Member
Use this code for your .bas module. This will crate a property and will allow you to keep the value of Y between 1 and 9.
Code:
Private intY As Integer
Private bSubtractOne As Boolean
Public Property Let Y(intNewY As Integer)
If intNewY = 10 Then
bSubtractOne = True
End If
If intNewY = 2 Then
bSubtractOne = False
End If
intY = IIf(bSubtractOne, intY - 1, intY + 1)
End Property
Public Property Get Y() As Integer
Y = intY
End Property
Use the code in the Command1_click event for all your buttons.
Code:
Private Sub Command1_Click()
Y = Y + 1
Text1.Text = Y
End Sub
If this is not what your trying to do then try to clarify a little bit more.
-
Feb 8th, 2000, 12:37 PM
#5
Thread Starter
Hyperactive Member
Thank you,
Sometimes I look at things to much and don't see the obvious (obvious only after your answer though).Thank you for helping this will work great.
Joey O.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|