Results 1 to 5 of 5

Thread: Challanging If Statement, Please Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    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?

  2. #2
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    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.



  3. #3
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    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]



  4. #4
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124

    Post

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    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
  •  



Click Here to Expand Forum to Full Width