+ Reply to Thread
Results 1 to 3 of 3

Sub procedures in commandbutton script help

Hybrid View

Guest Sub procedures in... 12-07-2005, 07:50 AM
Guest Re: Sub procedures in... 12-07-2005, 08:40 AM
Guest Re: Sub procedures in... 12-07-2005, 03:55 PM
  1. #1
    VB Newbie
    Guest

    Sub procedures in commandbutton script help

    I have sub procedures A1, A2, and A3 and I am looking to run them based on
    criteria of a script for commandbutton1()_click.

    i.e.

    Dim x as range, y as range, z as range

    If x.value > 0 then
    open sub procedure A1
    else
    if y.value > 0 then
    open sub procedure A2
    else
    open sub procedure A3
    end if
    end if

    I'm not sure how to open these subs up and how/where to declare them. Any
    assistance would be greatly appreciated.


  2. #2
    Tom Ogilvy
    Guest

    Re: Sub procedures in commandbutton script help

    You call a procedure by entering it name. Assume you have three procedures
    located in a general module (insert=>Module in the VBE)

    Sub Macro1()
    msgbox "In Macro1"
    End Sub

    Sub Macro2()
    msgbox "In Macro2"
    End Sub

    Sub Macro3()
    msgbox "In Macro3"
    End Sub

    then in your event code

    Private Sub CommandButton1_Click()
    Dim v as Long
    v = int(rnd()*3+1)
    if v = 1 then
    macro1
    elseif v = 2 then
    macro2
    elseif v = 3 then
    macro3
    end if
    End Sub

    --
    Regards,
    Tom Ogilvy





    "VB Newbie" <VBNewbie@discussions.microsoft.com> wrote in message
    news:F670890D-4C86-4764-B626-549BF25CD4CF@microsoft.com...
    > I have sub procedures A1, A2, and A3 and I am looking to run them based on
    > criteria of a script for commandbutton1()_click.
    >
    > i.e.
    >
    > Dim x as range, y as range, z as range
    >
    > If x.value > 0 then
    > open sub procedure A1
    > else
    > if y.value > 0 then
    > open sub procedure A2
    > else
    > open sub procedure A3
    > end if
    > end if
    >
    > I'm not sure how to open these subs up and how/where to declare them. Any
    > assistance would be greatly appreciated.
    >




  3. #3
    VB Newbie
    Guest

    Re: Sub procedures in commandbutton script help

    Thanks Tom-

    I think one of my petty errors was also not realizing I had already
    established AL1 as a range variable as well as sub. Hopefully this'll do the
    trick. Thanks again!

    "Tom Ogilvy" wrote:

    > You call a procedure by entering it name. Assume you have three procedures
    > located in a general module (insert=>Module in the VBE)
    >
    > Sub Macro1()
    > msgbox "In Macro1"
    > End Sub
    >
    > Sub Macro2()
    > msgbox "In Macro2"
    > End Sub
    >
    > Sub Macro3()
    > msgbox "In Macro3"
    > End Sub
    >
    > then in your event code
    >
    > Private Sub CommandButton1_Click()
    > Dim v as Long
    > v = int(rnd()*3+1)
    > if v = 1 then
    > macro1
    > elseif v = 2 then
    > macro2
    > elseif v = 3 then
    > macro3
    > end if
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    >
    >
    > "VB Newbie" <VBNewbie@discussions.microsoft.com> wrote in message
    > news:F670890D-4C86-4764-B626-549BF25CD4CF@microsoft.com...
    > > I have sub procedures A1, A2, and A3 and I am looking to run them based on
    > > criteria of a script for commandbutton1()_click.
    > >
    > > i.e.
    > >
    > > Dim x as range, y as range, z as range
    > >
    > > If x.value > 0 then
    > > open sub procedure A1
    > > else
    > > if y.value > 0 then
    > > open sub procedure A2
    > > else
    > > open sub procedure A3
    > > end if
    > > end if
    > >
    > > I'm not sure how to open these subs up and how/where to declare them. Any
    > > assistance would be greatly appreciated.
    > >

    >
    >
    >


+ 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