Solved

image control madness 2 :)

Posted on 2004-04-28
9
289 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
  • 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now