Author Topic: Question - Just getting started  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Question - Just getting started
« on: July 14, 2006, 02:51:22 PM »
With all this talk latley about VBA-lisp I decided to open the VBAIDE and start poking my head around.  My skill level with VBA is at about a -1.  I must say i do like the forms editor alot better than DCL  :roll: . Ok so to begin with I opened the help and started browsing. I decied to start small (very small).  I found a project in the help ;
Code: [Select]
Sub Ch4_IteratingLayers()
    Dim layerNames As String
    Dim entry As AcadLayer
    layerNames = ""
    For Each entry In ThisDrawing.Layers
        layerNames = layerNames + entry.Name + vbCrLf
    Next
    MsgBox "The layers in this drawing are: " + _
           vbCrLf + layerNames
End Sub

I started changing things to see what was what so far so good.

My question is what is "vbCrLf"?

What I am hoping to do is create some reusable funtion and store them.  to do this do I create a new module and add functions to that?

How do I get subs to return info i.e. how would I get the above sub to return a list that can be used in a listbox?

Thanks all.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Question - Just getting started
« Reply #1 on: July 14, 2006, 03:07:34 PM »
I m pretty sure it's:

vbCrLf=Visual Basic Carraige Return Line Feed.

A constant for an 'enter' character in the string.

TR

  • Guest
Re: Question - Just getting started
« Reply #2 on: July 14, 2006, 03:07:59 PM »
My question is what is "vbCrLf"?
vbCrLf means Carriage Return Line Feed. It's basically a newline statement.

What I am hoping to do is create some reusable funtion and store them.  to do this do I create a new module and add functions to that?
I usually keep all my functions in a single module and then import it into each project. Not sure if it's best way to do it but it has worked for me.

How do I get subs to return info i.e. how would I get the above sub to return a list that can be used in a listbox?
If you want a function to return something you need to name it as so. For example if I wanted something to return a boolean value you would need to create a function like
Code: [Select]
Public Function IsItemValid(Item as string) as Boolean
'perform validation code here
If ValidationCodeIsTrue then
    IsItemValid = True
Else:
    IsItemValid = False
End Function

However if you wanted to populate a listbox with layernames then the best thing to do would is populate the listbox when the userform is initialized.

For each layer in Thisdrawing.Layers
    listbox.AddItem layer.Name
Next

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Question - Just getting started
« Reply #3 on: July 14, 2006, 03:12:44 PM »
It just so happens we are starting the VBA class up again, And we are talking about Forms.  BobWahr and I are putting together the first installment this weekend.  Look for it early next week
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Question - Just getting started
« Reply #4 on: July 14, 2006, 03:19:24 PM »
Thanks guys,

That makes sense once I seen it run I get a long (vertical) msgbox with each layer on its own line.

CmdrDuh,

I have just started going through your old VBA course and reading through some of the material (Great stuff).  I will be looking forward to see the nex installment.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Arizona

  • Guest
Re: Question - Just getting started
« Reply #5 on: July 14, 2006, 05:42:46 PM »
How do I get subs to return info i.e. how would I get the above sub to return a list that can be used in a listbox?
A Sub won't return a value, but a function will.

Bob Wahr

  • Guest
Re: Question - Just getting started
« Reply #6 on: July 14, 2006, 05:52:04 PM »
although there are ways to get it to shhhhhhhhhhhh I didn't say that.