473,544 Members | 1,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Animating a Picture

44 New Member
How can I make a picture slide across the form in VBA. It can be pre-programmed or random what ever is easier. I need to be able to see it move at any given speed.

Thanks for your support.
Apr 3 '07 #1
17 6936
Killer42
8,435 Recognized Expert Expert
How can I make a picture slide across the form in VBA. It can be pre-programmed or random what ever is easier. I need to be able to see it move at any given speed.
Moving it is easy - you can either set the .Top and/or .Left properties, or use the .Move method.
Apr 3 '07 #2
I Hate My Computer
44 New Member
Moving it is easy - you can either set the .Top and/or .Left properties, or use the .Move method.
I understand but this moves it so fast that I can't see it happen.
Apr 3 '07 #3
Killer42
8,435 Recognized Expert Expert
I understand but this moves it so fast that I can't see it happen.
Have you tried putting a DoEvents in the loop? This might make a slight difference.

You could also invoke the Sleep function, which is somewhere in the API. Try a search for terms such as "VB SLEEP" on TheScripts. I think it allows you to put your program to sleep (basically, tell the CPU to ignore it) for a specified number of milliseconds.
Apr 4 '07 #4
tristanlbailey
31 New Member
How are you using the picture's .Left and .Top properties or Move method? Are you using them in a loop of some kind?

One way of doing this at a fairly consistent pace, independent of the computer's overall speed, is by using a Timer control.

Example:
(to move from left to right)


Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.  
  3.     Picture1.Move Picture1.Left + 15
  4.  
  5. End Sub
Set the Interval property of the Timer control to "50" (50 milliseconds). You may adjust this value after testing the code, to meet your needs.
Somewhere else in your program's code, you will switch the timer on by changing its Enabled property value to "True" (causing the picture to begin moving), and then switch the timer off by changing its Enabled property value to "False" (stopping the movement of the picture).

The direction in which the picture moves can be adjusted by changing the "+" (plus) to a "-" (minus), causing it to move right; and/or by giving the Move method a Top value to move the picture up or down.

Example
(to move diagonally down-right)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.  
  3.     Picture1.Move Picture1.Left + 15, Picture1.Top - 15
  4.  
  5. End Sub
If the form's ScaleMode property is set to "Twips", the number added or subtracted is equal to the number of twips that the picture is moved, when the Timer's Timer event is executed each interval. One pixel is equal to 15 twips.

Get the picture?
Apr 4 '07 #5
I Hate My Computer
44 New Member
How are you using the picture's .Left and .Top properties or Move method? Are you using them in a loop of some kind?

One way of doing this at a fairly consistent pace, independent of the computer's overall speed, is by using a Timer control.

Example:
(to move from left to right)


Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.  
  3.     Picture1.Move Picture1.Left + 15
  4.  
  5. End Sub
Set the Interval property of the Timer control to "50" (50 milliseconds). You may adjust this value after testing the code, to meet your needs.
Somewhere else in your program's code, you will switch the timer on by changing its Enabled property value to "True" (causing the picture to begin moving), and then switch the timer off by changing its Enabled property value to "False" (stopping the movement of the picture).

The direction in which the picture moves can be adjusted by changing the "+" (plus) to a "-" (minus), causing it to move right; and/or by giving the Move method a Top value to move the picture up or down.

Example
(to move diagonally down-right)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Timer1_Timer()
  2.  
  3.     Picture1.Move Picture1.Left + 15, Picture1.Top - 15
  4.  
  5. End Sub
If the form's ScaleMode property is set to "Twips", the number added or subtracted is equal to the number of twips that the picture is moved, when the Timer's Timer event is executed each interval. One pixel is equal to 15 twips.

Get the picture?
I get it but VBA has no Private Sub Timer1_Timer() type control. It has OnTime.
Apr 4 '07 #6
Killer42
8,435 Recognized Expert Expert
Unfortunately, VBA doesn't have a timer control. Unbelievable, but that's MS for you.

There are ways to simulate it, and third-party controls you can use. For example, see this thread.

