Results 1 to 10 of 10

Thread: Referencing image names with variables

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424

    Lightbulb Referencing image names with variables

    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.

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    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.

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    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?

  6. #6
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    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)
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424

    Talking This thread can be closed

    Thanks for all your help guys and gals. It turned out I didn't need to rename all the image files. I switched tactics:

    Code:
    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    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:

    Code:
    imagenum = 56 
    
    ' find image with tag number 56 and change the picture to null.
    
    any more bright idea's people?

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It may be wrong, and it is bad coding, but you may want to try this...
    VB Code:
    1. Dim picBox As PictureBox
    2. For Each picBox in WHATEVER '[a form or whatever you're searching in, I've never used VBA]
    3.     If picBox.Tag = CStr(56) Then
    4.         picBox.Picture = Null 'i dont know if that is right.
    5.     End If
    6. Next
    Well it's sketchy but it should work...
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Yeah, I wound up doing it like this:

    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width