Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

VBA copying picture in Image control to another Image control in different UserForm

Status
Not open for further replies.

atferrari

Well-Known Member
Most Helpful Member
VBA Excel
Two UserForms:

a) LayerAndFrameSettings with several Image controls. Amongst them: LED_1, LED_2, LED3, LED_4
b) Luminosity with five Image controls: Level_1, Level_2, Level_3, Level_4, Level_5

All data (single variables / arrays) is declared As Byte, enough for the values in play.

Code, based on external values is expected to copy the picture in one of the image controls at Luminosity
to one of the LED_X Image controls at LayerAndFrameSettings userform.

After extensive testing found that:

The following sentences do it properly
Code:
   LayerAndFrameSettings.Controls("LED_4").Picture = Luminosity.Controls("Level_" & CStr(LayerLuminosityData(Pntr_LED))).Picture

   LayerAndFrameSettings.Controls("LED_2").Picture = Luminosity.Level_4.Picture

   LayerAndFrameSettings.Controls("Middle_square_change").Picture = Luminosity.Controls("Level_" & CStr(LayerLuminosityData(Pntr_LED))).Picture

   LayerAndFrameSettings.Controls("Inner_square_change").Picture = Luminosity.Controls("Level_4").Picture

   LayerAndFrameSettings.Controls("Middle_" & "square_change").Picture = Luminosity.Controls("Level_" & CStr(LayerLuminosityData(Pntr_LED))).Picture

   LayerAndFrameSettings.Controls("Inner_square_change").Picture = Luminosity.Controls("Level_4").Picture

   LayerAndFrameSettings.LED_3.Picture = Luminosity.Controls("Level_" & CStr(LayerLuminosityData(Pntr_LED))).Picture
BUT the following do not copy any picture at all and Excel does NOT raise any error at runtime
Code:
   LayerAndFrameSettings.Controls("LED_" & CStr(Pntr_LED)).Picture = Luminosity.Level_2.Picture

   LayerAndFrameSettings.Controls("LED_" & CStr(Pntr_LED)).Picture = Luminosity.Controls("Level_" & CStr(LayerLuminosityData(Pntr_LED))).Picture
Just in case I checked in the worksheet, the values below and they display OK
Code:
   Range("FY4").Value = "LED_" & CStr(Pntr_LED)
   Range("GB4").Value = "Level_" & CStr(LayerLuminosityData(Pntr_LED))
   Range("GD4").Value = LayerLuminosityData(Pntr_LED)
I am supposed to use a string to identify which control is receiving the picture, right?
 
Probelm somehow solved.

I changed to Label controls and it works OK now. Pity is I cannot say why the Image controls did not work.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top