(Sorry, I typed this a couple of hours ago but forgot to hit Submit.)
Apr 4 '07 #7
I Hate My Computer
44 New Member
Unfortunately, VBA doesn't have a timer control. Unbelievable, but that's MS for you.

There are ways to simulate it, and third-party controls you can use. For example, see this thread.

(Sorry, I typed this a couple of hours ago but forgot to hit Submit.)
I know that I have this code so far:

Expand|Select|Wrap|Line Numbers
  1. Sub ShapeMover()
  2.     Image1.Left = Image1.Left + 6
  3.     Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="ShapeMover"
  4. End Sub
When I run this it says sub or function not defined and this is all the code I have. How can I fix this?
Apr 4 '07 #8
Killer42
8,435 Recognized Expert Expert
I know that I have this code so far:

Expand|Select|Wrap|Line Numbers
  1. Sub ShapeMover()
  2.     Image1.Left = Image1.Left + 6
  3.     Application.OnTime When:=Now + TimeValue("00:00:01"), Name:="ShapeMover"
  4. End Sub
When I run this it says sub or function not defined and this is all the code I have. How can I fix this?
At what point does it say this? When it runs, or when you try to compile it?

Maybe you need to qualify the name you pass, like "Module1.ShapeM over" or something. Or is it complaining about the TimeValue( ) function?
Apr 4 '07 #9
I Hate My Computer
44 New Member
At what point does it say this? When it runs, or when you try ti compile it?

Maybe you need to qualify the name you pass, like "Module1.ShapeM over" or something. Or is it complaining about the TimeValue( ) function?
It says this when I close the form. I run it and it moves the shape then I wait for the timer for about a minute but it never kicks in so I close it. At that point after I close it it shows the error message. The problem is that It is not a module I want to rerun the "ShapeMover " thing.
Apr 4 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
9481
by: Chris Coho, Jr. | last post by:
Ok, I'll explain the whole problem because there may be several ways to solve this and hopefully someone knows one. What I'm doing is creating a specialty template editor, similar to say a corel draw (but for specific uses). What I need to be able to do is import graphics and text and then move them around the background until they are where...
2
7226
by: Sandra Setz | last post by:
Hi, I was wondering if someone could explain to me what the difference is between the width propery of the picture property of an image and the width property of the image itself. I would have guessed that when the stretch property of an image was set to false and an image was assigned to the picture property, that Image1.Picture.Width...
3
10439
by: Sandra Setz | last post by:
Hi, Is it possible to assign the Picture property of a picturebox to the Picture property of an image control? I use an invisble picturebox to make some changes to a picture, but I want to show the picture in an imagecontrol, since the image is very large and I want to stretch it. But when I execute the following code:
2
8898
by: Lyn | last post by:
I am trying to embed a picture into a Bound Object Frame (Me!Photograph) with the following code which is based on MS article http://support.microsoft.com/?id=158941: strPathname = "C:\photo.bmp" Me!Photograph.Class = "Paint.Picture" Me!Photograph.OLETypeAllowed = acOLEEmbedded Me!Photograph.SourceDoc = strPathname Me!Photograph.Action =...
6
9455
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run out of purchasing cover. I am nearly there, the only problem is that the code below only changes the image background for text and combo-box...
4
8029
by: Chris Moltisanti | last post by:
Hi, I am executing a piece of javascript that does some intensive processing (sorting large tables). This can take a good few seconds so I have an animated gif as a progress bar to let the user know that something is happening. However, the GIF does not animate when the javascript is processing. Anyone know why? I am aware that animated...
6
8102
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a picture of themselves to their profile... I admit that I'm a newbie... but this is how I understand this:
3
2575
by: raghunadhs | last post by:
hi all! i have a picture box, in that picture box, there is a picture asume it as "pic1.bmp".. now i have made some changes in that picture. Now i want to load a picture to a image( my form consists of a picture box and a image also). like image1.picture=loadPicture(picture1.picture) ... but i know that this statement is invalid.... ...
0
7424
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7365
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7772
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7376
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5909
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1841
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.