Author Topic: VBA Controls Project  (Read 40394 times)

0 Members and 1 Guest are viewing this topic.

jbuzbee

  • Swamp Rat
  • Posts: 851
VBA Controls Project
« on: July 05, 2006, 02:54:37 PM »
OK, I've started a VBA controls project for the ObjectDCL community.  Hopefully this can be a project we all can learn from -I've sure learned alot from just creating this project.  I've included most of the more common controls found in ODCL.  Most of them I've got some pretty simple programming for, the ListView and TreeView I'm going to ask the VBA community to help out with.  I'll cross post this over at the VBA forum here at the swamp and also at the AutoDesk VBA discussion group.  Here's a look at the form:



The controls are:

ListView
TreeView
TextBox - coded for saving a view
ComboBox - one each for changing the active textstyle and dimstyle
ListBox - one each single and multiple select
Command Buttons - various applications - note the relationship with AutoLISP ("command" . . .)
Labels - interactive with other controls
Toggle Buttons - coded to switch from modelspace to paperspace
Option Buttons - coded to switch ortho on and off
Tab Control - contains the Dimstyle and TextStyle controls.
Picture Control

I've labeled the dvb file for today's date.  If anyone makes changes re-name with the date of the changes and perhaps even your initials.  Again, if anyone can help in providing code for the other controls - of better / different code for any controls I think this could be a useful project for many. 

Thankyou everyone who's helped thus far!!

jb
James Buzbee
Windows 8

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #1 on: July 05, 2006, 03:26:13 PM »
Looks like a good start for it.  The question begs that if you are using VBA for the form, why not for the whole project although I fully understand that the comfort level can be much higher in some languages than others.  This is definitely a nice hybridisation.  I'm pretty snowed under at work this week but will try to help fill in blanks when I can.

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #2 on: July 05, 2006, 03:51:36 PM »
changed the filename to include tim (GMT) and made a few quick changes to some of your If/Thens

Instead of saying

If something Then
Else
do something here
End If

to get a negative result, use If Not to test for a false.

Code: [Select]
Public Sub initializeListBox1()
VBAControls.ListBox1.Clear

For Each entry In ThisDrawing.Layers
If Not entry.Name Like "*|*" Then
VBAControls.ListBox1.AddItem entry.Name
End If
Next
End Sub
« Last Edit: July 05, 2006, 03:58:21 PM by Bob Wahr »

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #3 on: July 06, 2006, 08:43:51 AM »
Just a thought but if every time it is changed, it gets attached into this thread, it could get not only difficult to keep track of but will potentially start taking up a good chunk of server space.  I'm thinking that you and a few other ODCL people who are interested in this project could form a committee of sorts. 
Changes could be submitted to you and included if approved. 
You can discuss what, if any added functionality would be nice and post it for people to work on.
If anyone has a suggestion, it could be decided upon before the person spends time working on it.

Robert_s

  • Guest
Re: VBA Controls Project
« Reply #4 on: July 06, 2006, 10:10:17 AM »
Hello JP,

This is a good start for me. Thank you for this example. I was wondering
if you could also create a "Modeless" dialog box example with the same controls.

Most  of my Odcl projects are modeless. I use them between drawings.
Do you have a solution for  Odcl's...
1. Odcl_Form_IsActive 
2. OnDocActivate

Your help will be greatly appreciated.

Thanks,
Robert

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #5 on: July 06, 2006, 11:40:13 AM »
Robert,  You can make the same form modeless.  All you have to do is bring up your VBA IDE which you can do several ways, the easiest IMO being Alt+F11.  In the Project Pane, double click on VBAControls under Forms.  This will show the form in design mode.  Click on the title bar of the form so that the whole form is selected.  Now all of the Form's Properties are shown in the Property Pane.  Simply go down the list to "ShowModal" and set it to False.  You can also change it programatically so if you wanted a button that would toggle the form between modal and modeless you could do it.

Robert_s

  • Guest
Re: VBA Controls Project
« Reply #6 on: July 06, 2006, 12:07:14 PM »
Bob,

Yes! It worked. There is life after Objectdcl after all.
Thank you for your detailed explanation & illustration. 

Now is there a way I can tell my drawing/s that this form
is loaded/active when switching between drawings and/or
when I open a new drawing? Just like Odcl's.
.."Odcl_Form_Active" and "OnDocActivate"?

