AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

Page I. Page II. Home. Page IV.

VBA Primer - Page III.

O.K. we now have our basic dialogue box and would like it to do something.
Firstly, we need to code the cancel button so that we can exit the application
while we are still testing. We also need to create a Module so that we can run
the application from within AutoCAD.

Let's create the Module first.
A new window will open looking like this:

Code Window

This is the code window were you will be writing all of your Visual Basic Code.
If you look at the Project window you will find that a new Module has been created and has been given the default name of Module1.

Now enter the following code into the module : 

	sub chlayer ()
	'name of function

		'display the dialogue box

	End Sub

Thw code window should look like this :

Code Window

As you have probably worked out for yourself, any line starting with a ' is a comment. (The same as the ; in AutoLISP).
Visual Basic also colour codes the coding but I am not going to get into that
at this time.

Next, double click on the Cancel button on UserForm1. The code window will open again, displaying the Click Event procedure for that control.
Type in the following code :

	Private Sub CommandButton2_Click()

    		'end the programme
	End Sub
The code window should look like this :

Cancel Code Window

This sub-routine simply ends the programme if the Cancel button is selected.
Now, let's test our dialogue box.
(This would be a good time to save your project......)
Return to AutoCAD and select TOOLS - MACROS - RUN MACRO from the menu bar.
The following dialogue should appear:

Macro Dialogue

Choose 'Module1' from the list box and 'chlayer' from the drop down list box.
Now select 'Run'. Your dialogue should appear in all it's glory.
(Thunderous applause from the audience.)
Once you have finished admiring your handywork select 'Cancel'.
We still have a couple of problems though. Firstly, there is nothing in the
list box and the OK button doesn't work.
On the next page we'll show you how to populate the list box with all the
layer names in your drawing and then we'll write the main event procedure for
the O.K. button. 

While you are waiting for the next page you might as well grab yourself a beer.
I've got one....... 
Page I. Page II. Home. Page IV.
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website