Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Algorithm Problem
Hi
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.94 ,,SBR_3_Ammonia,01246,0.11,,SBR_4_Ammonia,01246,0. 01,,, 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 Lets say it is monday. The 0 indicates monday so I would like to check through the records collecting the values which have a flag for this day. All the records have a 0 so the string outut would look like - SBR_1_Ammonia,01246,0.15,,SBR_2_Ammonia,01246,0.94 ,,SBR_3_Ammonia,01246,0.11,,SBR_4_Ammonia,01246,0. 01,,, 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.01 ,,, Thanks for your assistance with this. I want to do some other things to it aswell but one step at a time. Rob |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Algorithm Problem
Thanks Harlan,
Thats great. I dont understand how you did it though. I can handle more basic code but how do you find good information on how to write that sort of stuff? Rob |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Algorithm Problem
Rob Hargreaves wrote...
.... I can handle more basic code but how do you find good information on how to write that sort of stuff? .... Reading general programming books and just writing code are the best ways to learn how to write code. Books focussed on VBA are unlikely to be much use except as references. If you're looking for book recommendations, my favorites are a bit old (but still excellent texts): Jon Bentley's two Programming Pearls books and Kernighan and Plaugher's The Elements of Programming Style. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Algorithm Problem
In article .com,
says... texts): Jon Bentley's two Programming Pearls books and Kernighan and Plaugher's The Elements of Programming Style. Don't know about Bentley's books but Elements of Programming Style should be a mandated prerequisite for anyone aspiring to write any kind of code. A bit dated maybe but still a must read. -- Regards, Tushar Mehta www.tushar-mehta.com Excel, PowerPoint, and VBA add-ins, tutorials Custom MS Office productivity solutions |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Algorithm Challenge | Excel Programming | |||
algorithm creation | Excel Programming | |||
can't find problem with permutation algorithm | Excel Programming | |||
help with algorithm | Excel Programming | |||
Need help with algorithm | Excel Programming |