|
-
Jul 15th, 2002, 09:13 PM
#1
Thread Starter
Fanatic Member
Man I SUCK Today!!!!! Select Case Statment
What's wrong with this? I'm trying to set column widths in a listview!
VB Code:
Private Sub CmdSaveExit_Click()
Select Case Checked
Case ckFilename.Value = Checked
Kamo2.ListView1.ColumnHeaders(1).Width = 4000
Case ckFilesize.Value = Checked
Kamo2.ListView1.ColumnHeaders(7).Width = 1301.1
Case ckArtist.Value = Checked
Kamo2.ListView1.ColumnHeaders(2).Width = 3200.31
Case ckSongname.Value = Checked
Kamo2.ListView1.ColumnHeaders(3).Width = 3200.31
Case ckAlbum.Value = Checked
Kamo2.ListView1.ColumnHeaders(4).Width = 2700.28
Case ckTrack.Value = Checked
Kamo2.ListView1.ColumnHeaders(5).Width = 899.71
Case ckFrequency.Value = Checked
Kamo2.ListView1.ColumnHeaders(8).Width = 1440
Case ckBitrate.Value = Checked
Kamo2.ListView1.ColumnHeaders(9).Width = 899.71
Case ckLength.Value = Checked
Kamo2.ListView1.ColumnHeaders(10).Width = 1301.1
Case ckGenre.Value = Checked
Kamo2.ListView1.ColumnHeaders(6).Width = 1440
End Select
Select Case Unchecked
Case ckFilename.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(1).Width = 0
Case ckFilesize.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(7).Width = 0
Case ckArtist.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(2).Width = 0
Case ckSongname.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(3).Width = 0
Case ckAlbum.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(4).Width = 0
Case ckTrack.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(5).Width = 0
Case ckFrequency.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(8).Width = 0
Case ckBitrate.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(9).Width = 0
Case ckLength.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(10).Width = 0
Case ckGenre.Value = Unchecked
Kamo2.ListView1.ColumnHeaders(6).Width = 0
End Select
Unload Me
End Sub
I also tried: Select Case True & Select Case False w/ no luck!
Any help appreciated.
Last edited by hipopony66; Jul 15th, 2002 at 09:20 PM.
-
Jul 15th, 2002, 09:25 PM
#2
Hyperactive Member
try this.
Select Case True
Case (checkbox1.value=checked)
msgbox "1"
case (checkbox2.value=checked)
msgbox "2"
End Select
Last edited by snakeeyes1000; Jul 15th, 2002 at 09:28 PM.
-
Jul 15th, 2002, 10:11 PM
#3
Thread Starter
Fanatic Member
Still no luck....
It works, but only for the first checkbox that is selected. It changes the listview columnwidth. Here's what I'm try to avoid by using a Select Case statement:
VB Code:
If ckFilename.value = Checked Then
'set columnwidth to certain size
Else
'set columnwidth to 0
End if
etc..
I have to do this for like 9 checkboxes and I don't want 9 IF..THEN...ELSE statements. I don't see what's wrong with my Select Case code though.
Any suggestions appreciated.
-
Jul 15th, 2002, 10:19 PM
#4
Re: Still no luck....
Originally posted by hipopony66
It works, but only for the first checkbox that is selected.
That's the idea behind the Select Case structure. Only one branch will execute, that's all.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 15th, 2002, 10:33 PM
#5
Thread Starter
Fanatic Member
Is there a better way?
Is there a better way then 9 IF Then statements? Maybe a control array or something here?
-
Jul 15th, 2002, 10:37 PM
#6
Looking at what you are trying to do, I would say it would be near impossible to avoid checking each value.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 15th, 2002, 10:56 PM
#7
Lively Member
try making your ckboxs an array of controls then cycl thru them with
Dim ckbox as CheckBox
Set ckbox as ckArray
for each ckbox in ckarray
if ckarray(ckbox.index).value=vbchecked then
'whatever you want
end if
next ckbox
Hope this helps
Don't go away mad, just go away.
Bam-Bam
-
Jul 15th, 2002, 11:06 PM
#8
Lively Member
oh yea , correlate the index of column headers with the index of the checkboxs. Then you can shove the select case structure inside of the if statement. By the way the case you are looking at is the index of the checkbox
Don't go away mad, just go away.
Bam-Bam
-
Jul 16th, 2002, 02:30 AM
#9
PowerPoster
Assuming that u are only using vbchecked and vbunchecked (ie not vbgray) then u can dispense with If Then and Select Case altogether. Simply multiply the width by the checkbox value
VB Code:
eg
With Kamo2.ListView1
.ColumnHeaders(1).Width = 4000 * ckFileName.Value
.ColumnHeaders(7).Width = 1301.1 * ckFilesize.Value
.ColumnHeaders(2).Width = 3200.31 * ckArtist.Value
'etc
'etc
End With
Also looks a lot nicer eh? You could also pass values, indexes to function etc... I am not sure about your use of fixed values in widths as this usually causes problems in diff screen sizes. Maybe use percentages?
-
Jul 16th, 2002, 02:33 AM
#10
Member
like bam said, but a little more detailed:
- make a chkBox(1 to 10) array
- store the used column width in the chkBox.Tag property, so the User can dynamically resize the column if he wants
VB Code:
Private Sub Form_Load
chkBox(1).Tag = 4000 'Filename
chkBox(2).Tag = 3200 'Artist
chkBox(3).Tag = 3200 'Songname
chkBox(4).Tag = 2700 'Album
chkBox(5).Tag = 900 'Track
chkBox(6).Tag = 1440 'Genre
chkBox(7).Tag = 1300 'Filesize
chkBox(8).Tag = 1440 'Frequency
chkBox(9).Tag = 900 'Bitrate
chkBox(10).Tag = 1300 'Length
End Sub
Private Sub CmdSaveExit_Click
Dim i As Long
For i = chkBox.Lbound to chkBox.Ubound
If chkBox(i).value = Checked Then
'set columnwidth to certain size
Kamo2.ListView1.ColumnHeaders(i).Width = chkBox(i).Tag
Else
'set columnwidth to 0
Kamo2.ListView1.ColumnHeaders(i).Width = 0
End if
Next i
End Sub
HTH
Felix
-
Jul 16th, 2002, 02:43 AM
#11
Hyperactive Member
why not put a tag on each of the checkboxes then add some code to the click event
VB Code:
Private Sub Check1_Click()
Dim nwidth As Long
nwidth = Val(Me.Check1.Tag)
End Sub
-
Jul 16th, 2002, 08:27 PM
#12
Lively Member
i like felix's solution, didn't think about the tag prop
Don't go away mad, just go away.
Bam-Bam
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
|