Results 1 to 12 of 12

Thread: Man I SUCK Today!!!!! Select Case Statment

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Angry Man I SUCK Today!!!!! Select Case Statment

    What's wrong with this? I'm trying to set column widths in a listview!

    VB Code:
    1. Private Sub CmdSaveExit_Click()
    2.  
    3. Select Case Checked
    4. Case ckFilename.Value = Checked
    5.     Kamo2.ListView1.ColumnHeaders(1).Width = 4000
    6. Case ckFilesize.Value = Checked
    7.     Kamo2.ListView1.ColumnHeaders(7).Width = 1301.1
    8. Case ckArtist.Value = Checked
    9.     Kamo2.ListView1.ColumnHeaders(2).Width = 3200.31
    10. Case ckSongname.Value = Checked
    11.     Kamo2.ListView1.ColumnHeaders(3).Width = 3200.31
    12. Case ckAlbum.Value = Checked
    13.     Kamo2.ListView1.ColumnHeaders(4).Width = 2700.28
    14. Case ckTrack.Value = Checked
    15.     Kamo2.ListView1.ColumnHeaders(5).Width = 899.71
    16. Case ckFrequency.Value = Checked
    17.     Kamo2.ListView1.ColumnHeaders(8).Width = 1440
    18. Case ckBitrate.Value = Checked
    19.     Kamo2.ListView1.ColumnHeaders(9).Width = 899.71
    20. Case ckLength.Value = Checked
    21.     Kamo2.ListView1.ColumnHeaders(10).Width = 1301.1
    22. Case ckGenre.Value = Checked
    23.     Kamo2.ListView1.ColumnHeaders(6).Width = 1440
    24. End Select
    25.  
    26. Select Case Unchecked
    27. Case ckFilename.Value = Unchecked
    28.     Kamo2.ListView1.ColumnHeaders(1).Width = 0
    29. Case ckFilesize.Value = Unchecked
    30.     Kamo2.ListView1.ColumnHeaders(7).Width = 0
    31. Case ckArtist.Value = Unchecked
    32.     Kamo2.ListView1.ColumnHeaders(2).Width = 0
    33. Case ckSongname.Value = Unchecked
    34.     Kamo2.ListView1.ColumnHeaders(3).Width = 0
    35. Case ckAlbum.Value = Unchecked
    36.     Kamo2.ListView1.ColumnHeaders(4).Width = 0
    37. Case ckTrack.Value = Unchecked
    38.     Kamo2.ListView1.ColumnHeaders(5).Width = 0
    39. Case ckFrequency.Value = Unchecked
    40.     Kamo2.ListView1.ColumnHeaders(8).Width = 0
    41. Case ckBitrate.Value = Unchecked
    42.     Kamo2.ListView1.ColumnHeaders(9).Width = 0
    43. Case ckLength.Value = Unchecked
    44.     Kamo2.ListView1.ColumnHeaders(10).Width = 0
    45. Case ckGenre.Value = Unchecked
    46.     Kamo2.ListView1.ColumnHeaders(6).Width = 0
    47. End Select
    48.  
    49. Unload Me
    50. 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.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    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:
    1. If ckFilename.value = Checked Then
    2.     'set columnwidth to certain size
    3. Else
    4.    'set columnwidth to 0
    5. End if
    6. 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.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Is there a better way?

    Is there a better way then 9 IF Then statements? Maybe a control array or something here?

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  7. #7
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    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

  8. #8
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    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

  9. #9
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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:
    1. eg
    2. With Kamo2.ListView1
    3.     .ColumnHeaders(1).Width = 4000 * ckFileName.Value    
    4.     .ColumnHeaders(7).Width = 1301.1 * ckFilesize.Value
    5.     .ColumnHeaders(2).Width = 3200.31 * ckArtist.Value
    6.  
    7. 'etc
    8. 'etc
    9.  
    10. 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?
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  10. #10
    Member
    Join Date
    Sep 1999
    Location
    Zurich, Switzerland
    Posts
    55
    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:
    1. Private Sub Form_Load
    2.  
    3. chkBox(1).Tag = 4000 'Filename
    4. chkBox(2).Tag = 3200 'Artist
    5. chkBox(3).Tag = 3200 'Songname
    6. chkBox(4).Tag = 2700 'Album
    7. chkBox(5).Tag = 900 'Track
    8. chkBox(6).Tag = 1440 'Genre
    9. chkBox(7).Tag = 1300 'Filesize
    10. chkBox(8).Tag = 1440 'Frequency
    11. chkBox(9).Tag = 900 'Bitrate
    12. chkBox(10).Tag = 1300 'Length
    13.  
    14. End Sub
    15.  
    16.  
    17.  
    18.  
    19. Private Sub CmdSaveExit_Click
    20.  
    21. Dim i As Long
    22.  
    23. For i = chkBox.Lbound to chkBox.Ubound
    24.     If chkBox(i).value = Checked Then
    25.         'set columnwidth to certain size
    26.         Kamo2.ListView1.ColumnHeaders(i).Width = chkBox(i).Tag
    27.     Else
    28.        'set columnwidth to 0
    29.         Kamo2.ListView1.ColumnHeaders(i).Width = 0
    30.     End if
    31. Next i
    32.  
    33. End Sub

    HTH
    Felix

  11. #11
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Halifax,UK
    Posts
    274
    why not put a tag on each of the checkboxes then add some code to the click event

    VB Code:
    1. Private Sub Check1_Click()
    2. Dim nwidth As Long
    3.  
    4. nwidth = Val(Me.Check1.Tag)
    5.  
    6. End Sub
    VB6 VS2005

  12. #12
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    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
  •  



Click Here to Expand Forum to Full Width