By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

Image Arrays

lotus18
100+
P: 866
Hello World

I'm back again. LOL


How to make an image arrays? I have 6 images named Button (Index from 1-6). I'm working on MouseMove events these images. So far I have these codes:

Expand|Select|Wrap|Line Numbers
  1. Public Sub DefaultImage()
  2.     It should be array
  3.     For i = 1 To 6
  4.         Button(i).Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  5.     Next i
  6. End Sub
  7.  
  8. Private Sub Button_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  9.    ...
  10. End Sub
  11.  
  12.  

This is my previous code and the Button were not on control arrays. This is working. I just want to shorten my codes. Thanks : )

Expand|Select|Wrap|Line Numbers
  1. Public Sub DefaultImage()
  2.     Button1.Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  3.     Button2.Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  4.     Button3.Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  5.     Button4.Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  6.     Button5.Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  7.     Button6.Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  8. End Sub
  9.  
  10. Private Sub Button1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  11.     DefaultImage
  12.     Button1.Picture = LoadPicture(App.Path & "\Images\ButtonHot.jpg")
  13. End Sub
  14.  
  15. ...
  16.  
  17. Private Sub Button6_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  18.     DefaultImage
  19.     Button6.Picture = LoadPicture(App.Path & "\Images\ButtonHot.jpg")
  20. End Sub
  21.  
Jan 14 '08 #1
Share this Question
Share on Google+
14 Replies


debasisdas
Expert 5K+
P: 8,127
What is the problem with the new code ?
Jan 14 '08 #2

QVeen72
Expert 100+
P: 1,445
Hi,

Just change your Mouse move event like this..


Expand|Select|Wrap|Line Numbers
  1. Public Sub DefaultImage()
  2.     Dim i As Integer
  3.     For i = 1 To 6
  4.         Button(i).Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  5.     Next i
  6. End Sub
  7.  
  8. Private Sub Button_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  9.     DefaultImage
  10.     Button(Index).Picture = LoadPicture(App.Path & "\Images\ButtonHot.jpg")
  11. End Sub
  12.  
  13.  

Regards
Veena
Jan 14 '08 #3

lotus18
100+
P: 866
What is the problem with the new code ?
Hi

Thanks for replying. If you notice that on my first code line #9 it contains only .... Hehe...
Jan 14 '08 #4

lotus18
100+
P: 866
Hi Veena

Thanks. I'll try that later : )
Jan 14 '08 #5

lotus18
100+
P: 866
Hi,

Just change your Mouse move event like this..


Expand|Select|Wrap|Line Numbers
  1. Public Sub DefaultImage()
  2.     Dim i As Integer
  3.     For i = 1 To 6
  4.         Button(i).Picture = LoadPicture(App.Path & "\Images\ButtonNormal.jpg")
  5.     Next i
  6. End Sub
  7.  
  8. Private Sub Button_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  9.     DefaultImage
  10.     Button(Index).Picture = LoadPicture(App.Path & "\Images\ButtonHot.jpg")
  11. End Sub
  12.  
  13.  

Regards
Veena
Hi Veena

I tried it and there's an error. The error says that an Compile Error: Expected Array :(
Jan 14 '08 #6

QVeen72
Expert 100+
P: 1,445
Hi,

Which Line you are getting the error...?
What version ? VB6 or VB.net...?


Regards
Veena
Jan 14 '08 #7

lotus18
100+
P: 866
Hi,

Which Line you are getting the error...?
What version ? VB6 or VB.net...?


Regards
Veena
Hi

Sorry for the late reply. I'm getting an error at line #10. I'm using vb6.
Jan 14 '08 #8

Expert 5K+
P: 8,434
In VB6, you're much better off using control arrays. But I don't quite understand what the problem is, or why you are moving away from control arrays.
Jan 15 '08 #9

Expert 5K+
P: 8,434
Sorry, I'm confused. which is the old code, and which is the new?
Jan 15 '08 #10

Expert 5K+
P: 8,434
I think this may be the line you're after...
Expand|Select|Wrap|Line Numbers
  1. Button(Index).Picture = LoadPicture(App.Path & "\Images\ButtonHot.jpg")
Jan 15 '08 #11

pureenhanoi
100+
P: 175
Hi Veena

I tried it and there's an error. The error says that an Compile Error: Expected Array :(
This error occures caused of Pictures in your form in diffrent name (Button1, button2...)
If you want use the given code, set the same name for 6 picturebox. Just named them with "Button". If VB6 ask you to create an array of picturebox, click "Yes" to accept.
If you could see in the Property window, all of these picturebox have same name "Button", and the Index property is increment from 0..5. So that the good time for runing given code again.

I must edit some thing on my post, caused the given code use "For i=1 To 6"
You can use "For i=0 To 5" instead, or set the index of 6 pictureboxs increment from 1..6
Jan 15 '08 #12

lotus18
100+
P: 866
This error occures caused of Pictures in your form in diffrent name (Button1, button2...)
If you want use the given code, set the same name for 6 picturebox. Just named them with "Button". If VB6 ask you to create an array of picturebox, click "Yes" to accept.
If you could see in the Property window, all of these picturebox have same name "Button", and the Index property is increment from 0..5. So that the good time for runing given code again.

I must edit some thing on my post, caused the given code use "For i=1 To 6"
You can use "For i=0 To 5" instead, or set the index of 6 pictureboxs increment from 1..6
Hi

If notice on my 1st post, in code #1, I stated there that the name of my Image is Button and they are in array control (Index from 1 to 6). But in code #2 on the same post, my buttons which are the images are not in control array instead, they are named as Button1, Buttton2,...Button6

Rey Sean
Jan 16 '08 #13

P: 2
hello world,
what is the code for arc sine and arc cosine please help thank you!
Jan 16 '08 #14

lotus18
100+
P: 866
hello world,
what is the code for arc sine and arc cosine please help thank you!
Hello

You are out of the topic. Please start a new thread.

Rey Sean
Jan 16 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.