473,219 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

Changing pictures

Hi!!

I have optionboxes on userform1 which dependent on which one is selected, the picture in imagebox1 on userform2 changes. I have got the code working so when i first load the programme and select an option the correct picture comes up. However when i then select a different option the picture doesnt change and remains on the first picture.
How do I get it to continue to change when different options are selected?
Hope it makes sense! Thanks in adavance!
:D
Dec 20 '11 #1

✓ answered by BigPapaN0z

Sure thing! The project contains 2 forms (frmImage, frmMain). frmImage has a picturebox (picImage) and frmMain has 2 option buttons in an array (optChoices).

No code in frmImage, copy and paste this in frmMain:

Expand|Select|Wrap|Line Numbers
  1. ' Used to preload and hold our images
  2. Private spicA As StdPicture
  3. Private spicB As StdPicture
  4.  
  5. Private Sub Form_Load()
  6.     ' Load the images for use
  7.     Set spicA = LoadPicture(App.Path & "\a.bmp")
  8.     Set spicB = LoadPicture(App.Path & "\b.bmp")
  9.     ' Let's show the Picture form and make it our child
  10.     frmImage.Show vbModeless, Me
  11. End Sub
  12.  
  13. Private Sub Form_Unload(Cancel As Integer)
  14.     ' Release/Clear our loaded images
  15.     Set spicB = Nothing
  16.     Set spicA = Nothing
  17.     ' Finally, unload our Picture form
  18.     Unload frmImage
  19. End Sub
  20.  
  21. Private Sub optChoices_Click(Index As Integer)
  22.     ' Select case for easy expandability
  23.     Select Case Index
  24.         Case 0      ' A
  25.             Set frmImage.picImage.Picture = spicA
  26.         Case 1      ' B
  27.             Set frmImage.picImage.Picture = spicB
  28.     End Select
  29. End Sub
As you can see, it looks for a.bmp and b.bmp in the same folder as the program resides. These can be any image (adjust your picturebox on frmImage if you wish).

I really hope this clarifies things for you, jcb! Feel free to pick my brain some more. :)

--EDIT--
By the way, this will NOT load a default image, as no option buttons are selected. If you want to set a default, just add this to your Form_Load:
Expand|Select|Wrap|Line Numbers
  1. optChoices(0).Value = True
Changing the index to something other than 0 will select whichever option button you wish to have selected on load. Also, changing the .Value will also initiate the "Click" event, where we change the images. Just make sure you put the above code AFTER we load the images.(Set spicA = LoadPicure)

5 1513
I've enclosed a simple example to show. Extract it somewhere and load the project. I've tried to comment on exactly what is happening. If this isn't what you're looking for, please feel free to clarify and I'll help as best as I can!
Attached Files
File Type: zip ImageSwap.zip (3.1 KB, 68 views)
Dec 21 '11 #2
Hi Thanks for getting back to me!

However I am unable to open the file you attached. is there anyway of pasting the code directly into the forum.

Cheers :)
Dec 21 '11 #3
Sure thing! The project contains 2 forms (frmImage, frmMain). frmImage has a picturebox (picImage) and frmMain has 2 option buttons in an array (optChoices).

No code in frmImage, copy and paste this in frmMain:

Expand|Select|Wrap|Line Numbers
  1. ' Used to preload and hold our images
  2. Private spicA As StdPicture
  3. Private spicB As StdPicture
  4.  
  5. Private Sub Form_Load()
  6.     ' Load the images for use
  7.     Set spicA = LoadPicture(App.Path & "\a.bmp")
  8.     Set spicB = LoadPicture(App.Path & "\b.bmp")
  9.     ' Let's show the Picture form and make it our child
  10.     frmImage.Show vbModeless, Me
  11. End Sub
  12.  
  13. Private Sub Form_Unload(Cancel As Integer)
  14.     ' Release/Clear our loaded images
  15.     Set spicB = Nothing
  16.     Set spicA = Nothing
  17.     ' Finally, unload our Picture form
  18.     Unload frmImage
  19. End Sub
  20.  
  21. Private Sub optChoices_Click(Index As Integer)
  22.     ' Select case for easy expandability
  23.     Select Case Index
  24.         Case 0      ' A
  25.             Set frmImage.picImage.Picture = spicA
  26.         Case 1      ' B
  27.             Set frmImage.picImage.Picture = spicB
  28.     End Select
  29. End Sub
As you can see, it looks for a.bmp and b.bmp in the same folder as the program resides. These can be any image (adjust your picturebox on frmImage if you wish).

I really hope this clarifies things for you, jcb! Feel free to pick my brain some more. :)

--EDIT--
By the way, this will NOT load a default image, as no option buttons are selected. If you want to set a default, just add this to your Form_Load:
Expand|Select|Wrap|Line Numbers
  1. optChoices(0).Value = True
Changing the index to something other than 0 will select whichever option button you wish to have selected on load. Also, changing the .Value will also initiate the "Click" event, where we change the images. Just make sure you put the above code AFTER we load the images.(Set spicA = LoadPicure)
Dec 22 '11 #4
THANK YOU SOOOOOO MUCH!!! :D

That was a fantastic help! Took me few reads to get it in my head but the code was very similar to what I had already written just with a few tweaks to make it work!

Much apprieciated! You are a STAR!! :D

Cheers
jcb
Dec 22 '11 #5
Very happy that this was of help, jcb. I've run into the same problem before where you think it should be working but sometimes missing just one or two small points can make a world of difference. :)

I would ask if this helped you, make sure you choose the post that helped you so other users that search the website with similar problems know the answer that solved your issue.

Again, if you have any other problems/questions/comments, we're always here to help! Best wishes!
Dec 22 '11 #6

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

Similar topics

1
by: Raymond Dunton | last post by:
I am new to Javascript programming. I have a page with four small pictures. I want to click on a picture and have it open up larger in a popup window. this is what I am currently using to do...
1
by: David | last post by:
Hi, I have a webpage where I want to have a select list which the user can select between two different pictures, and then the chosen picture loads onto the html page, but without having to reload...
23
by: Wade | last post by:
08122005 1505 GMT-5 Hello. I am working on a webpage for the local school (just before school starts). Their outside hired company really screwed things up. Im trying to get their computers up...
3
by: Wade | last post by:
08242005 1416 GMT-5 Recently some of you helped me with a script to change images. Well I was asked to make a change to the script and not knowing if what the school system is even possible, Ill...
2
by: brian | last post by:
I am new to .net technology. I have a home page built for my company using asp.net. On the bottom of the home page I want to embed a "dilbert comic strip" which is gif format. I have the strips...
4
by: Doug van Vianen | last post by:
Hi, I have the following coding on a web page. It causes two pictures (pic1.jpg and pic2.jpg) to show, one above the other and then when one clicks on the top picture is squeezes to the left...
2
by: austinra | last post by:
i have a splash screen that i want to change a picture once a second for three seconds; then load my main form. what i want it to do is load a picture into a picture box; start a timer which will...
0
by: hanisimo | last post by:
I am trying to write a small program to replace pictures in PowerPoint presentation... To find the pictures, I check Shape Type (Shape.Type = msoPicture)... But the problem is: how can I...
1
by: larystoy | last post by:
Newbie to VB6, comfortable with HTML, MS Access so I ain't totally stupid. Maybe just dumb. Am writing a Biblical Quiz program where I need to change a picture and midi sound file each time a user...
2
by: pkn6 | last post by:
Hi All, I am using VB.net to send my mails through outlook. Where i am giving the resource path for the pictures inserted in to it. But Email shows the inline pictures as attachments. what could be...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.