Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

image control madness 2 :)

Posted on 2004-04-28
9
Medium Priority
?
296 Views
Last Modified: 2010-05-02

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
Comment
Question by:kkoser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 10941004
Be specific, what's the difficulty?
0
 

Author Comment

by:kkoser
ID: 10941063
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
 
LVL 1

Expert Comment

by:EvadR
ID: 10941147
dim itm as listitem

for each itm in lstCards

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

next itm

-EvadR
0
Industry Leaders: 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!

 
LVL 76

Expert Comment

by:David Lee
ID: 10943056
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
 

Author Comment

by:kkoser
ID: 10960048
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
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 10960926
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
 

Author Comment

by:kkoser
ID: 10961137
thanx for the quick response. i will try it in a moment.
0
 

Author Comment

by:kkoser
ID: 10961974
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
 

Author Comment

by:kkoser
ID: 10971219
:)
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question