+ Reply to Thread
Results 1 to 4 of 4

Why wont this work?....Ontime + Now

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310

    Why wont this work?....Ontime + Now

    Please help with this, I am using 2 button presses to swap ranges
    ( I have 30 ranges and 30 buttons)
    and I am using Ontime to kill and reset the code if the user doesn't
    press the second button within 4 seconds of the first button press.

    They way I am using the Ontime function is taken directly
    out of EXCEL help yet it results in .... unable to find the function
    (ResetTheFirstManualSwapButton)

    I only am setting the values in B2 just to watch the results of the flow of the code before I add the code needed to do the swapping

    ************************************************** *****
    Public Sub ManualSwap(SwapPosition As Integer)

    If FirstButtonPress = 0 Then

    FirstButtonPress = SwapPosition
    Range("B2").Select
    Selection.Value = FirstButtonPress
    'give the user 4 seconds to choose the second range in the swap
    'Application.OnTime Now + TimeValue("00:00:4"), ResetTheFirstManualSwapButton

    Else

    'There are now 2 variables for the 2 ranges
    'run some code here to swap the ranges
    'set the to FirstButtonPress = 0 ready for the next swap
    FirstButtonPress = 0
    Range("B2").Select
    Selection.Value = FirstButtonPress

    End If

    End Sub
    ************************************************** *****
    Public Function ResetTheFirstManualSwapButton()
    ' the user waited too long so reset the to FirstButtonPress = 0
    Dim FirstButtonPress As Integer
    FirstButtonPress = 0
    Range("B2").Select
    Selection.Value = FirstButtonPress
    End Function

    If I can get past this obstacle I will be able to complete the code for these
    swap buttons. Your help is appreciated

  2. #2
    Bob Phillips
    Guest

    Re: Why wont this work?....Ontime + Now

    Haven't tested this but the OnTime macro is a string, not a direct
    reference

    Public Sub ManualSwap(SwapPosition As Integer)

    If FirstButtonPress = 0 Then

    FirstButtonPress = SwapPosition
    Range("B2").Select
    Selection.Value = FirstButtonPress
    'give the user 4 seconds to choose the second range in the swap
    Application.OnTime Now + TimeValue("00:00:4"), _
    "ResetTheFirstManualSwapButton"

    Else

    'There are now 2 variables for the 2 ranges
    'run some code here to swap the ranges
    'set the to FirstButtonPress = 0 ready for the next swap
    FirstButtonPress = 0
    Range("B2").Select
    Selection.Value = FirstButtonPress

    End If

    End Sub
    '************************************************** *****
    Public Function ResetTheFirstManualSwapButton()
    ' the user waited too long so reset the to FirstButtonPress = 0
    Dim FirstButtonPress As Integer
    FirstButtonPress = 0
    Range("B2").Select
    Selection.Value = FirstButtonPress
    End Function



    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "SuitedAces" <SuitedAces.2a5ih0_1151563502.8894@excelforum-nospam.com> wrote
    in message news:SuitedAces.2a5ih0_1151563502.8894@excelforum-nospam.com...
    >
    > *Please help with this*, I am using 2 button presses to swap ranges
    > ( I have 30 ranges and 30 buttons)
    > and I am using Ontime to kill and reset the code if the user doesn't
    > press the second button within 4 seconds of the first button press.
    >
    > They way I am using the Ontime function is taken directly
    > out of EXCEL help yet it results in .... unable to find the function
    > (ResetTheFirstManualSwapButton)
    >
    > I only am setting the values in B2 just to watch the results of the
    > flow of the code before I add the code needed to do the swapping
    >
    > ************************************************** *****
    > Public Sub ManualSwap(SwapPosition As Integer)
    >
    > If FirstButtonPress = 0 Then
    >
    > FirstButtonPress = SwapPosition
    > Range("B2").Select
    > Selection.Value = FirstButtonPress
    > 'give the user 4 seconds to choose the second range in the swap
    > 'Application.OnTime Now + TimeValue("00:00:4"),
    > ResetTheFirstManualSwapButton
    >
    > Else
    >
    > 'There are now 2 variables for the 2 ranges
    > 'run some code here to swap the ranges
    > 'set the to FirstButtonPress = 0 ready for the next swap
    > FirstButtonPress = 0
    > Range("B2").Select
    > Selection.Value = FirstButtonPress
    >
    > End If
    >
    > End Sub
    > ************************************************** *****
    > Public Function ResetTheFirstManualSwapButton()
    > ' the user waited too long so reset the to FirstButtonPress = 0
    > Dim FirstButtonPress As Integer
    > FirstButtonPress = 0
    > Range("B2").Select
    > Selection.Value = FirstButtonPress
    > End Function
    >
    > If I can get past this obstacle I will be able to complete the code for
    > these
    > swap buttons. *Your help is appreciated*
    >
    >
    > --
    > SuitedAces
    > ------------------------------------------------------------------------
    > SuitedAces's Profile:

    http://www.excelforum.com/member.php...o&userid=35840
    > View this thread: http://www.excelforum.com/showthread...hreadid=556796
    >




  3. #3
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    What is a macro string

  4. #4
    Bob Phillips
    Guest

    Re: Why wont this work?....Ontime + Now

    I didn't say a macro string, I said the macro passed to OnTime is passed as
    a string

    Application OnTime, earliest_time, "procedure_to_run"

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "SuitedAces" <SuitedAces.2a5pvn_1151573104.9656@excelforum-nospam.com> wrote
    in message news:SuitedAces.2a5pvn_1151573104.9656@excelforum-nospam.com...
    >
    > What is a macro string
    >
    >
    > --
    > SuitedAces
    > ------------------------------------------------------------------------
    > SuitedAces's Profile:

    http://www.excelforum.com/member.php...o&userid=35840
    > View this thread: http://www.excelforum.com/showthread...hreadid=556796
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1