TheSwamp

Code Red => VB(A) => Topic started by: TimSpangler on July 14, 2006, 02:51:22 PM

Title: Question - Just getting started
Post by: TimSpangler 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.
Title: Re: Question - Just getting started
Post by: Atook 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.
Title: Re: Question - Just getting started
Post by: TR 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
Title: Re: Question - Just getting started
Post by: CmdrDuh 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
Title: Re: Question - Just getting started
Post by: TimSpangler 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.
Title: Re: Question - Just getting started
Post by: Arizona 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.
Title: Re: Question - Just getting started
Post by: Bob Wahr on July 14, 2006, 05:52:04 PM
although there are ways to get it to shhhhhhhhhhhh I didn't say that.