TheSwamp

Code Red => VB(A) => Topic started by: David Hall on May 03, 2005, 05:31:35 PM

Title: Topics for a VBA Tutorial
Post by: David Hall on May 03, 2005, 05:31:35 PM
Please post what kind of topics you would like to see in a VBA tutorial.  Please try to keep this thread on topic.  EX. I would like a utility to turn all my graphics to Color=ByLayer and Linetype=ByLayer
Title: Topics for a VBA Tutorial
Post by: Oak3s on May 03, 2005, 05:52:07 PM
for tutorial topics i would like a tutorial on how to 'use' the utility created.
for specific utilitiesi would like a utility to create layers.
"" to insert blocks from specified location
Title: Topics for a VBA Tutorial
Post by: David Hall on May 03, 2005, 05:55:40 PM
both of those are good topics.  Espically the first b/c VBA doesn't offer an EASY way to make a shortcut.
Title: Topics for a VBA Tutorial
Post by: Mark on May 03, 2005, 06:27:59 PM
1 ) Entity manipulation and creation.

2 )  File I/O.

In that order.
Title: Re: Topics for a VBA Tutorial
Post by: Birdy on May 03, 2005, 07:03:01 PM
Quote from: CmdrDuh
I would like a utility to ...

How 'bout start a new job/open existing job.
New job would give an interface (dailog?) to enter pertinent info like job name, number, customer, etc. and create a folder, populate the titleblock info & save everything to a drive location.  Existing job would either open an existing dwg for editing, or add a new dwg to the existing folder.

IOW, no more creating folders or browsing thru them in windoze.
Title: Topics for a VBA Tutorial
Post by: BAshworth on May 04, 2005, 01:51:18 AM
Ok, that's easily do-able Birdy.  Although, isn't this what the wonderful folks at Autodesk gave us the Sheet Set Manager for? :D  J/k.

The entity manipulation is also a very good one.  VBA gives us almost total control over all the aspects of a drawing object's properties, but very few of the modifications are available directly. (ex. trim, break, move, copy)  You can still do all of those, but you have to know your way around to be able to pull it off.

For file I/O, are you talking about text files, or dwg files?

heh, "blocks" will be fun.  Since "blocks" and "blockreferences" are two terms that don't come into AutoLisp very often.

As a given, any tutorials will seem easier for those versed in V-Lisp vs. those who only know AutoLisp.  V-Lisp uses many of the same terms as VBA, and the way of manipulating objects is also somewhat similar.

I think that we can also work in the topics that Mark mentioned (private and public subs and functions) at the same time.
Title: Topics for a VBA Tutorial
Post by: Mark on May 04, 2005, 03:30:13 AM
Quote
For file I/O, are you talking about text files, or dwg files?

text files.
Title: Topics for a VBA Tutorial
Post by: Birdy on May 04, 2005, 07:14:04 AM
Quote from: BAshworth
Ok, that's easily do-able Birdy.  Although, isn't this what the wonderful folks at Autodesk gave us the Sheet Set Manager for? :D  J/k.


