Home > ZWCAD > Compile and Work with Customiz >
VBA

May 20, 2011

VBA is a kind of programming language including variety of Microsoft applications program environment (such as WORD, EXCEL .etc)

Microsoft VBA is a type of program environment for objects, capable of providing developing function as Visual Basic 6 (VB). The main difference between VBA and VB is that VBA runs together with ZWCAD in the same process space, and provides intellective and frequent program environment.

VBA provides application integration for those application programs supportive of VBA. That is to say, ZWCAD (using other applications database) can be Automation controlling program such as Microsoft Word or Excel and other applications.

You should purchase independent developed version of Visual Basic 6,providing ZWCAD VBA with extra components, such as external database engine and report forms compiling function.

Four advantages of realizing VBA in ZWCAD:

  •      VBA and its environment are prone to study and apply.

  •      VBA is capable of running together with ZWCAD in the same process space and facilitate the program operating.

  •      Rapid and effective construction of dialog box, which enables developers construct prototype applications and receive design feedback quickly.

  •      The project is both independent and embedded supported. Which provides developers with flexible ways to release their applications.

VBA applications are saved in Projects files, ZWCAD® VBA project is a combination of code module, class module and window, all these modules and windows run together to execute specified function. The project can be stored in both ZWCAD drawings and also can be stored as independent file.

You can open VBA manager through ZWCAD menu Tools-Macro-VBA Manager to view VBA project in which you are allowed to create, load and close projects.

ZWCAD VBA project is incompatible with independent Visual Basic 6 project binary system. However, you can use IMPORT File and EXPORT File from File menu option to import and export forms, modules and classes while working in VBA IDE.

Open VBA environment

VBA has its own interface environment, execute from "Tools-Macro-VisualBasic editor, to open Visual Basic program and display VBA environment window which is short for IDE, i.e. Integrated Development Environment.

ZWCAD VBA project is a collection of code modules, classes and forms, here module is self-include program code segment, a project is capable of containing multiple modules. These modules and forms run together to perform given functions.

You can add new modules by selecting "Insert – Module" menu option from the Visual Basic project window. And next to open module file editor window, in which you can write codes. Meanwhile, a new module icon will be added in the module list in "Project" window with default name as Modual1.

ZWCAD is running while opening VBA environment, you can toggle to ZWCAD platform from the last option on "View" menu in VBA IDE.

VBA program samples

The following VBA program draws a donut with inside diameter as 10, and outside diameter as 15:

Sub DrawDonut()
        
    Dim CenterPt(0 To 2) As Double
    Dim OutRad As Double
    Dim InRad As Double
    
    CenterPt(0) = 10: CenterPt(1) = 10: CenterPt(2) = 0
    
    OutRad = 15
    InRad = 10
    
    Dim pts(0 To 3) As Double
    
    pts(0) = CenterPt(0) - InRad - Abs(OutRad - InRad) / 2
    pts(1) = CenterPt(1)
    pts(2) = CenterPt(0) + InRad + Abs(OutRad - InRad) / 2
    pts(3) = CenterPt(1)

    Dim PolyObj As ZwcadLWPolyline
    Set PolyObj = ThisDocument.ModelSpace.AddLightWeightPolyline(pts)
    PolyObj.Closed = True
    
    For i = 0 To 1
        PolyObj.SetBulge i, 1
        PolyObj.SetWidth i, Abs(OutRad - InRad), Abs(OutRad - InRad)
    Next i
        
    PolyObj.Update
    
    ThisDocument.Regen
    
End Sub

Remarks

See "VBA Develop and Migrate Guide" and "VBA Reference" in "Developer's help" to view the VBA functions as well as relevant tutorials provided in ZWCAD platform (it's recommended to reference specific instructions from "Help"-"Developer's help").

 

  

PrintPrint Get a PDF version of this webpage PDF
2013 ZWCAD Software Co., Ltd. All rights reserved. | About ZWSOFT | Privacy Policy | Terms and Conditions | Contact us | Site Map