Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing between images

Status
Not open for further replies.

bfamo

Technical User
Feb 16, 2006
132
NO
right...

I'm looking into making an object which changes between 3 different smiley-images, depending on which value I fill into the textbox "TxtValue". The values goes from 1 (happy smiley) to 4 (sad smiley).

Any suggestions how I can solve this one? A line of code that I can continue work on would be great!


thanks ;)

 
How are ya bfamo . . .

Using an image object, in the [blue]On Current[/blue] event of the form code would be something like:
Code:
[blue]   Dim prp As Property
   
   Set prp = Me.[purple][b][i]ImageCtlName[/i][/b][/purple].Properties("Picture")
   
   prp = Choose(Me.[purple][b][i]TextboxName[/i][/b][/purple], "C:\Database\Pic1.bmp", _
                                "C:\Database\Pic2.bmp", _
                                "C:\Database\Pic3.bmp", _
                                "C:\Database\Pic4.bmp" 
   Set prp = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hello there.
Finally, I'm almost done with my database.

I took your advice and started working on the code you so kindly provided.
My database is located in C:\database, along with the 4 images that the image control is supposed to change between(Pic1, Pic2 etc.).

The following code is found in the forms [Blue]On Current[/Blue] event:
Code:
Private Sub Form_Current()
   Dim prp As Property
   
   Set prp = Me.CtrlSmil1.Properties("Picture")
   prp = Choose([FrmSub].Form![cboKar1], "C:\Database\Pic1.bmp", _
                                          "C:\Database\Pic2.bmp", _
                                          "C:\Database\Pic3.bmp", _
                                          "C:\Database\Pic4.bmp"
   Set prp = Nothing
End Sub

As you can see, the image control is called CtrlSmil1. The text box that controls it is called cboKar1 and is placed in a subform FrmSub.

Now, here's the thing...
In my first post I only needed one text box to control the image control, now I have added two more (cboKar1,cboKar2,cboKar3).
This means that CtrlSmil1 should only be controlled by the text box that contains the highest number. Hope this makes as much sence as it does in my head.

Any suggestions as to what my next move would be?

Thanks a lot for the help so far!
 
bfamo . . .

. . . and if the two highest are equal? . . . or is that possible?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 

sorry, forgot to mention that.
yes, two or all of them can also be equal.
 
bfamo said:
[/blue]yes, two or all of them can also be equal./blue]
So . . . [blue]which one to display[/blue] under these circumstances?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
if cboKar1, cboKar2 or/and cboKar3 = 1, then show Pic1
if cboKar1, cboKar2 or/and cboKar3 = 2, then show Pic2
if cboKar1, cboKar2 or/and cboKar3 = 3, then show Pic3
if cboKar1, cboKar2 or/and cboKar3 = 4, then show Pic4

that should do it...

thanks
 
bfamo . . .

Try this:
Code:
[blue]   Dim sfrm As Form, prp As Property, topName As String
   
   Set prp = Me.CtrlSmil1.Properties("Picture")
   Set sfrm = [FrmSub].Form
   
   If sfrm!cbokar1 > sfrm!cboKar2 Then
      If sfrm!cbokar1 > sfrm!cboKar3 Then
         topName = "cboCar1"
      Else
         topName = "cboCar3"
      End If
   ElseIf cboKar2 > cboKar3 Then
      topName = "cboCar2"
   Else
      topName = "cboCar3"
   End If
         
   prp = Choose([FrmSub].Form(topName), "C:\Database\Pic1.bmp", _
                                        "C:\Database\Pic2.bmp", _
                                        "C:\Database\Pic3.bmp", _
                                        "C:\Database\Pic4.bmp")
   Set prp = Nothing
   Set sfrm = Nothing[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
In a standard code module create the following function:
Code:
'A generic function to get the max value of an arbirtrary numbers of same type values:
Public Function myMax(ParamArray Args())
Dim i As Long, rv
For i = 0 To UBound(Args)
  If IsNull(rv) Or rv < Args(i) Then rv = Args(i)
Next
myMax = rv
End Function
Now you may try this in your code:
Code:
...
With [FrmSub].Form
   prp = Choose(myMax(![cboKar1], ![cboKar2], ![cboKar3]), _
     "C:\Database\Pic1.bmp", _
     "C:\Database\Pic2.bmp", _
     "C:\Database\Pic3.bmp", _
     "C:\Database\Pic4.bmp")
End With
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
bfamo . . .

My question . . .
[blue]So . . . which one to display under these circumstances?[/blue]
. . . relates ton the following:

If cboKar1[blue]=3[/blue] AND cboKar2[blue]=3[/blue] AND cboKar3[red]<3[/red] [purple](Show cboKar1 or cboKar2)?[/purple]
If cboKar1[red]<4[/red] AND cboKar2[blue]=4[/blue] AND cboKar3[blue]=4[/blue] [purple](Show cboKar2 or cboKar3)?[/purple]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Back again from a short trip abroad.

You'll have to excuse my ignorance, I hope this will be more precise.

Value | Corresponding picture
1 | pic01.bmp
2 | pic02.bmp
3 | pic03.bmp
4 | pic04.bmp

The imagecontrol "CtrlSmil1" is only going to look for the [red]lowest[/red] value returned by either cboKar1,2,3 and show the corresponding picture.

Two examples can be:
If cboKar1=3 AND [red]cboKar2=1[/red] AND cboKar3=4 [blue](Show pic01.bmp)[/blue] The lowest value is [red]1[/red], and imagecontrol shows [red]pic01[/red].
If [red]cboKar1=3[/red] AND cboKar4=4 AND cboKar3=4 [blue](Show pic03.bmp)[/blue] The lowest value is [red]3[/red], and imagecontrol shows [red]pic03[/red].

 
bfamo . . .

My mistake . . . what to display is apparent.

So have you tried any code?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
yeah, I tried your code.
VB prompts a compile error, saying that variable is not defined for cboKar2. I have marked it red in the code:
Code:
Private Sub Form_Current()
Dim sfrm As Form, prp As Property, topName As String
   
   Set prp = Me.CtrlSmil1.Properties("Picture")
   Set sfrm = [FrmSub].Form
   
   If sfrm!cbokar1 > sfrm!cboKar2 Then
      If sfrm!cbokar1 > sfrm!cboKar3 Then
         topName = "cboCar1"
      Else
         topName = "cboCar3"
      End If
   ElseIf [red]cboKar2[/red] > cboKar3 Then
      topName = "cboCar2"
   Else
      topName = "cboCar3"
   End If
         
   prp = Choose([FrmSub].Form(topName), "C:\Database\Pic1.bmp", _
                                        "C:\Database\Pic2.bmp", _
                                        "C:\Database\Pic3.bmp", _
                                        "C:\Database\Pic4.bmp")
   Set prp = Nothing
   Set sfrm = Nothing
End Sub

When I try PHV's code, I get no errors. Still, nothing happens.

 
This is how I put PHV's code into my db:
Code:
Private Sub Form_Current()
Dim sfrm As Form, prp As Property, topName As String
   
   Set prp = Me.CtrlSmil1.Properties("Picture")
   Set sfrm = [FrmSub].Form
   
With [FrmSub].Form
   prp = Choose(myMax(![cbokar1], ![cboKar2], ![cboKar3]), _
     "C:\Database\Pic1.bmp", _
     "C:\Database\Pic2.bmp", _
     "C:\Database\Pic3.bmp", _
     "C:\Database\Pic4.bmp")
End With

   Set prp = Nothing
   Set sfrm = Nothing

End Sub

Is this done correctly? nothing happens...

thanks ;)
 
look for the lowest value
So, in the already created standard code module:
Code:
'A generic function to get the min value of an arbirtrary numbers of same type values:
Public Function MyMin(ParamArray Args())
Dim i As Long, rv
If UBound(Args) >= 0 Then rv = Args(LBound(Args))
For i = 1 + LBound(Args) To UBound(Args)
  If Trim(rv & "") = "" Or (rv > Args(i) And Trim(Args(i) & "") <> "") Then rv = Args(i)
Next
MyMin = rv
End Function
And now in your form's class module:
Code:
Private Sub Form_Current()
Dim prp As Property
Set prp = Me![CtrlSmil1].Properties("Picture")
With  Me![FrmSub].Form
   prp = Choose(MyMin(![cbokar1], ![cboKar2], ![cboKar3]), _
     "C:\Database\Pic1.bmp", _
     "C:\Database\Pic2.bmp", _
     "C:\Database\Pic3.bmp", _
     "C:\Database\Pic4.bmp")
End With
Set prp = Nothing
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hey there,

VB prompts a compile error, expected variable or procedure, not module.

prp = Choose([red]MyMin[/red](![cbokar1], ![cboKar2], ![cboKar3]), _

It should be possible to refer to modules using choose... or?

 
A module can't have the same name than a procedure, so rename it !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
woops, sorry. I renamed the module.
However I keep getting the runtime error "invalide use of Null"

Can this be caused by cboKar1,2,3 that is set to Null as standard when the form opens?
 
Replace this:
prp = Choose(MyMin(![cbokar1], ![cboKar2], ![cboKar3]), _
with this:
prp = Choose([!]Nz([/!]MyMin(![cbokar1], ![cboKar2], ![cboKar3])[!], 1)[/!], _

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top