Click to See Complete Forum and Search --> : Referencing image names with variables
Ephesians
Mar 15th, 2002, 11:05 AM
Here's the situation. And I'm sure it's something that I'm just overlooking.
Say I've got images with names image1....image10 and they have tags 20....30.
I've actually got a couple hundred and want to rename them like this.
dim i
for i = 1 to 10
image & i.name = image & i.tag
next i
obviously this doesn't work. I can't get the variable attached to the image in a what that I can bring up the name property.
Any ideas? PS: This is in VBA.
riis
Mar 15th, 2002, 11:27 AM
Can't you use a control array for this?
You'll reference your images as: image(0), image(1), ..., image(n), etc.
Btw, you can't change the name property of any control through code.
Ephesians
Mar 15th, 2002, 11:34 AM
I didn't think you could reference an image index in vba. Can you? I'll give it a try and let you know. I know it's not a problem in VB but VBA is a little more stringent.
joey o.
Mar 15th, 2002, 11:46 AM
Sorry no time to write code, but why don't you just use a dynamic control array and assign each pic to an index. If you need to have descriptive names you could print those to a file while scrolling and concatinate like:
Open file for write
dim myPic as string
for i = 1 to whatever
"If i =" & i & "then myPicName(" & i & ")=" & myPic.name
Then cut and paste it into a function to do look ups.
Next
Let me know if I'm offtrack
Ephesians
Mar 15th, 2002, 01:41 PM
Ok I've got a reference for the pictures. Thanks for all the help. I have a new problem. I have a timer set for 3 seconds on the form and the on timer function is as follows.
[code]
Private Sub Form_Timer()
Dim sleeper
If imageflag = True Then
sleeper = Timer
myimage.Visible = False
Me.Requery
Do While Timer <= sleeper + 1
Loop
sleeper = Timer
myimage.Visible = True
Me.Requery
Do While Timer <= sleeper + 1
Loop
End If
End Sub
[code]
and when I step through it or if I have even a message box in the loops my picture will be set to visible true and false. If I take those msgboxes out and just run regularly the images won't. Any ideas?
Nirces
Mar 15th, 2002, 04:29 PM
isn;t there an execute command in VBA (its not in VB).
i know that it is in Access VBA. it is something like Execute(Code Line)
so Execute Image1.name & i & ".tag" = x
would work
MSDN says it works for VBS. i know it works for access VBA. (wrote a function that called a function depending on the parameter passed to it)
Ephesians
Mar 18th, 2002, 08:03 AM
Thanks for all your help guys and gals. It turned out I didn't need to rename all the image files. I switched tactics:
Public myimage As Image
Public imageflag As Boolean
Public imagefile As String
Public Sub Imageclick(num As Image)
Set myimage = num
imageflag = True
End Sub
Private Sub Form_Timer()
Static intShowPicture As Integer
If imageflag = True Then
If intShowPicture Then
myimage.Visible = True
Else
myimage.Visible = False
End If
intShowPicture = Not intShowPicture
End If
End Sub
Ephesians
Mar 18th, 2002, 12:07 PM
Ok. I AM going to have to somehow index all these images. The problem is that I have 150 images on my form and they all have different names. Is there a way I can have the system automatically index all these images under a common control name? The other part of the problem is that this form is in Access and VBA doesn't have the image(index) ability in the properties of an image in Access. The only thing I can think of is to make a table containing the control names for the images and an index number for reference in the same record. Is there a faster better way to do this? For example, I've got image name Ctl56 and image name image1 and I need to be able to reference and modify the properties for these images through code without having to manually type all these freakin' names. They are all tagged but I can't figure out how to pull up all the properties through the tag reference. Like:
imagenum = 56
' find image with tag number 56 and change the picture to null.
any more bright idea's people?
Sastraxi
Mar 18th, 2002, 02:57 PM
It may be wrong, and it is bad coding, but you may want to try this...Dim picBox As PictureBox
For Each picBox in WHATEVER '[a form or whatever you're searching in, I've never used VBA]
If picBox.Tag = CStr(56) Then
picBox.Picture = Null 'i dont know if that is right.
End If
NextWell it's sketchy but it should work...
Ephesians
Mar 18th, 2002, 03:32 PM
Yeah, I wound up doing it like this:
Sub sparedesk(frm As Form)
Dim ctl As Control
Dim i, sparecount
Dim jack(150) As String
Dim strresult
Set dbase = CurrentDb
Set rst = dbase.OpenRecordset("LT", dbOpenDynaset)
sparecount = 1
strresult = "[First Name:] = 'Spare'"
With rst
.MoveFirst
.FindFirst strresult
Do While Not .NoMatch
jack(sparecount) = ![Jack #:]
sparecount = sparecount + 1
.FindNext strresult
Loop
End With
For i = 1 To sparecount
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acImage
If ctl.Properties(38) = jack(i) Then
ctl.Properties(3) = "spare.bmp"
End If
End Select
End With
Next
Next
End Sub
Thanks for all your help Guys and Gals.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.