Results 1 to 3 of 3

Thread: ByRef Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    2

    ByRef Error

    I am getting an error when trying to pass a Split directly to another function.

    This is the Add function - It is in a class module:
    Code:
    Public Sub Add(strItem As String)
        If Arr(0) <> "" Then
            'Redimension Array
            ReDim Preserve Arr(UBound(Arr) + 1)
        End If
        'Add channel to end of array
        Arr(UBound(Arr)) = strItem
    End Sub
    From another module, I want to do this:
    Code:
    TheBot.Prop_Controllers.Add Split(Parameter," ")(1)
    However, this gives me a ByRef error. I can fix this by doing this:
    Code:
    Dim mysplit As String
    mysplit = Split(Parameter, " ")(1)
    TheBot.Prop_Controllers.Add mysplit
    But seeing as I use that statement many times in the same module, I would rather not double my sourcecode size. Is there any way to get around this error without using a lot of extra code? Maybe a C-Style static cast?

    Any help would be appreciated!

    DocUK

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Try this:

    VB Code:
    1. 'This way will pass the result of the split as a string.
    2. TheBot.Prop_Controllers.Add cstr(Split(Parameter," ")(1))

    VB Code:
    1. 'Or change your procedure to accept the parameter ByVal like this:
    2.  
    3. Public Sub Add(ByVal strItem As String)
    4.     If Arr(0) <> "" Then
    5.         'Redimension Array
    6.         ReDim Preserve Arr(UBound(Arr) + 1)
    7.     End If
    8.     'Add channel to end of array
    9.     Arr(UBound(Arr)) = strItem
    10. End Sub

    Either method should fix you up. I'd Prefer the ByVal Option if it was me.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    2
    Thanks a ton!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width