Solved

Image Command help!

Posted on 2001-09-18
12
147 Views
Last Modified: 2010-05-02
In Visual Basic 6.0, I am trying to write a program to change what the content in the image box is to a different picture when I push a button (i.e. animate it) I have a list of *.bmps that I want to be called when I push a button in Visual basic (e.g. my game character walking animation). I know this sound confusing, but maybe somebody can help me.
0
Comment
Question by:Linky
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491802
you could use Loadpicture function from within comman_click event.
Something like:

sub command1_click()
picture1.picture= loadpicture("c:\mypic.bmp")
'or
image1.picture= loadpicture("c:\mypic.bmp")
end sub

if you have more than one picture to load, i suggest you rename  those files to something like this:
mypic1.bmp
mypic2.bmp
mypic3.bmp
.... and so on

Then:

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491810

sub command1_click()
static idx as integer
' This code asumes that you have four bmps called mypic1.bmp
' to mypic4.bmp
idx=idx+1
if idx=5 then idx=1

picture1.picture= loadpicture("c:\mypic" & idx & ".bmp")
'or
image1.picture= loadpicture("c:\mypic" & idx & ".bmp")
end sub
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6491811
something like
set image1.picture=loadpicture("c:\mygame\character1.bmp")

Note that the image doesn't redraw until the next 'idle' moment, so you'll probably want to add
image1.refresh
after changing the image

Incidentally, this isn't the most efficient way of doing things for games, but it's certainly the easiest if speed isn't an issue.
0
 
LVL 2

Author Comment

by:Linky
ID: 6491840
What would be the best way to do this for a game?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6491861
Set statement isn't necessary.
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 100 total points
ID: 6491936
It sounds like you want to create an animation which is activated by a button.

To do this, you probably want to use a timer to control the speed of the animation, so try this:

Private m_intImageCounter as integer

Private Sub Command1_Click()
   m_intImageCounter = 0
   Timer1.interval = 100' 1/10 second
   Timer1.enabled=true
End Sub

Private Sub Timer1_Timer()
   Picture1.Picture = LoadPicture(app.path & "images\Animate" & m_intImageCounter & ".gif")
   m_intImageCounter = m_intImageCounter + 1
   if m_intImageCounter > 10 then
      ' stop the timer after all (10?) images are displayed
      Timer1.Enabled = False
   end if
End Sub

'This assumes you have 10 images named Animate##.gif located in a subfolder 'images' located in your app's path
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:rspahitz
ID: 6491938
(Actually, 11 images named Animate0.gif through Animate10.gif)
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6491939
Darn...you also need to convert m_intImageCounter to a string for the concatenation.  I usually use mid$(str$(m_intImageCounter),2), so:

...
Picture1.Picture = LoadPicture(app.path & "images\Animate" & mid$(str$(m_intImageCounter),2) & ".gif")
...
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6491944
I'll get this right yet...add a "\" after the use of app.path:

Picture1.Picture = LoadPicture(app.path & "\images\Animate" & mid$(str$(m_intImageCounter),2) & ".gif")
0
 
LVL 2

Author Comment

by:Linky
ID: 6492039
Thanks all for the help...
0
 
LVL 2

Author Comment

by:Linky
ID: 6492041
Thanks all for the help...
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6492048
Glad to help...VB games can be fun, but be warned that using VB this way often leads to choppy animations, especially if you decide to use interacting images with collisions.  To do that, you may be better off with lower-level languages, or possibly API calls from VB.  Also, for large bitmaps, you may be better off using the BITBLT API function.

Anyway, have fun with it!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now