View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default Algorithm Problem

Rob Hargreaves wrote...
I have a string which I would like to pass into my code

The string -

SBR_1_Ammonia,01246,0.15,,SBR_2_Ammonia,01246,0.9 4,,
SBR_3_Ammonia,01246,0.11,,SBR_4_Ammonia,01246,0.0 1,,,

Broken down this means Name ,WeekDay ,Previous Value

There are 4 records in the string each is separated by double commas, the
end of the string is found by three commas each piece of the record is
separated with a single comma

looking at the first record it is -

SBR_1_Ammonia - Name
01246 - Monday, Tuesday, Wednesday, Friday, Sunday - Weekdays to be
included.
0.15 - Previous Value

....
but suppose only the first and last records contained the 0 it would only
show

SBR_1_Ammonia,01246,0.15,,SBR_4_Ammonia,01246,0.0 1,,,

....

Just a parsing problem. Pass such strings through the
following function.


Function parser(s As String) As String
Dim t As String, n As Long
Dim a As Variant, b As Variant

t = Replace(s, ",,,", "")
t = Replace(t, ",,", Chr(28))
a = Split(t, Chr(28))

t = ""
For n = LBound(a) To UBound(a)
b = Split(a(n), ",")
If b(1) Like "*0*" Then t = t & ",," & a(n)
Erase b
Next n

Erase a

parser = Mid(t, 3) & ",,,"
End Function