Sheet sets... gotta have em to use em (a2k4 here) unless I'm missing something.
Title: Topics for a VBA Tutorial
Post by: daron on May 04, 2005, 08:01:05 AM
So is this going to be a tag team teaching set? It is getting interesting.
Title: Topics for a VBA Tutorial
Post by: jonesy on May 04, 2005, 08:42:19 AM
Would it be possible to create a routine that stops users creating layers with "incorrect" layer names :roll:
Title: Topics for a VBA Tutorial
Post by: ELOQUINTET on May 04, 2005, 09:23:29 AM
some basic terms would be nice to begin with (for me at least)
and a tutorial of the vba manager (which i still don't quite grasp)  :oops:
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 09:29:51 AM
Quote from: ELOQUINTET
some basic terms would be nice to begin with (for me at least)
and a tutorial of the vba manager

Im working on that right now.  I hope to have something ready to hand out by Monday
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 09:32:26 AM
Quote from: jonesy
Would it be possible to create a routine that stops users creating layers with "incorrect" layer names :roll:

No, but maybe. Depends on how cruel you want to be to your non-conformists.  Say for instance they created a wrong layer name, you can search the entire drawing for non standard names, and move all the graphics on those layers to another layer.  Then they would have to sort out the mess on the correct layers.  Or you could just delete it and make them do it again.
Title: Topics for a VBA Tutorial
Post by: daron on May 04, 2005, 09:34:15 AM
Sounds like ODBX to the rescue on that one?
Title: Topics for a VBA Tutorial
Post by: Keith™ on May 04, 2005, 09:40:22 AM
Well, you "could" do something a little more sneaky .... how about turning off the ability to create layers altogether .. force users to use a template with the layers already defined. It can be done ... but it won't be pretty
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 09:46:40 AM
Quote from: Keith
Well, you "could" do something a little more sneaky .... how about turning off the ability to create layers altogether .. force users to use a template with the layers already defined. It can be done ... but it won't be pretty

Like undefining the commands or deeper than that?
Title: Topics for a VBA Tutorial
Post by: Keith™ on May 04, 2005, 09:55:47 AM
Well, like an API that disables the "new" button in the layer dialog, removes the "new layer" option from the popup menu and intercepts the "layer" command from the command line.

Unfortunately, the only real way to prevent the making of layers is to have an event fire when a layer is created, check against a list of authorized layers then have the unauthorized layer deleted. The question becomes how to deal with any entities on the layer when you want to delete it ... such as when inserting a block .. any layers in the block are automatically created
Title: Topics for a VBA Tutorial
Post by: daron on May 04, 2005, 01:03:33 PM
Personally CMDuh, I think if you started with the basics, like how to use and test code in the ide, how to use the watch window, and other debugging tasks and the importance of indenting and commenting code. That would be a great start. You'll have some heavy hitters like Keith and Ben, but the majority of us are mush brained when it comes to starting vba. Myself, being knowledgeable in Vlisp, it wouldn't take too long to grasp this after getting through the basics, but until then, I'm a mush brain with vba.
Title: Topics for a VBA Tutorial
Post by: M-dub on May 04, 2005, 01:06:41 PM
Outline of good and bad habits to start / avoid. :?:
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 01:15:12 PM
Quote from: Daron
Personally CMDuh, I think if you started with the basics, like how to use and test code in the ide, how to use the watch window, and other debugging tasks and the importance of indenting and commenting code. That would be a great start.

Thats the idea.

Quote from: Daron
You'll have some heavy hitters like Keith and Ben, but the majority of us are mush brained when it comes to starting vba.


And I'm counting on Ben and Keith and the other GURUs to fill in the blanks when we get to an area I'm not versed in.  I'm self taught with a lot of questions asked on Cad Vault.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 01:17:25 PM
Quote from: M-dub
Outline of good and bad habits to start / avoid. :?:

Thats hard b/c that would be my opinion... There are the obvious ones like COMMENT you code, but we all know that, we just dont always follow thru.  There are some good guidelines that I'm putting in the getting started guide I'm making.  Hopefully that is what your looking for.
Title: Topics for a VBA Tutorial
Post by: Keith™ on May 04, 2005, 01:29:18 PM
Quote from: CmdrDuh
Quote from: Daron
Personally CMDuh, I think if you started with the basics, like how to use and test code in the ide, how to use the watch window, and other debugging tasks and the importance of indenting and commenting code. That would be a great start.

Thats the idea.

Quote from: Daron
You'll have some heavy hitters like Keith and Ben, but the majority of us are mush brained when it comes to starting vba.


And I'm counting on Ben and Keith and the other GURUs to fill in the blanks when we get to an area I'm not versed in.  I'm self taught with a lot of questions asked on Cad Vault.


You can count me in as far as offering advice from time to time ... I won't soon be able to actually manage teaching a class, but I MIGHT over the course of the next few weeks put together an API primer ... Those who are familiar (intermediate) with VB(A) will likely want to look toward expanding its usefulness.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 01:52:59 PM
Keith, that would be great!
Title: Topics for a VBA Tutorial
Post by: MP on May 04, 2005, 01:58:39 PM
If it's ok I'd like to contribute too when I've time. I programmed in VB before it even became a Windows application.

:)
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 02:01:45 PM
Quote from: MP
If it's ok I'd like to contribute too when I've time. I programmed in VB before it even became a Windows application.

:)


