-
Oct 30th, 2013, 02:19 PM
#1
Thread Starter
Member
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...
-
Oct 30th, 2013, 02:22 PM
#2
Thread Starter
Member
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.
-
Oct 30th, 2013, 02:26 PM
#3
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
-
Oct 30th, 2013, 02:36 PM
#4
Thread Starter
Member
Re: stepping backwards through array elements, passing values to function
Yes, I should get used to looking there, thanks for pointing it out.
-
Oct 31st, 2013, 01:47 AM
#5
Re: stepping backwards through array elements, passing values to function
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
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.
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.
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)
-
Oct 31st, 2013, 05:23 AM
#6
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|