OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-12-2002, 15:58
bbolte
Guest
 
Posts: n/a
Default VB6, GMS questions

been playing around with some examples found on your site and in the mail list archives (is it really closed?) and have some questions.

I'm trying to move some code from a com into a gms but am getting an error when trying to hit the gms. here is the error.
Code:
Run-time error '-2147467259 (800040005)'
Method 'RunMacro' of object "IDrawGMSmanager' failed
i'm not entirely sure of the whole gms process thing. does it need to be compiled? where is the compiled file then? what does this error mean? etc, etc... can someone point me in the right direction?
Reply With Quote
  #2  
Old 03-12-2002, 16:24
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: VB6, GMS questions

Quote:
Originally Posted by bbolte
i'm not entirely sure of the whole gms process thing. does it need to be compiled? where is the compiled file then? what does this error mean? etc, etc... can someone point me in the right direction?
No, the code in a GMS is just a normal VBA module (macro). However you must ensure that before you use the method, you initialize VBA. By default, VBA is not loaded until you first access any of its features in the UI. You can make VBA load on application startup by going to Tools>Options>Workspace>VBA dialog and removing a checkmark from "Delay load VBA" box.

In CorelDRAW 11, there is a method Application.InitializeVBA that can force VBA to load programmatically.

Also, make sure that you specify the GMS module name and macro name correctly and all the required parameters (if any) are passed through RunMacro command.

If this doesn't help, please post your VBA and VB code and I will see what could be wrong here.
Reply With Quote
  #3  
Old 03-12-2002, 16:50
bbolte
Guest
 
Posts: n/a
Default

i'm using Corel 10, btw... any differences? in Corel, when i go to tools>vb>play and select my gms, there aren't any listings for the macro.
Reply With Quote
  #4  
Old 03-12-2002, 17:08
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Quote:
Originally Posted by bbolte
i'm using Corel 10, btw... any differences?
Well, the only difference is that InitializeVBA method is not available in Draw 10.

Quote:
in Corel, when i go to tools>vb>play and select my gms, there aren't any listings for the macro.
This could be because of two reasons:

1. Your subroutine is defined with Private keyword:

Code:
Private Sub MyMacro()
2. Your subroutine has any parameters:

Code:
Public Sub MyMacro(v As Long)
If the subroutine is defined as one of the above, it will not be listed by VBA as a possible macro.

You will still be able to run the subroutine through GMSManager.RunMacor command, but you will need to provide the parameters:

Code:
GMSManager.RunMacro "MyGMS", "Module1.MyMacro", 2
This is the same as if you run the subroutine from inside the GMS as:

Code:
MyMacro 2
I hope this clears things out.
Reply With Quote
  #5  
Old 05-12-2002, 14:54
bbolte
Guest
 
Posts: n/a
Default

ok, here is the gms. this is in a class module, clsEstimate:
Code:
Option Explicit

'//set up Corel vars
Private CSApp As Application
Private CSDoc As Document
Private CSPage As Page
Private CSWindow As Window
'//set up class vars
Private m_OverallWidth As Double
Private m_OverallHeight As Double
Private m_ShapeSurfaceArea As Double
Private m_SegmentCount As Integer

Public Property Get OverallWidth() As Double
    OverallWidth = m_OverallWidth
End Property

Public Property Let OverallWidth(ByVal vNewValue As Double)
    m_OverallWidth = vNewValue
End Property

Public Property Get OverallHeight() As Double
    OverallHeight = m_OverallHeight
End Property

Public Property Let OverallHeight(ByVal vNewValue As Double)
    m_OverallHeight = vNewValue
End Property

Public Property Get ShapeSurfaceArea() As Double
    ShapeSurfaceArea = m_ShapeSurfaceArea
End Property

Public Property Let ShapeSurfaceArea(ByVal vNewValue As Double)
    m_ShapeSurfaceArea = vNewValue
End Property

Public Property Get SegmentCount() As Double
    SegmentCount = m_SegmentCount
End Property

Public Property Let SegmentCount(ByVal vNewValue As Double)
    m_SegmentCount = vNewValue
End Property

Public Sub CreateArt(textString As String)
    Dim CSText, intAlign As Integer, CSShape As Shape
    Dim dblTextHeight As Double, dblFontSize As Double, i As Integer
    Dim objWidth As Double, objHeight As Double, objSurfaceArea As Double
    'figure the alignment
  intAlign = 3
    
    Set CSText = ActiveLayer.CreateArtisticText(1, 2, textString)
    
    With ActiveShape.Text
        .FontProperties.Name = "Helvetica"
        .FontProperties.Size = 500
        .FontProperties.Style = cdrBoldFontStyle
        .AlignProperties.alignment = intAlign
        .SpaceProperties.LineSpacingType = cdrPercentOfCharacterHeightLineSpacing
        .SpaceProperties.LineSpacing = 70
    End With
    ActiveShape.ConvertToCurves
    
    '// get segment count
    m_SegmentCount = ActiveShape.Curve.Segments.Count
    '// get measurments
    ActiveShape.GetSize objWidth, objHeight
    m_OverallHeight = objHeight
    m_OverallWidth = objWidth
    '// cad cutting length measurement
    For i = 1 To ActiveShape.Curve.Segments.Count
            objSurfaceArea = ActiveShape.Curve.Segments.Item(i).Length + objSurfaceArea
    Next i
    m_ShapeSurfaceArea = objSurfaceArea
