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...
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.
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
Re: stepping backwards through array elements, passing values to function
Yes, I should get used to looking there, thanks for pointing it out.
Re: stepping backwards through array elements, passing values to function
Quote:
Originally Posted by
moorea21
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
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
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.
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.