Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Viewing Multiple Pictures

Posted on 2002-05-26
Medium Priority
Last Modified: 2010-05-02
The following code works very nicely for viewing a picture in a ImageBox but it will not allow repeated clicks of the command button.  I must have to unload the first picture before calling the second picture.How is this done?

Private Sub Command1_Click()
Image1.Picture = LoadPictur("C:\WINDOWS\Desktop\snap.jpg")
End Sub
Question by:BOBH
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

SirNick earned 200 total points
ID: 7035551

dim holdnum as integer
holdnum = 1
Private Sub Command1_Click()

Image1.Picture = LoadPictur("C:\WINDOWS\Desktop\snap.jpg")
End Sub

Expert Comment

ID: 7035552
I just tried it, worked fine for me. Only thing I can see wrong is the spelling, should be LoadPicture.

Expert Comment

ID: 7035556

Sorry about the above

dim holdnum as integer
holdnum = 1
Private Sub Command1_Click()
  Image1.Picture = LoadPicture("")
if holdnum = "1" then
  Image1.Picture = LoadPicture("C:\WINDOWS\Desktop\snap.jpg")
elseif holdnum = "2" then
  Image1.Picture = LoadPicture("C:\WINDOWS\Desktop\snap2.jpg")
elseif holdnum = "3" then
  Image1.Picture = LoadPicture("C:\WINDOWS\Desktop\snap3.jpg")
end if
holdnum = holdnum + 1
End Sub

Hope this helps...
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 22

Expert Comment

ID: 7039797
If you're looking to display a series of pictures in sequence every time you click a button, such as one labeled "Next" there are several ways.  The above comment is one.  Here's another:

' Assumes all desired pictures are in one directory, and all of the same type

' Place this before all other procedures
Private m_strFilename as string

private sub Form_Load()
'...other code here
'...other code here
end sub

private sub InitializePictures()
   ' strMyPath is the path to the pictures
   dim strMyPath as string

   strMyPath = "C:\WINDOWS\Desktop\"
   m_strFilename = Dir$(strMyPath & "*.jpg")
end sub

Private sub Command1_Click()
  Image1.Picture = LoadPicture(m_strFilename)
  m_strFilename = Dir$
  if m_strFilename = vbNullString then
    ' out of pictures...start again
  end if
end sub

Author Comment

ID: 7041669
Finally got back into the forum. I've been locked out for several days for unknown reasons.
 The above comments are excellent, and I will give them a  try.  Basically what I've been trying to do is to retrieve an ever changing JPG picture from another application from the clipboard and show it in an Image box by calling the same file name repeatedly.  The problem has been that the program will run for a while, but then develops an error. Error trapping can eliminate the error but no new pictures are assigned to the Image box. I cannot number each picture as there will be an infinate number of them. Perhaps some of the above comments will help.
                                    73    RSH
LVL 49

Expert Comment

ID: 7818573
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept SirNick's comment(s) as an answer.

BOBH, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7909978
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question