Results 1 to 4 of 4

Thread: get the index of the control array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    76

    get the index of the control array

    Code:
    Private Sub btnSubmit_Click()
    
    Dim intIndex As Integer
    
    
    
    If chk(intIndex) = vbChecked Then
    
    Select Case intIndex
    Case 0
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\1pc chicken.jpg")
    Case 1
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\french fries.jpg")
    Case 2 ' could also use "Case Else" here
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\hamburger.jpg")
    Case 3
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\beef steak.jpg")
    Case 4
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\lasagna.jpg")
    Case 5
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\spaghetti.jpg")
    Case 6
    Image1.Picture = LoadPicture("C:\Users\myrna\Documents\a VB VB\Pictures vb vb vb\mexican green wave pizza.jpg")
    End Select
    End If
    End Sub
    that's my code, I created a control array of chkbox and the index is 0 to 6..
    what I want is.. to get the index of the selected checkbox and use it in a select case statement, but my code is not working..

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: get the index of the control array

    More than 1 checkbox can be checked at one time. I think you should move this code into the chk_Click event instead
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2010
    Posts
    76

    Re: get the index of the control array

    I like that way, but our teacher asking us to do that select case approach.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: get the index of the control array

    Its nearly the exact same code, but your image will be guaranteed to be loaded with the most recently checked box:
    Code:
    Private Sub chk_Click(Index As Integer)
        If chk(Index).Value = vbChecked Then
            Select Case Index
               .... your case statements
            End Select
        End If
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Tags for this Thread

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