The more the better!  This originally started out very small as a one-on-one thing, and its grown very quickly.
Title: Topics for a VBA Tutorial
Post by: TR on May 04, 2005, 02:24:12 PM
CmdrDuh :
I look forward to seeing what you come up with. I'm sure it will be quite excellent.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 02:26:04 PM
Well I hope I meet your expectations.  I "used" to teach for a living for Autodesk reseller, so the teaching part is not too hard.  But I have only done 1 or 2 web class things, so we will see how it goes.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 02:27:08 PM
Also, it should be noted that I am more of a hacker than a programmer(being self taught).  I make it work, not always the most elegant way possible.
Title: Topics for a VBA Tutorial
Post by: TR on May 04, 2005, 02:28:36 PM
Quote from: Keith
but I MIGHT over the course of the next few weeks put together an API primer ... Those who are familiar (intermediate) with VB(A) will likely want to look toward expanding its usefulness.


Keith:
I hope to see something like this from you. The Windows API is something I've yet to venture into in VBA and a primer course would be very nice. Judging by what I've seen from you in the past I'm sure it would be a worthwhile read.
Title: Topics for a VBA Tutorial
Post by: MP on May 04, 2005, 02:59:56 PM
Quote from: CmdrDuh
Also, it should be noted that I am more of a hacker than a programmer(being self taught).  I make it work, not always the most elegant way possible.

Quick, read this (http://www.theswamp.org/phpBB2/viewtopic.php?p=60813#60813).

(http://www.theswamp.org/screens/mp/thumbsup.gif)
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 03:05:36 PM
MP, its funny that you sent me there, b/c I read that just this morning.  Whats also funny is I teach by that very principle.  What I meant about being a hacker is I have no formal trainging in VB(A) so the methods I will be showing are what I know. (Which is sometimes not the best way to get the job done)  Also, I dont program for a living, so by someothers standards, that makes me a hacker not a programmer.  Either way, I dont care, because if it helps me get my job done faster or more efficiently, its a program.
Title: Topics for a VBA Tutorial
Post by: daron on May 04, 2005, 03:08:14 PM
And if teaching it helps you get better knowledge, then you become a better hacker/programmer.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 04, 2005, 03:10:28 PM
Quote from: Daron
And if teaching it helps you get better knowledge, then you become a better hacker/programmer.

Exactly!!!
Title: Topics for a VBA Tutorial
Post by: Kerry on May 04, 2005, 08:57:14 PM
Quote
Also, I dont program for a living, so by someothers standards, that makes me a hacker not a programmer.


here, here. According to some people there are only the the 2 clubs.

Personal Opinion : Programming is about solving problems. You solve problems, therefore ...

< deleted derogarory remarks about some academics >
Title: Topics for a VBA Tutorial
Post by: David Hall on May 05, 2005, 09:33:21 AM
KWB - Thank You
Title: Topics for a VBA Tutorial
Post by: jonesy on May 06, 2005, 07:09:49 AM
OK, getting back on track, would it be easy to create a proggy that can issue a save every 10 commands? Could this be covered in a course?
Title: Topics for a VBA Tutorial
Post by: Keith™ on May 06, 2005, 10:07:29 AM
Tracey, that would be a simple program in VBA ...
Title: Topics for a VBA Tutorial
Post by: hyposmurf on May 06, 2005, 11:53:48 AM
Not only simple but dam handy. :)
Title: Topics for a VBA Tutorial
Post by: ML on May 06, 2005, 03:02:38 PM
Has anyone tried applying VBA in other programs? I have several macros in Excel as well and quite frankly, enjoy it more then CAD at times.

The irony is that it helps me approach programming better in AutoCAD.

Anyone who is in this forum is very fortunate. I have learned a bit from different people and a lot from others.

I still have a long way to go but I have also come a long way in VBA. So anyone in this forum (with persistence) can learn just as I am.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 06, 2005, 03:11:56 PM
OK, this is jumping ahead, but here is that program.  I will have to look to see who gets credit for this.

Code: [Select]

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)

