S
Saga
Hello all,
I am reading 3 strings from a DB table. I need to apply the
same process to all three strings, so I figured that I would use
a for loop. To make the loop easier to handle I am going to
put the three strings into an array so I can loop through each
one, something like this:
dim sArr() as string
redim sArr(0)
sArr(0) = string 1
redim preserve sArr(1)
sArr(1) = string 2
redim preserve sArr(2)
sArr(2) = string 3
for each sItem as string in array
'process here
next
That seems simple enough, except that any one of the
strings might be empty. I could validate this within the loop:
for each sItem as string in array
if sItem.Length > 0 then
'process here
end if
next
Or I can create the array with only items that are not empty.
This method now needs more logic:
if string 1 <> "" then
redim sArr(0)
sArr(0) = string 1
end if
if string 2 <> "" then
redim preserve sArr(sArr.getupperbound(0) + 1)
sArr(sArr.getupperbound(0)) = string 2
end if
Same with string 3.
Is this the best way to do this? Any orientation or
references are welcomed! Thanks for your help. Saga
I am reading 3 strings from a DB table. I need to apply the
same process to all three strings, so I figured that I would use
a for loop. To make the loop easier to handle I am going to
put the three strings into an array so I can loop through each
one, something like this:
dim sArr() as string
redim sArr(0)
sArr(0) = string 1
redim preserve sArr(1)
sArr(1) = string 2
redim preserve sArr(2)
sArr(2) = string 3
for each sItem as string in array
'process here
next
That seems simple enough, except that any one of the
strings might be empty. I could validate this within the loop:
for each sItem as string in array
if sItem.Length > 0 then
'process here
end if
next
Or I can create the array with only items that are not empty.
This method now needs more logic:
if string 1 <> "" then
redim sArr(0)
sArr(0) = string 1
end if
if string 2 <> "" then
redim preserve sArr(sArr.getupperbound(0) + 1)
sArr(sArr.getupperbound(0)) = string 2
end if
Same with string 3.
Is this the best way to do this? Any orientation or
references are welcomed! Thanks for your help. Saga