+ Reply to Thread
Results 1 to 11 of 11

Toggle Code Calls

  1. #1
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256

    Toggle Code Calls

    Hi all,

    If these work, to call macro's:

    Sub RunCode1()
    Code1
    End Sub

    Sub RunCode2()
    Code2
    End Sub

    Why dosen't this work, to toggle the calls?
    Sub testoftoggle()
    If Code1 = True Then
    Code2
    Else
    Code1
    End If
    End Sub
    Thx
    Dave
    "The game is afoot Watson"

  2. #2
    Norman Jones
    Guest

    Re: Toggle Code Calls

    Hi Dave,

    I am not sure that I understand, but perhaps:

    Sub RunCode1()
    MsgBox "Code1"
    End Sub

    Sub RunCode2()
    MsgBox "Code2"
    End Sub

    Sub testoftoggle()
    If Date > #1/3/2006# = True Then
    RunCode2
    Else
    RunCode1
    End If
    End Sub


    ---
    Regards,
    Norman



    "Desert Piranha"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    >
    > If these work, to call macro's:
    >
    > Sub RunCode1()
    > Code1
    > End Sub
    >
    > Sub RunCode2()
    > Code2
    > End Sub
    >
    > Why dosen't this work, to toggle the calls?
    > Sub testoftoggle()
    > If Code1 = True Then
    > Code2
    > Else
    > Code1
    > End If
    > End Sub
    >
    >
    > --
    > Desert Piranha
    >
    >
    > ------------------------------------------------------------------------
    > Desert Piranha's Profile:
    > http://www.excelforum.com/member.php...o&userid=28934
    > View this thread: http://www.excelforum.com/showthread...hreadid=517572
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: Toggle Code Calls

    Because a sub can't return a value, so it can't have a value of True.

    If it was a function and could, then you would have to run it to get that
    value.

    --
    Regards,
    Tom Ogilvy


    "Desert Piranha"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    >
    > If these work, to call macro's:
    >
    > Sub RunCode1()
    > Code1
    > End Sub
    >
    > Sub RunCode2()
    > Code2
    > End Sub
    >
    > Why dosen't this work, to toggle the calls?
    > Sub testoftoggle()
    > If Code1 = True Then
    > Code2
    > Else
    > Code1
    > End If
    > End Sub
    >
    >
    > --
    > Desert Piranha
    >
    >
    > ------------------------------------------------------------------------
    > Desert Piranha's Profile:

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




  4. #4
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Hi Norman,

    What i am trying to do is have one call, If i call it once it will call Code1, If i call it again it will call Code2, If i call again it will call code1, as in a toggle. But i don't have the code in there, They are just a call to code elsewhere.

    Yours would be what i am trying, without the date stuff.
    Sub testoftoggle()
    If Date > #1/3/2006# = True Then
    RunCode2
    Else
    RunCode1
    End If
    End Sub


    Quote Originally Posted by Norman Jones
    Hi Dave,

    I am not sure that I understand, but perhaps:

    Sub RunCode1()
    MsgBox "Code1"
    End Sub

    Sub RunCode2()
    MsgBox "Code2"
    End Sub

    Sub testoftoggle()
    If Date > #1/3/2006# = True Then
    RunCode2
    Else
    RunCode1
    End If
    End Sub


    ---
    Regards,
    Norman



    "Desert Piranha"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    >
    > If these work, to call macro's:
    >
    > Sub RunCode1()
    > Code1
    > End Sub
    >
    > Sub RunCode2()
    > Code2
    > End Sub
    >
    > Why dosen't this work, to toggle the calls?
    > Sub testoftoggle()
    > If Code1 = True Then
    > Code2
    > Else
    > Code1
    > End If
    > End Sub
    >
    >
    > --
    > Desert Piranha
    >
    >
    > ------------------------------------------------------------------------
    > Desert Piranha's Profile:
    > http://www.excelforum.com/member.php...o&userid=28934
    > View this thread: http://www.excelforum.com/showthread...hreadid=517572
    >

  5. #5
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Hi Tom,
    Thx for the input, I will look at a function.
    Dave
    Quote Originally Posted by Tom Ogilvy
    Because a sub can't return a value, so it can't have a value of True.

    If it was a function and could, then you would have to run it to get that
    value.

    --
    Regards,
    Tom Ogilvy


    "Desert Piranha"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi all,
    >
    > If these work, to call macro's:
    >
    > Sub RunCode1()
    > Code1
    > End Sub
    >
    > Sub RunCode2()
    > Code2
    > End Sub
    >
    > Why dosen't this work, to toggle the calls?
    > Sub testoftoggle()
    > If Code1 = True Then
    > Code2
    > Else
    > Code1
    > End If
    > End Sub
    >
    >
    > --
    > Desert Piranha
    >
    >
    > ------------------------------------------------------------------------
    > Desert Piranha's Profile:

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

  6. #6
    Norman Jones
    Guest

    Re: Toggle Code Calls

    Hi Dave,]

    At the top of the code module, before any code, insert:

    Public myToggle As Boolean

    Then try:

    Sub RunCode1()
    MsgBox "Code1"
    End Sub

    Sub RunCode2()
    MsgBox "Code2"
    End Sub

    Sub testoftoggle()
    If myToggle Then
    RunCode2
    Else
    RunCode1
    End If
    myToggle = Not myToggle
    End Sub


    ---
    Regards,
    Norman



  7. #7
    Norman Jones
    Guest

    Re: Toggle Code Calls

    Hi Dave,

    Instead of using a public variable, you could also try:

    Sub RunCode1()
    MsgBox "Code1"
    End Sub

    Sub RunCode2()
    MsgBox "Code2"
    End Sub

    Sub testoftoggle()
    Static myToggle As Boolean
    If myToggle Then
    RunCode2
    Else
    RunCode1
    End If
    myToggle = Not myToggle
    End Sub


    ---
    Regards,
    Norman



  8. #8
    Tom Ogilvy
    Guest

    Re: Toggle Code Calls

    No, don't.

    --
    Regards,
    Tom Ogilvy

    "Desert Piranha"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi Tom,
    > Thx for the input, I will look at a function.
    > Dave
    > Tom Ogilvy Wrote:
    > > Because a sub can't return a value, so it can't have a value of True.
    > >
    > > If it was a function and could, then you would have to run it to get
    > > that
    > > value.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Desert Piranha"
    > > <[email protected]> wrote in
    > > message
    > > news:[email protected]...
    > > >
    > > > Hi all,
    > > >
    > > > If these work, to call macro's:
    > > >
    > > > Sub RunCode1()
    > > > Code1
    > > > End Sub
    > > >
    > > > Sub RunCode2()
    > > > Code2
    > > > End Sub
    > > >
    > > > Why dosen't this work, to toggle the calls?
    > > > Sub testoftoggle()
    > > > If Code1 = True Then
    > > > Code2
    > > > Else
    > > > Code1
    > > > End If
    > > > End Sub
    > > >
    > > >
    > > > --
    > > > Desert Piranha
    > > >
    > > >
    > > >

    > > ------------------------------------------------------------------------
    > > > Desert Piranha's Profile:

    > > http://www.excelforum.com/member.php...o&userid=28934
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=517572
    > > >

    >
    >
    > --
    > Desert Piranha
    >
    >
    > ------------------------------------------------------------------------
    > Desert Piranha's Profile:

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




  9. #9
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Hi Tom,
    No ,Don't <-- What? use a public variable?
    Dave
    Quote Originally Posted by Tom Ogilvy
    No, don't.

    --
    Regards,
    Tom Ogilvy

    "Desert Piranha"
    <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hi Tom,
    > Thx for the input, I will look at a function.
    > Dave
    > Tom Ogilvy Wrote:
    > > Because a sub can't return a value, so it can't have a value of True.
    > >
    > > If it was a function and could, then you would have to run it to get
    > > that
    > > value.
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Desert Piranha"
    > > <[email protected]> wrote in
    > > message
    > > news:[email protected]...
    > > >
    > > > Hi all,
    > > >
    > > > If these work, to call macro's:
    > > >
    > > > Sub RunCode1()
    > > > Code1
    > > > End Sub
    > > >
    > > > Sub RunCode2()
    > > > Code2
    > > > End Sub
    > > >
    > > > Why dosen't this work, to toggle the calls?
    > > > Sub testoftoggle()
    > > > If Code1 = True Then
    > > > Code2
    > > > Else
    > > > Code1
    > > > End If
    > > > End Sub
    > > >
    > > >
    > > > --
    > > > Desert Piranha
    > > >
    > > >
    > > >

    > > ------------------------------------------------------------------------
    > > > Desert Piranha's Profile:

    > > http://www.excelforum.com/member.php...o&userid=28934
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=517572
    > > >

    >
    >
    > --
    > Desert Piranha
    >
    >
    > ------------------------------------------------------------------------
    > Desert Piranha's Profile:

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

  10. #10
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Hi Norman,

    Both of your examples work great.

    Thank you very much. I couldn't figure that one out.

    Dave
    Quote Originally Posted by Norman Jones
    Hi Dave,

    Instead of using a public variable, you could also try:

    Sub RunCode1()
    MsgBox "Code1"
    End Sub

    Sub RunCode2()
    MsgBox "Code2"
    End Sub

    Sub testoftoggle()
    Static myToggle As Boolean
    If myToggle Then
    RunCode2
    Else
    RunCode1
    End If
    myToggle = Not myToggle
    End Sub


    ---
    Regards,
    Norman

  11. #11
    Tom Ogilvy
    Guest

    Re: Toggle Code Calls

    >Thx for the input, I will look at a function.

    Too bad the Excel Forum isn't linear. It makes more sense in a Usenet
    reader.

    --
    Regards,
    Tom Ogilvy




+ 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