I hope vba via autolisp has something similar.


Much Thanks,
Robert

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #7 on: July 06, 2006, 12:29:37 PM »
I am entirely unfamiliar with ODCL so I'm not sure exactly what Odcl_Form_Active or OnDocActivate do, but I'm guessing that OnDocActivate would be basically covered if you put this into the ThisDrawing Module
Code: [Select]
Private Sub AcadDocument_Activate()
MsgBox "What's up, Doc?"
End Sub
and thatOdcl_Form_Activate could be done by putting the following into the form code, which can be done by clicking VBAControls in the Project Pane, then right click and select View Code
Code: [Select]
Private Sub UserForm_Activate()
MsgBox "Formin' at the mouth!"
End Sub

LE

  • Guest
Re: VBA Controls Project
« Reply #8 on: July 06, 2006, 01:09:15 PM »
Bob;

So, in that event is where the Modeless forms are updated?

Robert_s

  • Guest
Re: VBA Controls Project
« Reply #9 on: July 06, 2006, 01:14:43 PM »
Le & Bob,

Thats exactly what I was trying to ask.

Lets say I first open 2 dwgs. Then I open a 3rd one.
On the 3rd dwg I loaded "vbacontrols.lsp". The layer
listbox will populate itself with that 3rd dwg layers.
Now when I switch to the first or second dwg I want the
layer listbox to update itself too with that current dwg's
layers..I guess this is where ODCL's event "OnDocActivate"
comes into play. I want to load again "vbacontrols.lsp".

And if I open a 4th dwg, I need something in my startup
lisp routine like ODCL's "Odcl_Form_Active" that if it
sees that the form it loaded/floating it will update the
form's layer listbox too with the 4th dwg's layers.(Or
load "vbacontrols.lsp" again?).

What do you think?


Robert,

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #10 on: July 06, 2006, 01:34:21 PM »
Ahh, I see.  Change the Userform_initialize sub to
Code: [Select]
Public Sub UserForm_Initialize()
Module1.FormStart
Message.Caption = "Use this project to aid in the transition from ObjectDCL to Hybrid Apps using VBA forms with AutoLISP!"
End Sub
add this to Module 1
Code: [Select]
Public Sub FormStart()
Module1.initializeToggleButtons
Module1.initializeOptionButtons
Module1.initializeListBox1
Module1.initializeListBox2
Module1.initializeComboBox1
Module1.initializeComboBox2
End Sub
and add this to ThisDrawing
Code: [Select]
Private Sub AcadDocument_Activate()
Module1.FormStart
End Sub
Is that what you're after?

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #11 on: July 06, 2006, 01:55:57 PM »
Here's an updated dvb although I took some liberties with the form.

Robert_s

  • Guest
Re: VBA Controls Project
« Reply #12 on: July 06, 2006, 02:02:16 PM »
Bob,

Yes...!!!!!!!! It's funny how this morning your instructions
was to hit Alt+F11 to start up the VBA IDE. This was the
first time I've ever seen that "vba screen". It was quite
scary & intimidating.

In a scale to 1 to 10. I'm
a 6 with autolisp
a 7 with objectdcl
a 0 with Vba


Thanks to you & JB I think I'm a little confident now to start
learning VBA. 


Thank you guys for being around!!!!!


Robert,

Bob Wahr

  • Guest
Re: VBA Controls Project
« Reply #13 on: July 06, 2006, 02:11:59 PM »
I use this comparison with both the difference between Micrstation and AutoCAD and the difference between VBA and Lisp.  It's pretty much the same as the difference between a standard calculator and a RPN HP calculator.  Both will get you there, you just have to train your brain to think a little differently.  This is a good place to learn it, there are a lot of very knowledgable, very helpful people here who will help you with any problems that you run into, many of whom were instrumental in my learning it as well (although I'm sure none of them would admit it.)

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: VBA Controls Project
« Reply #14 on: July 06, 2006, 04:10:38 PM »
Robert - sorry I've been out on a job site!  Looks like you got the help you needed - isn't this site great?  I quickly read through the posts and implimented this on all my modeless forms. One word: AWSOME!  No more refresh button!!!!

Bob - a big thanks for the direction to the AcadDocument_Activate function.  I'm really diggin this VBA stuff.  :wink:

jb
James Buzbee
Windows 8