PDA

View Full Version : CAN NOT GET VBA EXAMPLES TO W-O-R-K



joeposton
2004-11-16, 12:34 AM
I am trying to get the ADDWEDGE sample (EXAMPLE) to function... I copied the example code for VBA (AddWedge) into my FORM... but my professor says that NONE of these examples WORK...
I use AutoCad HELP... Developers help... VBA Reference... Code Examples... There are thousands of examples... NON WORK when copied and pasted in my programs... IS there a default VBA set-up required... (Win XP Pro... AutoCad 2005... HP ZD 7202)


Private Sub CommandButton1_Click()
' This example creates a wedge in model space.
Dim wedgeObj As Acad3DSolid
Dim centerx(0 To 2) As Double
Dim lengthx As Double
Dim widthx As Double
Dim heightx As Double

' Define the wedge... DO NOT USE RESERVE WORDS
centerx(0) = 5#: centerx(1) = 5#: centerx(2) = 0
lengthx = 10#: widthx = 15#: heightx = 20#

' Create the wedge in model space
Set wedgeObj = ThisDrawing.ModelSpace.AddWedge(centerx, lengthx, widthx, heightx)
wedgeObj.Update

' Change the viewing direction of the viewport
Dim NewDirection(0 To 2) As Double
NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
ThisDrawing.ActiveViewport.Direction = NewDirection
ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
ZoomAll

End Sub

Private Sub CommandButton2_Click()
End
End Sub

THANKS... Joe Poston... joeposton@ij.net...

Ed Jobe
2004-11-16, 04:56 PM
I use the sample code all the time. However, it may need to be adapted to your needs. Sometimes the examples do things just for demonstration, not the way you would normally work. So the whole sample is not all that useful, just the part that is relevant to the help topic the example goes with. For example, suppose you are looking in Help under the Layer property. The example may create several objects, select them and then change the Layer property to some hardcode value. The only thing you are interested in is the line that actually sets the Layer property. The rest is not meant to imply that's the way to work, but to provide a self-contained package that demonstrates the main principle.

Some require you to provide additional setup. The example you show requires two controls to be added to a form. They must be buttons and they must be named CommandButton1 and CommandButton2. It also requires that you have at least one viewport with modelspace active. So you may need to examine the code to see what's required. Usually, there is a paragraph at the beginning that explains what it does and what's needed. It's greatly overexaggerated for your instructor to say that "none" of the examples work. If you want one that is designed where all the pieces fit together, then try the tutorial.

joeposton
2004-11-16, 07:01 PM
THANKS... I have a form with Bottons on it... cmd1 and cmd2...
MY INSTRUCTOR is CORRECT... NONE of the SAMPLES WORK... (N-O-N-E)
THERE is some EXTRA CODE to make them WORK... B-U-T NONE is GIVEN...
WE need code snippets inserted to make them (EXAMPLES) WORK...
I am a software consultant Microsoft (ISV) and when I teach or give an EXAMPLE...
IT must work correctly the first time... or IM FIRED...
IF you (anybody) got snippets that will make ADDWEDGE WORK...
GREAT... PASS IT ON... THANKS...

Ed Jobe
2004-11-16, 07:32 PM
I've used some as-is. I gave you the info you need to make this sample work. It seems the names you gave the buttons don't match. CommandButton1, not cmd1. If you don't want to rename your buttons, go to the sub for its click event and just paste in the code between Sub..End Sub.

Ed Jobe
2004-11-16, 07:49 PM
I just used the example as-is. It doesn't have any event requirements. The only requirement is that you have a modespace viewport. These examples are not meant to cut and paste into an application, but to impart understanding. You should try to follow the code execution through in your mind. Their inline comments help you. Note the last part, "Set up the viewport". If you don't have one, it won't work. This part isn't really necessary. The wedge is already created. It is a single line, the AddWedge method. Prior to that, setup was done for the AddWedge method's arguments. In the real world, you would probably prompt the user for this info. The viewport part is just to show you the wedge in 3d so it doesn't look like a rectangle. Again, they are not production examples, but like any human work, they can have typos. Also, if you don't have a ms viewport, but do have a paperspace vp, change the lines from "ActiveViewport" to "ActivePViewport".

joeposton
2004-11-17, 03:59 AM
HI ED... THANKS for the INFO... BUT what I need is the actual code (snippets) inserted into the EXAMPLE that make the dam thing work... IF you have that... GREAT...
YES!!! I have the correct buttons names... SEE the above code...
I use cmd1 as a teaching aid...look at the CODE.. its spelled OUT properly...
HAVE you got the code... or NOT... to make ADDWEDGE work properly...
MAKE my code work and resend it along...that would be great..

