|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to create an array of imagesform. The code below does not compile. I dont understand why? What I want to do is to create an array of all image objects found at my main form. I want to access these using an index into the array, but I dont know how to allocate the array properly? Private Sub Form_Load() Dim imgField(1 To 3) As Image ' Initialize my array of images imgField(1) = Image1 ' this row fails imgField(2) = Image2 imgField(3) = Image3 ' "value" is normally given from a sub routine Select Case value Case 1 imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual Studio\COMMON\Graphics\Bitmaps\Assorted\HAPPY.bmp") Case 2 imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual Studio\COMMON\Graphics\Bitmaps\Assorted\key.bmp") Case 3 imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual Studio\COMMON\Graphics\Bitmaps\Assorted\card.bmp") Case 4 imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual Studio\COMMON\Graphics\Bitmaps\Assorted\club.bmp") End Select Regards, Sebastian "di98mase" <di98m***@hotmail.com> wrote in message Trynews:1138655216.000800.97150@g44g2000cwa.googlegroups.com... > ' Initialize my array of images > imgField(1) = Image1 ' this row fails Set imgField(1) = Image1 But really, why not simply make the control on the form into an image array? > How should I do to create an array of all my image objects found at my <code snipped>> form. The code below does not compile. I dont understand why? > > What I want to do is to create an array of all image objects found at > my main form. I want to access these using an index into the array, but > I dont know how to allocate the array properly? A collection would be better for this kind of thing: '*** Dim Images As Collection Const BasePath As String = "C:\Program\Microsoft Visual Studio" & _ "\COMMON\Graphics\Bitmaps\Assorted\" Set Images = New Collection Call Images.Add(LoadPicture(BasePath & "HAPPY.bmp"), "Happy") Call Images.Add(LoadPicture(BasePath & "key.bmp"), "Key") Call Images.Add(LoadPicture(BasePath & "card.bmp"), "Card") Call Images.Add(LoadPicture(BasePath & "club.bmp"), "Club") '*** You can then access images by index or key: '*** Set Picture = Images.Item("Key") ' or Set Picture = Images.Item(2) '*** Hope this helps, Mike - Microsoft Visual Basic MVP - E-Mail: ED***@mvps.org WWW: Http://EDais.mvps.org/ Could you not use an image list control here?
Saga Show quoteHide quote "di98mase" <di98maseNON@SPAMMEhotmail.com> wrote in message news:1138655216.000800.97150@g44g2000cwa.googlegroups.com... > How should I do to create an array of all my image objects found at my > form. The code below does not compile. I dont understand why? > > What I want to do is to create an array of all image objects found at > my main form. I want to access these using an index into the array, > but > I dont know how to allocate the array properly? > > Private Sub Form_Load() > > Dim imgField(1 To 3) As Image > > ' Initialize my array of images > imgField(1) = Image1 ' this row fails > imgField(2) = Image2 > imgField(3) = Image3 > > ' "value" is normally given from a sub routine > Select Case value > Case 1 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\HAPPY.bmp") > Case 2 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\key.bmp") > Case 3 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\card.bmp") > Case 4 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\club.bmp") > End Select > > > > Regards, > > Sebastian >
Show quote
Hide quote
"di98mase" <di98m***@hotmail.com> wrote in message Are you needing to display all (or at least 2 or more) of these images at news:1138655216.000800.97150@g44g2000cwa.googlegroups.com... > How should I do to create an array of all my image objects found at my > form. The code below does not compile. I dont understand why? > > What I want to do is to create an array of all image objects found at > my main form. I want to access these using an index into the array, but > I dont know how to allocate the array properly? > > Private Sub Form_Load() > > Dim imgField(1 To 3) As Image > > ' Initialize my array of images > imgField(1) = Image1 ' this row fails > imgField(2) = Image2 > imgField(3) = Image3 > > ' "value" is normally given from a sub routine > Select Case value > Case 1 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\HAPPY.bmp") > Case 2 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\key.bmp") > Case 3 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\card.bmp") > Case 4 > imgField(ix).Picture = LoadPicture("C:\Program\Microsoft Visual > Studio\COMMON\Graphics\Bitmaps\Assorted\club.bmp") > End Select once? If not, ONE Image control would suffice. If you want to cache the pictures, then you could use a StdPicture object and add each of those to a collection. Another possibility would be to create a control array of the Image control at design-time. At runtime, just load additional Image controls to the control array. Note that a "control array" and an "array of controls" is NOT the same thing. What it appears you're doing is creating an array of controls. More information about what you're really trying to accomplish (your ultimate goal) would be helpful. It's just not really clear why, or for what purpose, you're wanting to do this. If we knew that purpose, we could provide better suggestions/alternatives. -- Mike Microsoft MVP Visual Basic Hi everybody,
thanks for all input to this issue. Let me describe what I intend to do: I am doing a Memory game where a have maximum 12 images (to start with). So at form load I want to load an image into each Image object but dont show any of them to start with. So what I have done is that I have an array of 12 integers that randomly gets an value of 1..6 every number is used twice. so it looks like e.g. 2,1,3,5,4,6,1,2,3,4,5,6, these indexes are later used to load an image into my Image objects, i.e. for ImageObjectArray(1) I will load ImageArray(2). These are the steps: 1) Randomize all numbers of the playTable, these are the indexes into all arrays e.g. ImageArray 2) for all image objects on the form load a picture corresponding to the value found in playTable 3) image.visable = False Do you understand what I am trying to do?
How to best resize a form?
Using Control Array in User Control Proper way to resize a Form [function LOF] Fails after WordPad saving Why Randomize() won't work? Problems with vbCtrlMask Eliminate duplication in an array VB.NET Shutdown from text file can't use a function from dll built in delphi VB crash on .PopupMenu .zmnuDemo Defaultmenu |
|||||||||||||||||||||||