Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

image control madness 2 :)


List1 holds names of cards.(Randomly Drawn) i.e. AceofHearts, 2ofHearts, 3ofHearts, 4ofHearts, 5ofHearts.(Like a poker Hand). The images of the cards are in .jpg format on the hardrive. To Load an image into an image control i use

Text1.Text = List1.List(List1.ListIndex)
Image1.picture = LoadPicture(app.path & "\" & Text1 & ".jpg")

This works ok.

Now the Goal here is to graphically represent the contents of List1 by opening a form(Form2), Adding image controls, then loading the controls with images from List1.

IdleMind gave me a great code snippet refer to : http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20962264.html

it makes an array of image controls on the form. But i am having dificulty loading the images from a listbox.

now the question is: What would be the best way i can do this?
Any suggestions?
0
kkoser
Asked:
kkoser
  • 5
  • 3
1 Solution
 
David LeeCommented:
Be specific, what's the difficulty?
0
 
kkoserAuthor Commented:
well...to be specific..i am not sure how to do it the right way...i can load an image in the first imagebox i create but i cannot load the rest of the items in the listbox. i assume a for next is in order but....i am not sure of the right way to proccess the routine....:(
0
 
EvadRCommented:
dim itm as listitem

for each itm in lstCards

  Image1.picture = LoadPicture(app.path & "\" & List1.List(List1.ListIndex) & ".jpg")

next itm

-EvadR
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
David LeeCommented:
EvadR's on the right track.  Since the image controls are in a control array the process needs to change to look like this:

Dim intCounter As Integer
For intCounter = 0 To (List1.ListCount - 1)
    Image1(intCounter).Picture = LoadPicture(List1.List(intCounter))
Next

Also, whether or not you need to append App.Path to the begining of the listbox entry and ".jpg" (or some other extension) to the end will depend on whether you stored the full path and file extension in the listbox with the image names when you loaded them into the listbox.
0
 
kkoserAuthor Commented:
i think i got confused. i tried this;

Dim intCounter As Integer
For intCounter = 0 To (Form1.List1.ListCount - 1)

 If Image1(0).Visible = False Then
        Image1(0).Visible = True
    Else
        Load Image1(Image1.Count)
        Image1(Image1.ubound).Visible = True
        Image1(Image1.ubound).Left = Image1(0).Left + Image1.ubound * Image1(0).Width
         Image1(intCounter).Picture = LoadPicture(Form1.List1.List(intCounter))

        Image1(Image1.ubound).Top = Image1(0).Top
    End If

Next intCounter


however it didn't work.

Am i doing it the right way? I feel like i am missing something. btw i put this in the On_Load of Form2. and to make it more simpler, the listbox has the entire path statement now. i.e C:\Images\AceofHearts.jpg,,,. i hope that will help. Also thanx a lot for the help so far. i really appreciate it.:)
0
 
David LeeCommented:
kkoser,

I'm not sure what it is you're trying to do in this code.  That said, I revised it and commented it to get an idea of what you're doing.  I'm not sure it's right but I'll need you to explain further in order to determine that.  Here the revised code with comments.  If this isn't right, then please give mmore details on the goal and I'll revise.

    Dim intCounter As Integer
    'Assuming the list contains 52 items, one for each card in the deck
    For intCounter = 0 To (Form1.List1.ListCount - 1)
        'The first element of the Image1 control array already exists
        'so we only need this If statement for the elements of the array
        'we create here
        If intCounter > 0 Then
            'Create a new element
            Load Image1(intCounter)
        End If
        'Load the picture first
        Image1(intCounter).Picture = LoadPicture(Form1.List1.List(intCounter))
        'Calculate the horizontal position
        Image1(intCounter).Left = Image1(0).Left + Image1.ubound * Image1(0).Width
        'Calculate the vertical position
        Image1(intCounter).Top = Image1(0).Top
        'Make the element visible
        Image1(intCounter).Visible = True
    Next intCounter
0
 
kkoserAuthor Commented:
thanx for the quick response. i will try it in a moment.
0
 
kkoserAuthor Commented:
still haven't tried it yet..wrapping stuff up for the weekend. but the goal is to make the form look like an actual "Hand" of cards.

Part1. It starts with a db with a little over 1500 cards. a listbox gets filled with the names of these cards.(lstCards) this listbox is constant ,as everything reverts back to the index number of this list.

Part2. The user selects from these cards their own personal "Deck".(Usually about 40-60 cards). This gets loaded into a different listbox.(lstDeck) on_click of this listbox sync's the listboxes together and fills an imagebox with the picture of this card. Form1.Image1.Picture = LoadPicture(lstDeck.list(lstCards.ListIndex)Note: not the actual code but just to give you the idea.

Part3. as the online gameplay is started, you "Draw" 5 cards from your "Deck". Now i can fill the listbox with the cards, but what i wanted to do was, to create a form and on_load, it would graphically represent the items in the listbox.(Kind of like a "Hand of Cards")(lstHand). and this is where i am at...pulling my hair out on thissection of the app.:)

so the relationship here goes as follows: lstCards>lstDeck>lstHand>lstDiscard.
0
 
kkoserAuthor Commented:
:)
This did the trick..
thanx a lot


Private Sub Form_Load()
Dim intCounter As Integer

         Form1.lstHand.ListIndex = 0 - 1

    For intCounter = 0 To (Form1.lstHand.ListCount - 1)

          Form1.lstHand.ListIndex = Form1.lstHand.ListIndex + 1
   
       If intCounter > 0 Then
           Load Image1(intCounter)
       End If
       
         Image1(intCounter).Picture = LoadPicture(Form1.ImagePath.Text)
         Image1(intCounter).Left = Image1(0).Left + Image1.UBound * 350
         Image1(intCounter).Top = Image1(0).Top
         Image1(intCounter).Visible = True
         Image1(intCounter).Tag = Form1.LstCards.ListIndex

    Next intCounter
End Sub
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now