DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Ben Guest

    Using variables in command lines


    I am wondering if there is a way to write the code in VB so that if I am trying
    make 20 command buttons visible, do it thru a variable type method so that
    i can have 1 to 20 be the value of a variable and then just increment that
    value and save a ton of code. This is what I mean...

    dim num as interger
    dim temp as string


    num = 1
    temp = "Command" & num & ".Visible")
    temp = False


    so that it acts the same as Command1.Visible = False
    thanks


  2. #2
    dnagel Guest

    Re: Using variables in command lines

    Theres this method:

    Private Sub Form_Load()
    Dim num As Integer

    num = 1
    With Me.Controls("Command" & num)
    .Visible = False
    End With

    End Sub


    And then theres (Where CmdSpecial are the names of the Array of Command
    Buttons:

    Dim xControl as control

    for each xControl in me.controls
    if type of xControl is CommandButton then
    If instr(1,xControl.name,"CmdSpecial") > 0 then
    xcontrol.visible = false
    Endif
    endif
    next


    "Ben" <bbeyerlein@gentex.com> wrote in message
    news:3b04067c$1@news.devx.com...
    >
    > I am wondering if there is a way to write the code in VB so that if I am

    trying
    > make 20 command buttons visible, do it thru a variable type method so that
    > i can have 1 to 20 be the value of a variable and then just increment that
    > value and save a ton of code. This is what I mean...
    >
    > dim num as interger
    > dim temp as string
    >
    >
    > num = 1
    > temp = "Command" & num & ".Visible")
    > temp = False
    >
    >
    > so that it acts the same as Command1.Visible = False
    > thanks
    >




  3. #3
    Alex Guest

    Re: Using variables in command lines


    ...or use this routine


    Sub ShowControls(bShow As Boolean, ParamArray arrControls())
    Dim ctl As Variant
    For Each ctl In arrControls
    ctl.Visible = bShow
    Next
    End Sub


    Private Sub Command2_Click()
    ShowControls True, List1, Label1, Text1, Command1
    End Sub

    Private Sub Command3_Click()
    ShowControls False, List1, Label1, Text1, Command1
    End Sub


    Alex


    "dnagel" <dnagel@egghead.com> wrote:
    >Theres this method:
    >
    >"Ben" <bbeyerlein@gentex.com> wrote in message
    >news:3b04067c$1@news.devx.com...
    >>
    >> I am wondering if there is a way to write the code in VB so that if I

    am
    >trying
    >> make 20 command buttons visible, do it thru a variable type method so

    that
    >> i can have 1 to 20 be the value of a variable and then just increment

    that
    >> value and save a ton of code. This is what I mean...
    >>
    >> dim num as interger
    >> dim temp as string
    >>
    >>
    >> num = 1
    >> temp = "Command" & num & ".Visible")
    >> temp = False
    >>
    >>
    >> so that it acts the same as Command1.Visible = False
    >> thanks
    >>

    >
    >



  4. #4
    Arthur Wood Guest

    Re: Using variables in command lines


    Ben,
    The really "correct" way to do this would be to build a Control array
    out of the command buttons, then you can use a regular loop to make each
    one visible:

    for iButton = 0 to 19
    cmdButton(iButton).Visible = True
    Next iButton

    Arthur Wood



    "Ben" <bbeyerlein@gentex.com> wrote:
    >
    >I am wondering if there is a way to write the code in VB so that if I am

    trying
    >make 20 command buttons visible, do it thru a variable type method so that
    >i can have 1 to 20 be the value of a variable and then just increment that
    >value and save a ton of code. This is what I mean...
    >
    >dim num as interger
    >dim temp as string
    >
    >
    >num = 1
    >temp = "Command" & num & ".Visible")
    >temp = False
    >
    >
    >so that it acts the same as Command1.Visible = False
    >thanks
    >



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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links