Results 1 to 6 of 6

Thread: stepping backwards through array elements, passing values to function

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    stepping backwards through array elements, passing values to function

    I have a function that takes 2 elements of a string array as it's parameters. The function manipulates these and returns a modified version of both to their original indices. I need to send the current element's string value and the previous element's string value to the function:-

    ...(part of calling sub's code)...

    Drg (BArr(I), BArr(I-1
    Next I

    Join(BArr2, vbNewLine)

    End Sub
    ------------------------------------------------

    Private Function Drg (BArr(I), BArr(I-1))


    Is this the correct way to send and return the parameters? Or should they take new names in the function?
    Is it permissible to refer to array elements as "I" and "I-1" ? I'm not sure how else to achieve this if not.

    On a different note, if I refer to an integer variable in code that has not yet been assigned a value, will its value be 0?
    Lastly, I'm using " " as a delimiter for joining. Some elements will include spaces within their string values. Will this cause any problems?

    Hope its OK to ask so many questions in one go...

  2. #2

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    Re: stepping backwards through array elements, passing values to function

    I realize parentheses are missing, probably typos there too, this is a 'sketch' rather than finished code.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: stepping backwards through array elements, passing values to function

    The default value of an Integer is 0. (So, Yes, to your 2nd question).
    See:
    http://msdn.microsoft.com/en-us/libr.../06bkb8w2.aspx

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    Re: stepping backwards through array elements, passing values to function

    Yes, I should get used to looking there, thanks for pointing it out.

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: stepping backwards through array elements, passing values to function

    Quote Originally Posted by moorea21 View Post
    Is this the correct way to send and return the parameters? Or should they take new names in the function?
    Is it permissible to refer to array elements as "I" and "I-1" ? I'm not sure how else to achieve this if not.
    Any function, subroutine or property knows nothing about the names of the parameters passed to them. They only know about the data type, the number of arguments supplied and the order they are passed, except in the case of ParamArray parameters. So, you can choose any valid, sensible name for your procedure's arguments.

    Code:
    Private Function Drg(ByRef strParam1_InOut As String, ByRef strParam2_InOut As String) As Variant
    Quote Originally Posted by moorea21 View Post
    On a different note, if I refer to an integer variable in code that has not yet been assigned a value, will its value be 0?
    It was mentioned in the Erase statement what the default values of various data types are.

    Quote Originally Posted by moorea21 View Post
    Lastly, I'm using " " as a delimiter for joining. Some elements will include spaces within their string values. Will this cause any problems?
    Existing spaces are treated just like any other character. You can join 2 strings containing nothing but spaces using an arbitrary number of spaces and the resulting string will have the expected length. BTW, it isn't necessary to explicitly specify the space character as the delimiter because that is already the default delimiter used when you skip that optional parameter.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    Re: stepping backwards through array elements, passing values to function

    Thanks Bonnie, that's all as I thought. Hopefully today I'll get a chance to run the code, and see if the value I-1 for array elements passes OK.

Tags for this Thread

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