joeposton
2004-11-17, 02:15 PM
Hi ED...
I forgot the ERROR MESSAGE...
Runtime error: '-2145386390(8020006a)': NO DATABASE...
This is yellow line on SET WEDGEOBJ = ...
I have not seen an error message like this since 1966 @ Bell Labs IBM 360 mod 44 computer using Fortran II... I guess AutoCad has not advanced much since then...
IF you can make ADDWEDGE work on your computer and show me the code... GREAT...

jwanstaett
2004-11-17, 03:12 PM
Are you pasting the code in to a VB form or a VBA form.
The code examples in Autocad are for VBA not VB. I pasted the code from the examples in a VBA form and it work OK. note : you have a error in the the code you added. I copy your code in to my computer and it work after I fixed the error in the code you added.

try the wedge command in AutoCAD to see if it works on your computer. Then run the examples.


Debug.Print "centers = "; centerx

this will error centerx is a array.

Ed Jobe
2004-11-17, 04:27 PM
I didn't do anything to the example other than change ActiveViewport to ActivePViewport. Other than that, I used it as-is. I think you've done something in your code that you don't understand. Why don't you send me your dvb and I'll take a look at it. If I make any changes, I'll comment them.

joeposton
2004-11-17, 09:19 PM
Hi ED... THANKS MUCH...
I have tried some of my ole VBA code and get that stupid error... as on the set wedge...
THIS is my present code... works fine when set wedge is commented out...
Can I send the .DVB code in an E-Mail... I still get that stupid ERROR in earlier reply...

'===============================================================
' This example creates a wedge in model space...
'PROJECT: C:/AUTOCAD 2005/POSTON'S THEOREMS/WEDGE_1.DVB... 11/11/2005
Dim wedgeObj As Acad3DSolid
Dim AcadObjs As Object
Dim AcadDoc As Object
Dim acadObj As Object
Dim centerx(0 To 2) As Double
Dim lengthx As Double
Dim widthx As Double
Dim heightx As Double

Private Sub CommandButton1_Click()
' Define the wedge... DO NOT USE RESERVE WORDS
' THIS RUNS PERFECTLY WITH THE SET WEDGE COMMENTED OUT...
'=============================================
Set AcadObjs = GetObject(, "AutoCAD.Application") 'USED IN OLD R2000 CODE
Set AcadDoc = AcadObjs.ActiveDocument
'=============================================
centerx(0) = 0#: centerx(1) = 0#: centerx(2) = 0
lengthx = 10#: widthx = 10#: heightx = 20#
Debug.Print "centers = "; centerx(0); " "; centerx(1); " "; centerx(2)
Debug.Print "length = "; lengthx; " "; "width = "; widthx; " "; "height ="; heightx

' Create the wedge in model space
'Set wedgeObj = ActiveDocument.ModelSpace.AddWedge(centerx, lengthx, widthx, heightx)
'wedgeObj.Update

' Change the viewing direction of the viewport
'Dim NewDirection(0 To 2) As Double
'NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
'ThisDrawing.ActiveViewport.Direction = NewDirection
'ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
ZoomAll ' this works and will ZOOM ALL...

End Sub

Private Sub CommandButton2_Click()
End
End Sub

Private Sub CommandButton3_Click()
TextBox1.SetFocus
End Sub

Private Sub UserForm_Click()

End Sub

joeposton
2004-11-17, 09:32 PM
YES!!! corrected centerx ERRORS...
YES!!! the wedg works PERFECTLY on my computer... many times...
YES!!! I am useing VBA code in Autocad r2005... Win XP Pro... HP ZD 7202...
I have tried other VBA code and get the same stupid error...
RUNTIME ERROR: '-214538639098020006A0': NO DATA BASE... kinda stupid I think...
Maybe something is wrong with my computer...

Ed Jobe
2004-11-17, 11:09 PM
Send me the whole dvb, not just the code.

joeposton
2004-11-18, 01:43 PM
HI FOLKS...
My son can over and immediately said I HAVE as AUTOCAD SYSTEM ERROR...
BAD or NON-EXISTING .DLL or something in the SYSTEM...

BUT NO ONE suggested the the ERROR code was system ERROR not VBA...

I wish to thank everyone for their assistance... HOPE we get it closer next time...

Ed Jobe
2004-11-18, 05:08 PM
You never said anything about a missing dll, only a runtime error. A runtime error is caused by vba.

joeposton
2004-11-23, 04:32 PM
HI ED...
The error it gave is the only one I had... BUT my son said I had a more difficult problem..
He called his system analyst at AutoCad (Seattle - home of VBA) and he sent some system code to be inserted... FIXED instantly...
THIS PROJECT works perfectly with some of the example VBA code... NOT ALL...
BUT NOT ALL EXAMPLES FUNCTION... try to make a FRUSTUM of a CONE.... Ha...

PLEASE TAKE THIS THREAD OFF... as this project is over... MUST move ON...

AGAIN... I wish to thank everyone who HELPED... THANKS...