'***Below code is to AUTO save the drawing every 25 commands,
  If ThisDrawing.GetVariable("DWGTITLED") = 1 Then 'don't use on new, unsaved drawings
  Select Case CommandName
    Case UCase("undo"), UCase("u"), UCase("zoom"), UCase("z"), UCase("pan")
        command_count = command_count
    Case UCase("QSAVE"), UCase("SAVE")
        command_count = 0
    Case Else
        command_count = command_count + 1
        If command_count = 25 Then 'change this to any number you want
            ThisDrawing.Save
            command_count = 0
        End If
    End Select
  End If
End Sub
Title: Topics for a VBA Tutorial
Post by: David Hall on May 06, 2005, 03:13:57 PM
Jeff_M gets credit for that module.
Title: Topics for a VBA Tutorial
Post by: MP on May 06, 2005, 03:16:09 PM
That's Jeff Mishler in case anyone wants to know. An excellent programming lad that wears a white hat.
Title: Topics for a VBA Tutorial
Post by: ML on May 06, 2005, 03:17:43 PM
Did everyone want too turn this into a code posting post? Or are we going to stick to basic theory?
Title: Topics for a VBA Tutorial
Post by: David Hall on May 06, 2005, 03:17:55 PM
It needs to be placed in the ThisDrawing module of the Acad.dvb (or any dvb that will always be loaded)  For those of you who do not know where that is, I will be covering that in an upcoming handout.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 06, 2005, 03:18:52 PM
I am putting together handouts that will cover the theory, but by people posting code, we can use those examples in our discussions.
Title: Topics for a VBA Tutorial
Post by: hendie on May 06, 2005, 03:20:08 PM
Quote from: ML
Has anyone tried applying VBA in other programs? I have several macros in Excel as well and quite frankly, enjoy it more then CAD at times.


I use VBA in Word, Excel, AutoCAD, Access, in fact only today I developed a small application in Word for my colleagues over in the US.

truth be told, I'm a lazy sonofa.... so if I can develop something that will save me doing something twice, then I'll do it.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 06, 2005, 03:27:27 PM
Quote from: hendie

truth be told, I'm a lazy sonofa.... so if I can develop something that will save me doing something twice, then I'll do it.

Words I live by :dood:
Title: Topics for a VBA Tutorial
Post by: ML on May 06, 2005, 03:35:28 PM
I second that emotion!
Title: Topics for a VBA Tutorial
Post by: David Hall on May 06, 2005, 06:02:08 PM
UPDATE:  I have most of my images in the Doc file and have all my headings that I want to cover.  Now I just have to add the small text that goes b/t pics.  Should be done for a Monday posting.
Title: Topics for a VBA Tutorial
Post by: Mark on May 07, 2005, 08:04:54 AM
:dood:
Title: Topics for a VBA Tutorial
Post by: jonesy on May 08, 2005, 09:06:36 AM
You guys here are great :dood:
Title: Topics for a VBA Tutorial
Post by: hyposmurf on May 08, 2005, 06:14:11 PM
Would it be an idea to create a new thread that is strictly a tutorial and only certain members can add to it (CmdrDuh etc)?That way the tutorial wont become disjointed, as members post their comments and the thread grows ever larger.
Title: Topics for a VBA Tutorial
Post by: Mark on May 08, 2005, 06:31:40 PM
Quote from: hyposmurf
Would it be an idea to create a new thread that is strictly a tutorial and only certain members can add to it (CmdrDuh etc)?

Way ahead of ya. :)
Title: Topics for a VBA Tutorial
Post by: David Hall on May 09, 2005, 01:53:35 PM
Please PM me if you would like access to the Tutorial forum that Mark has created.
Title: Topics for a VBA Tutorial
Post by: BAshworth on May 09, 2005, 02:12:27 PM
Hate it when I get busy (and lazy) So David, are you posting your first tutorial today?

Daron used to work for Pulte out here. (If I remember correctly)
Title: Topics for a VBA Tutorial
Post by: hyposmurf on May 09, 2005, 02:13:30 PM
I'd like access to veiw it but as far as teaching VBA goes. :lol: Thats why I'd like access as I havent a clue.
Title: Topics for a VBA Tutorial
Post by: David Hall on May 09, 2005, 02:13:34 PM
Yes, Im trying to set up the group access now
Title: Topics for a VBA Tutorial
Post by: daron on May 09, 2005, 03:12:50 PM
Yup, Ben. That's me. Your memory serves you well.