End Sub
here is the procedure from a VB exe that calls the main sub:

Code:
Private Sub cmdBuild_Click()
    '// start building the text object
    Dim strAlignment As String
    
    If txtText.Text = "" Then
        MsgBox "Please add some text!", vbCritical
        txtText.SetFocus
        Exit Sub
    Else
        strTextToSet = UCase(txtText.Text)
    End If
    
    If cmbAlignment.Text = "" Then
        MsgBox "Please pick an alignment!", vbCritical
        cmbAlignment.SetFocus
        Exit Sub
    Else
        strAlignment = cmbAlignment.Text
    End If
    
    Dim n As Long
    n = GMSManager.RunMacro("CadTest", "clsEstimate.createArt", strTextToSet)
    overallWidth = GMSManager.RunMacro("cadtest", "clsestimate.overallwidth")
   
    DisplayDims
    
    '//close up the object
    'Set objCad = Nothing
End Sub
Reply With Quote
  #6  
Old 05-12-2002, 16:48
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Oh, that's easy. You can't place your procedure in a class module.

In order to call a method in a class, you need to have an instance of that class, that is, you need to create the object with a New keyword or something. When you call from your VB program, there isn't an instance of your class and you can't call a method without it.

Put your method in a regular module which would create an instance of a class and call the method.

However what is the reason for putting your function in a class? You can't do much about it once the function exits... Plus you cannot guarantee that any of your data will be preserved between calls, so you cannot store anything in variables for later use. Rather convert your subroutine into a function and let it return an array of variants which would contain all your output parameters, or put them in the argument list using ByRef so you can return values through them...
Reply With Quote
  #7  
Old 05-12-2002, 16:56
bbolte
Guest
 
Posts: n/a
Default

ok, that makes sense. the only reason they were in a class is because they were in a class in my vb app. i wondered about the properties also. i haven't done much VBA so don't know the rules or differences between it and VB 6. thanks. will let you know what i come up with. :wink:
Reply With Quote
  #8  
Old 05-12-2002, 17:03
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Quote:
Originally Posted by bbolte
ok, that makes sense. the only reason they were in a class is because they were in a class in my vb app. i wondered about the properties also. i haven't done much VBA so don't know the rules or differences between it and VB 6. thanks. will let you know what i come up with.
Well, there isn't much difference between VB and VBA. In VB, you don't call your method as just clsEsitmate.CreateArt, right? You do it like this:

Code:
Dim obj as New clsEstimate
obj.CreateArt
Here clsEstimate is a class while obj is an instance of that class and it can be used to call the methods of the class.

When you use RunMacro you do not have the instance of that class and hence you can't use its methods.

I have noticed a couple other things in your code. First of all, is it Draw 10 or Draw 11? Because in Draw 11 you can apply a lot of text attributes (such as font, alignment, etc) right in the CreateArtisticText method.

Second, in order to loop through all segments, it would be easier and faster to do it like this:

Code:
Dim seg As Segment
For Each seg in ActiveShape.Curve.Segments
    objSurfaceArea = seg.Length + objSurfaceArea
Next seg
And finally, why do you need to go through all segments to get the total curve length? Why not use ActiveShape.Curve.Length instead?
Reply With Quote
  #9  
Old 05-12-2002, 17:08
bbolte
Guest
 
Posts: n/a
Default

Quote:
Originally Posted by Alex
And finally, why do you need to go through all segments to get the total curve length? Why not use ActiveShape.Curve.Length instead?
well, because i didn't know that activeshape.curve.length would get me the total length. i thought i would have to add up all the segments. this would be much cooler, because my way was a little slow.
Reply With Quote
  #10  
Old 05-12-2002, 17:12
bbolte
Guest
 
Posts: n/a
Default

what if the active shape is some text that has been converted to paths, it will still give the total curve length?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can convert GMS file unviewable??!!! bb CorelDRAW/Corel DESIGNER VBA 0 29-03-2005 19:31
Where does COrelPhotopaint 12 keeps its Globalmacros file? cyrilgupta Corel Photo-Paint VBA 1 08-11-2004 15:02
*** Read me first before posting new questions *** Alex CorelDRAW/Corel DESIGNER VBA 0 09-03-2004 08:51
Newbie questions Adrian Batchelor CorelDRAW/Corel DESIGNER VBA 2 15-11-2003 11:04
What is a GMS file? sergent CorelDRAW/Corel DESIGNER VBA 1 12-06-2003 17:57


All times are GMT -5. The time now is 08:41.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com