|
-
January 12th, 2003, 08:23 PM
#1
An easier if esle if (Resolved!!)
OK VBers, There has got to be an easier way to perform all these if statements. This is just the tab letter A and B, there is 24 more!
Code:
dim tabstrip as string
tabstrip = sstab1.caption
If tabstrip = "A" Then
Data1.Visible = True
Data2.Visible = False
Data3.Visible = False
Data4.Visible = False
Data5.Visible = False
Data6.Visible = False
Data7.Visible = False
Data8.Visible = False
Data9.Visible = False
Data10.Visible = False
Data11.Visible = False
Data12.Visible = False
Data13.Visible = False
Data14.Visible = False
Data15.Visible = False
ElseIf tabstrip = "B" Then
Data1.Visible = False
Data2.Visible = True
Data3.Visible = False
Data4.Visible = False
Data5.Visible = False
Data6.Visible = False
Data7.Visible = False
Data8.Visible = False
Data9.Visible = False
Data10.Visible = False
Data11.Visible = False
Data12.Visible = False
Data13.Visible = False
Data14.Visible = False
Data15.Visible = False
I thought something like this would work but it didn't.
Code:
dim counter as integer
counter = 1
if tabstrip = "A" then
do
data & counter.visible = false
counter = counter + 1
loop until counter = 15
data1.visible = true
end if
Can someone see the problem or give me a better solution?
Last edited by dedub; January 12th, 2003 at 08:58 PM.
R.L.T.W. A+, NET+, CCNA
doin' my best
-
January 12th, 2003, 09:02 PM
#2
Sorry, I should of hacked at it a few more until I posted. Here is the answer.
make the data controls an array also, ..ie..
data1(0)
data1(1)
instead of data 1 through 26
then this code works.
Code:
Dim tabstrip As String
tabstrip = SSTab1.Caption
Dim counter As Integer
counter = 0
If tabstrip = "A" Then
Do
Data1(counter).Visible = False
counter = counter + 1
Loop Until counter = 26
Data1(0).Visible = True
R.L.T.W. A+, NET+, CCNA
doin' my best
-
January 12th, 2003, 09:05 PM
#3
Hello;
I am going to assume that the object you are hiding/showing using the visible property is a label (if not, insert object type for 'Label')
You could first have a select case block for the tabstrip.caption property:
select case sstab1.caption
case "A"
case "B"
.....
end select
You could then create a control array for the labels (or whatever you are using)...when you name a control with the same name of another, you are prompted and asked if you wish to make a control array....select yes....you will then notice that each control has the same name, but they are indexed the way arrays are indexed:
Label1(0)
Label1(1)
Label1(2)
etc
Then, dim a variable of appropriate scope to represent the indexe of the control you are 'switching off' so to speak using the visible property:
dim switchOff as Integer
and then your sub could look like:
sub showNewLabel(newLabel as Integer, oldLabel as Integer)
Label1(oldLabel).visible = false
Label1(newLabel).visible = true
switchOff = newLabel
end sub
set all label visible properties to false at design time.
When you run for the first time, show the label of choice:
switchOff = 0
showNewLabel(3, switchOff) 'will show Label1(3)
You could then call this procedure inside your select case block:
case "B"
showNewLabel(1, switchOff)
case "C"
showNewLabel(2, switchOff)
etc...
Hope that helps, cheers
DA
-
January 13th, 2003, 08:08 AM
#4
Here's what you can try
'assuming that you have a control array called carray
'consisting of 15 elements, instead 15 different instances
'of the same control
select case
case "A"
for i=1 to 15
carray(i).visible=true
next
case "B"
for i=1 to 15
carray(i).visible=false
next
end select
Hope this will help
Suhaib
-
January 13th, 2003, 09:38 AM
#5
Using the last post, you absolutely need to change something and use a private sub:
Code:
Private Sub ShowHide(boolShow As Boolean)
For i = 1 To 15
carray(i).Visible = boolShow
Next
End Sub
Private Sub Command1_Click()
Select Case Str
Case "A"
ShowHide True
Case "B"
ShowHide False
End Select
End Sub
In that way, if you add more controls to show or hide, it will be easier to code it 
Using a array of controls is the right thing to do
JeffB
-
January 13th, 2003, 08:01 PM
#6
To JeffB, Ahara and Suhaib,
Those are all excellent examples and I appreciate your help. I learn so much from you guys!!!
Thanks again
R.L.T.W. A+, NET+, CCNA
doin' my best
-
January 13th, 2003, 10:27 PM
#7
That's a smart function JeffB I had simply overlooked it !!
Good Luck All you Guys
Suhaib
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
|
Click Here to Expand Forum to Full Width
|