-
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
-
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
>
-
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
>>
>
>
-
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
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks