Public Function does return SS

Public Function does return SS

mdhutchinson
Advisor Advisor
473 Views
10 Replies
Message 1 of 11

Public Function does return SS

mdhutchinson
Advisor
Advisor
The following code snippet is located within in my form level module in a cmd button click event.

For i = 0 To lstOpenDwgs.ListCount - 1
Application.Documents.Item(lstOpenDwgs.List(i)).Activate
Set ssPlineCorrals = getPolyLineBlockCorrals()
MsgBox ssPlineCorrals.Count
Next

The Public function getPolyLineBlockCorrals doesn't return the selection set to ssPlineCorrals variable. The selection set is getting created but doesn't make back to the form code.
What am I missing?

Dim FilterType(0 To 2) As Integer
Dim FilterData(0 To 2) As Variant

FilterType(0) = 8
FilterData(0) = "ContNum"
FilterType(1) = 0
FilterData(1) = "INSERT"
FilterType(2) = 2
FilterData(2) = "`*U*"
' set an error trap for failed selection set calls
On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("test2corrals")
If Err = 0 Then
objSS.Clear
Else
Set objSS = ThisDrawing.SelectionSets.Add("test2corrals")
End If
objSS.Select acSelectionSetAll, , , FilterType, FilterData
objSS.Highlight True

MsgBox objSS.Count ' test line

End Function
0 Likes
474 Views
10 Replies
Replies (10)
Message 2 of 11

mdhutchinson
Advisor
Advisor
Sorry this should have been called
Public Function does NOT return SS
0 Likes
Message 3 of 11

Anonymous
Not applicable
Is your selection an AND or an OR for criteria?

Also, is your function declared like this

Public Function getPolyLineBlockCorrals() As AcadSelectionSet
..... 'whatever it does

Set getPolyLineBlockCorrals = objSS
End Function

Joe
--

wrote in message news:5196898@discussion.autodesk.com...
The following code snippet is located within in my form level module in a
cmd button click event.

For i = 0 To lstOpenDwgs.ListCount - 1
Application.Documents.Item(lstOpenDwgs.List(i)).Activate
Set ssPlineCorrals = getPolyLineBlockCorrals()
MsgBox ssPlineCorrals.Count
Next

The Public function getPolyLineBlockCorrals doesn't return the selection set
to ssPlineCorrals variable. The selection set is getting created but
doesn't make back to the form code.
What am I missing?

Dim FilterType(0 To 2) As Integer
Dim FilterData(0 To 2) As Variant

FilterType(0) = 8
FilterData(0) = "ContNum"
FilterType(1) = 0
FilterData(1) = "INSERT"
FilterType(2) = 2
FilterData(2) = "`*U*"
' set an error trap for failed selection set calls
On Error Resume Next
Set objSS = ThisDrawing.SelectionSets("test2corrals")
If Err = 0 Then
objSS.Clear
Else
Set objSS = ThisDrawing.SelectionSets.Add("test2corrals")
End If
objSS.Select acSelectionSetAll, , , FilterType, FilterData
objSS.Highlight True

MsgBox objSS.Count ' test line

End Function
0 Likes
Message 4 of 11

mdhutchinson
Advisor
Advisor
thanks Joe... it appears that I didn't include...
Set getPolyLineBlockCorrals = objSS

It seems to work now... I am testing.
0 Likes
Message 5 of 11

mdhutchinson
Advisor
Advisor
Joe... is this the 'construct' that must be used if a function is meant to return a value? That is that the same variable needs to be use? ... and like LISP it returns the last executed code to the calling function?
0 Likes
Message 6 of 11

Anonymous
Not applicable
If your function did not return a value it wouldn't be a function [but
rather a sub].

Yes, you have to use the construct as shown.

[I don't know about AutoLISP, it's been about 10 years since I used it]. If
memory serves me I think everything is a function in AutoLISP?

Joe
--

wrote in message news:5196940@discussion.autodesk.com...
Joe... is this the 'construct' that must be used if a function is meant to
return a value? That is that the same variable needs to be use? ... and
like LISP it returns the last executed code to the calling function?
0 Likes
Message 7 of 11

mdhutchinson
Advisor
Advisor
so putting it another way...
Is it the fact that it is a 'function' ...
or that the same varialbe is used, or
that it is the last line in the function that makes for a successful return? ... or all of these?
0 Likes
Message 8 of 11

Anonymous
Not applicable
You have to use the construct I showed you, the way it is, because your
returned variable is an object.

Had you been returning say a String variable you would drop the Set.

Either way you must state the function name equal to a variable or value of
the datatype declared.

Here are the two examples:

Public Function WhatEver() As ObjectDataType
Set WhatEver = ObjectDataType variable
End Function

Public Function WhatEver() As String
WhatEver = "Some string value or variable"
or
WhatEver = StringVariable
End Function

I'm should there are other examples that could be given but this should help
explain the basics for your situation.

Joe
--

wrote in message news:5196948@discussion.autodesk.com...
so putting it another way...
Is it the fact that it is a 'function' ...
or that the same varialbe is used, or
that it is the last line in the function that makes for a successful return?
... or all of these?
0 Likes
Message 9 of 11

Anonymous
Not applicable
No, vba does not work like lisp. A value is not automatically "returned". In
lisp everything in parens is a function. In vba, to create a "function", you
must assign a value or object to the procedure's name. Otherwise it remains
just a "procedure" that performs some action.

--
----
Ed
----
0 Likes
Message 10 of 11

Anonymous
Not applicable
Slight correction:

In VB/VBA, a function DOES automatically return a value if you did not
assign a value to the function within the function. The returned value, in
this case, is the default value of the data type the function is supposed to
return.

For example,

Public Function GetInteger() As Integer

Dim i as Integer
Dim j as Integer
i+j

''Note, no value is assigned to GetInteger

End Function

This function returns 0, which is default value of Integer type

You can even not specify Function's return type, like this:

Public Function GetValue()

'Do something
'You can even not assign a value back to GetValue

End Function

In this case, it return Empty (vbEmpty, since there is VB enum. value to
represent Empty, so we can still say the function returns a value), if you
did not assign any value to the function, or it returns whatever data type
you assign to the function

Sometimes, VB/VBA simply does too much for programmers, that encourages "not
so good practice". My thumb of rule here is to always expiciltly declare a
function's return type and to always assign the function a return value
within the function.

"Ed Jobe" wrote in message
news:5197036@discussion.autodesk.com...
No, vba does not work like lisp. A value is not automatically "returned". In
lisp everything in parens is a function. In vba, to create a "function", you
must assign a value or object to the procedure's name. Otherwise it remains
just a "procedure" that performs some action.

--
----
Ed
----
0 Likes
Message 11 of 11

Anonymous
Not applicable
Thanks for the clarificatin Norman. I was thinking in terms of "useful
information", i.e. he was expecting something more specific.

--
----
Ed
----
0 Likes