tags:

views:

386

answers:

3

I'm trying to write a subroutine in access 2003 that removes all quote characters from strings in an array. The subroutine removes the quotes successfully in the routine itself, but not when the program returns to the passing function. I'm very confused, as it is done ByRef.

How it is called:

Call removeQuotes(wbs_numbers())

and the subroutine itself:

'goes through a string array and removes quotes from each element in the array'
Sub removeQuotes(ByRef string_array() As String)
    For Each element In string_array()
    'chr(34) is quotation character. visual basic does not have escape characters.'
    element = Replace$(element, Chr(34), "")
    Next
End Sub

Can someone please explain what I am doing wrong? I would love you forever!

+10  A: 

Your array may be by reference, but element isn't. Iterate by index, and set the string back into the array once you've manipulated it.

David M
Once I specified the exact array index in the assignment statement, everything worked perfectly. Thank you!!!
You're welcome.
David M
+3  A: 

You are creating new variable "element" and do not store it back in string_array, so it is not changing.

Roman Kagan
+2  A: 

My VB is a little rusty but a quick google search turned up something like this:

Dim i As Integer
For i = LBound(string_array) To UBound(string_array)
   string_array(i) = Replace$(string_array(i), Chr(34), "")
Next
Jesse
Obviously, i needs to be declared somewhere. Integer is usually sufficient.
David-W-Fenton
Thanks...fixed it.
Jesse