Hi.
Holding a key modifies the fucntion of a macro.
Ie hold shift and run the macro and it does this, hold Crtl and it does this... etc.
A great way to make your macros multi functional.
I also lightly touch base on Option Explicit which makes variable declaration necessary.
I also quickly talk about If, Else, ElseIf conditionals and colors.
Enjoy! (the code is pasted below)
~John
Option Explicit#If VBA7 Then Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As LongPtr) As Integer#Else Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer#End If'Private Const VK_ESCAPE = &H1B'Private Const VK_RETURN = &HDPrivate Const VK_SHIFT = &H10Private Const VK_CONTROL = &H11Sub makeRect() Dim s As Shape, sRect As Shape Dim x As Double, y#, h#, w# Dim dMarg# Dim col As New Color If GetAsyncKeyState(VK_SHIFT) Then dMarg = 0.25 col.RGBAssign 255, 0, 0 ElseIf GetAsyncKeyState(VK_CONTROL) Then dMarg = 0.25 col.RGBAssign 255, 0, 0 Else dMarg = 0.1 col.RGBAssign 0, 0, 255 End If ActiveDocument.Unit = cdrInch Set s = ActiveShape If s Is Nothing Then Exit Sub 's.GetBoundingBox x, y, w, h myGetBoundingBox s, x, y, w, h Set sRect = ActiveLayer.CreateRectangle2(x - dMarg, y - dMarg, w + (dMarg * 2), h + (dMarg * 2)) sRect.Fill.UniformColor.CopyAssign col sRect.OrderToBack End SubPrivate Function myGetBoundingBox(ByVal s As Shape, ByRef x As Double, y#, w#, h#) h = s.SizeHeight w = s.SizeWidth ActiveDocument.ReferencePoint = cdrBottomLeft x = s.PositionX y = s.PositionYEnd Function
My explanation of the New and Set statement was a little wrong.
Set assigns an object reference to a variable. In the video I said it creates it.
Example.
Set s = ActiveShape 'This sets the variable s to be a reference to the object.
This basically means now you can use s to reference the object. You must do this with objects.
In the video I said it created the variable when in actual fact it just sets the reference to an object. I hope this makes sense.
Many times in the video I will use basic and simple terminology to try to explain things. My hope is that everyone can understand and follow along easily.
So just to clarify
You declare and object variable but must Set the reference. If you use the New word you can do this in one step, in the declaration!
Here's the VBA definition for Set and New:
Assigns an object reference to a variable or property.
Syntax
Set objectvar = {[New] objectexpression | Nothing}
The Set statement syntax has these parts:
Remarks
To be valid, objectvar must be an object type consistent with the object being assigned to it.
The Dim, Private, Public, ReDim, and Static statements only declare a variable that refers to an object. No actual object is referred to until you use the Set statement to assign a specific object.
The following example illustrates how Dim is used to declare an array with the type Form1. No instance of Form1 actually exists. Set then assigns references to new instances of Form1 to the myChildForms variable. Such code might be used to create child forms in an MDI application.
Form1
myChildForms
Dim myChildForms(1 to 4) As Form1 Set myChildForms(1) = New Form1 Set myChildForms(2) = New Form1 Set myChildForms(3) = New Form1 Set myChildForms(4) = New Form1
Generally, when you use Set to assign an object reference to a variable, no copy of the object is created for that variable. Instead, a reference to the object is created. More than one object variable can refer to the same object. Because such variables are references to the object rather than copies of the object, any change in the object is reflected in all variables that refer to it. However, when you use the New keyword in the Set statement, you are actually creating an instance of the object.
Hey RunFlaCruiser these video tutories about writing macros are great. Thank you for doing them
and I hope you plan on doing a bunch more.
Thank you. Your thanks is what makes me do them.
I will try to do at least 1 today and hope I can do many more.
RunFlaCruiser,
There is very little information on writing macros for Coreldraw and phototpaint. The PDF they have has
lots of information but it is much easier to learn seeing with you are doing and then using the PDF as a reference. Do you know
if you will have a list of your videos someplace so we dont have to search for them in this form?
dfaris said: Do you know if you will have a list of your videos someplace so we dont have to search for them in this form?
Do you know
Naw. At first I figured maybe I would create and sell them, but then figured all what the hell, just put em here for free. Macros has always been mostly a hobby for me anyways.
As I make them I'll post them here. I might be able to bundle them up and make available elsewhere later though.
I've started adding these posts to my favorites page here on coreldraw.com, that way I can find them all in one place. Hugh suggested posting them on the Wikis How-to's page, have you given that any thought?
Haven't had a chance to watch them all yet, but wow, John, these videos are super helpful. I've already learned some new things that will help me a great deal.
Thank you for being so generous!
Patti
pranderson said:I've started adding these posts to my favorites page here on coreldraw.com, that way I can find them all in one place. Hugh suggested posting them on the Wikis How-to's page, have you given that any thought?
Hi Patti.
You guys can make a wiki if ya want. Just post a link to each forum post and it would be easy that way.
Glad it helped. Can't wait to see some new ideas from everyone!
Thanks for the thanks!
RunFlaCruiser said:You guys can make a wiki if ya want. Just post a link to each forum post and it would be easy that way.
Consider it done. I placed in under How to & Tips & Tricks.
I added the link to your website at the bottom of the Wiki page. Edit the wiki page as you wish, John, or add an intro paragraph if you want. It's so kind of you to share these videos/lessons, we all thank you!
Thanks again.