Passing a collection

Discussion in 'AutoCAD' started by James Wedding, Jul 21, 2004.

  1. Help out this poor hack? This code generates an Argument Not Optional error
    when I try to shove the MyStyles out for sorting. Any ideas would be
    appreciated.


    Private Sub StyleTypeComboBox_Change()
    Me.Style1ComboBox.Clear
    Me.Style2ComboBox.Clear
    Dim StyleList() As Variant 'I know I don't need this, it's a leftover.
    Select Case Me.StyleTypeComboBox.value
    Case Is = "Alignment"
    Dim MyStyles As AeccAlignmentStyles
    Set MyStyles = MyDwg.AlignmentStyles
    MakeLists (MyStyles)
    Case "Alignment: Label: Curve"
    'the rest of the cases will go here!
    End Select
    End Sub

    Private Sub MakeLists(ByVal MyObjs As Object)
    Dim StyleObj As Object
    Dim j, k As Integer
    j = MyObjs.Count
    ReDim StyleList(0 To j - 1)
    j = 0
    For Each StyleObj In MyObjs
    StyleList(j) = StyleObj.Name
    j = j + 1
    Next StyleObj
    Style1ComboBox.List = BubbleSort(StyleList)
    Style2ComboBox.List = BubbleSort(StyleList)
    End Sub

    Thanks in advance!
    --
    James Wedding, P.E.
    IT Manager
    Jones & Boyd, Inc.
    Dallas, TX
    XP/1 on P4-3.4/1G
    LDT2004&5+C3D

    Troll :a slang term for a person who posts messages without contributory
    content, simply intended to incite conflict. http://wikipedia.com
     
    James Wedding, Jul 21, 2004
    #1
  2. James Wedding

    Joe Sutphin Guest

    Change this line

    Private Sub MakeLists(MyObjs As AeccAlignmentStyles)

    Joe
     
    Joe Sutphin, Jul 21, 2004
    #2
  3. I would, but I'm passing different collections every time. The first case,
    I'm passing the AeccAlignmentStyles collection. The next case, I'm passing
    the AeccProfileViewStyles collection, etc. That's the bugger. I can do this
    by pulling the function back in and coding every case with the function
    internally, but that seems like a really inefficient way to do it.

    BTW, I had your 2000 VBA book on my desk this week. Still one of my faves.
    <g>

    --
    James Wedding, P.E.
    IT Manager
    Jones & Boyd, Inc.
    Dallas, TX
    XP/1 on P4-3.4/1G
    LDT2004&5+C3D

    Troll :a slang term for a person who posts messages without contributory
    content, simply intended to incite conflict. http://wikipedia.com
     
    James Wedding, Jul 21, 2004
    #3
  4. If they are actual Collection objects, try 'As Collection'.
     
    Frank Oquendo, Jul 21, 2004
    #4
  5. I tried that as well. :-( Same error message about Argument not optional,
    and it highlights the MyStyles portion of the MakeLists(MyStyles) line.

    --
    James Wedding, P.E.
    IT Manager
    Jones & Boyd, Inc.
    Dallas, TX
    XP/1 on P4-3.4/1G
    LDT2004&5+C3D

    Troll :a slang term for a person who posts messages without contributory
    content, simply intended to incite conflict. http://wikipedia.com
     
    James Wedding, Jul 21, 2004
    #5
  6. Just for grins, try 'Call MakeLists(MyStyle)' or 'MakeLists MyStyle'.

    BTW, what product are you using? Can you send me the TLB that contains
    the description of AeccAlignmentStyles? I'm assuming MyDwg is something
    other than an AcadDocument?
     
    Frank Oquendo, Jul 21, 2004
    #6
  7. Have you tried using "Private Sub MakeLists(ByRef MyObjs As Object)"
    instead ??
     
    Jorge Jimenez, Jul 21, 2004
    #7
  8. I'm running this in the preview version of Civil3D. MyDwg is dimd as an
    AeccDocument, not just a autocad doc.
    From the checking module:

    How strange. Using the Makelists MyStyles worked. Why wouldn't the argument
    be in () like I expected? Here's what finally worked:

    Private Sub StyleTypeComboBox_Change()
    Me.Style1ComboBox.Clear
    Me.Style2ComboBox.Clear
    Dim StyleList() As Variant
    Select Case Me.StyleTypeComboBox.value
    Case Is = "Alignment"
    Dim MyStyles As AeccAlignmentStyles
    Set MyStyles = MyDwg.AlignmentStyles
    MyStylesLists MyStyles

    'MyStlyesLists MyStyles
    Case "Alignment: Label: Curve"
    'Other cases here
    End Select
    End Sub

    Private Sub MyStylesLists(ByVal MyObjs As Object)
    Dim StyleObj As Object
    Dim j, k As Integer
    j = MyObjs.Count
    ReDim StyleList(0 To j - 1)
    j = 0
    For Each StyleObj In MyObjs
    StyleList(j) = StyleObj.Name
    j = j + 1
    Next StyleObj
    Style1ComboBox.List = BubbleSort(StyleList)
    Style2ComboBox.List = BubbleSort(StyleList)
    'End If
    End Sub




    --
    James Wedding, P.E.
    IT Manager
    Jones & Boyd, Inc.
    Dallas, TX
    XP/1 on P4-3.4/1G
    LDT2004&5+C3D

    Troll :a slang term for a person who posts messages without contributory
    content, simply intended to incite conflict. http://wikipedia.com
     
    James Wedding, Jul 21, 2004
    #8
  9. You normally use the parens only when calling a function that will return a
    value/object that you want to use. e.g.:

    MyVar = MyFunc(myArg)

    if you wanted to use the same function but didn't need/want the return
    value:

    MyFunc myArg


    --
    R. Robert Bell


    I'm running this in the preview version of Civil3D. MyDwg is dimd as an
    AeccDocument, not just a autocad doc.
    From the checking module:

    How strange. Using the Makelists MyStyles worked. Why wouldn't the argument
    be in () like I expected? Here's what finally worked:
     
    R. Robert Bell, Jul 21, 2004
    #9
  10. James Wedding

    MP Guest

    since it's a sub, rather than a function, you don't use the parens

    a function returns a value, goes on the right side of an =, and the args
    must be in parens
    eg:
    Style1ComboBox.List = BubbleSort(StyleList)
     
    MP, Jul 21, 2004
    #10
  11. James Wedding

    MP Guest

    ok I learned something there, didn't know you could do that
    since I always use the values returned by my functions i never tried that
    guess if i didn't want a return I'd have just made a sub

    can you give an example of a function whose return you might not need?
     
    MP, Jul 21, 2004
    #11
  12. Umm... how about a function that returns True for success, but you don't
    need to check for that in some cases?

    --
    R. Robert Bell


    ok I learned something there, didn't know you could do that
    since I always use the values returned by my functions i never tried that
    guess if i didn't want a return I'd have just made a sub

    can you give an example of a function whose return you might not need?
     
    R. Robert Bell, Jul 21, 2004
    #12
  13. James Wedding

    AKS Guest

    For one thing a Function is hidden from the user unlike a Sub that
    might show up in the Macros dialog and be run by an inquisitive user.

    One example might be a function that returns the success status of a
    particular process. Say the process is AddItemToList that does just
    that but also returns whether or not the item was added - not if the
    item was already in the list or the index number of where it uccurs in
    the list. You might set up the function that way in the beginning
    knowing that you may or may not be interested in the returned value.
     
    AKS, Jul 21, 2004
    #13
  14. James Wedding

    MP Guest

    right, I get the theoretical idea, I guess I just cant' think outside my own
    box to
    imagine why i wouldn't want to check the value in actual usage if i designed
    the function to return the value in the first place.
    i suppose...
    Function MakeLine(pt1 pt2) as AcadLine or object or whatever
    Set MakeLine = ...make a line object...
    End function

    Sub Test()
    dim stuff...

    Set oLine = MakeLine (vp1, vp2)
    oLine.Layer = .blah blah
    etc

    MakeLine vp3, vp4
    ...don't care what layer etc ...

    End sub

    anyway, thanks again for pointing out something I hadn't thought of

    now maybe I'll come up with all kind of ways to ignore my return values!
    :)
     
    MP, Jul 21, 2004
    #14
  15. James Wedding

    Joe Sutphin Guest

    Anytime you create an AutoCAD object [line, circle, etc.] the AddXXX
    function is returning an object of that specific type.

    ThisDrawing.ModelSpace.AddCircle Center, Radius

    This would return an AcadCircle object. Most of the time (but not
    necessarily always) storing the AcadCircle object in an appropriate object
    variable is not necessary [so the call would be just like it is shown
    above].

    However, if you wish to do something with the returned object, you must
    first assign it to an appropriately typed object variable like the following
    example.

    Dim oCircle As AcadCircle

    Set oCircle = ThisDrawing.ModelSpace.AddCircle(Center, Radius)

    Then you would use the oCircle object variable to change properties of that
    entity you just created. Does that help?

    Joe
    --

     
    Joe Sutphin, Jul 21, 2004
    #15
  16. James Wedding

    Joe Sutphin Guest

    Then I believe what you're going to have to do is inside the receiving
    function, figure out it's exact type and cast the object variable to that
    type similiar to creating a selection set of a bunch of different entities
    and figuring out which ones are BlockRefs for example and casting them to
    that object type.

    Joe
     
    Joe Sutphin, Jul 21, 2004
    #16
  17. Much clearer explanation Joe! ;^)
     
    R. Robert Bell, Jul 21, 2004
    #17
  18. James Wedding

    MP Guest

    right, just like my previous example
    I was just saying that my habit is to use the object returned - just a
    stylistic thing i guess

    I just work the opposite is all. Most of the time i do want to have control
    of the just added circle, at the minimum to put it on the correct layer etc.

    Thanks as always for the input.
    Mark
     
    MP, Jul 22, 2004
    #18
  19. James Wedding

    wivory Guest

    Another example: Ever use the MsgBox function? This can have a complex choice of return values, but sometimes you just want to display a message!

    Code:
    If MsgBox("Do you want to continue?", vbYesNo) = vbNo Then Exit Sub
    MsgBox "Okay, let's keep going!"
    
    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jul 22, 2004
    #19
  20. James Wedding

    MP Guest

    excellent example!
    Now there's a function that I don't even think of as being a function cause
    I have only used it to display debug info
    !!!
    :)

    choice of return values, but sometimes you just want to display a message!
     
    MP, Jul 22, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.