excel - Simple VBA to inserting row at an increment -


it has been awhile since start use vba again.

i have 1 question regarding inserting row @ increment of "0.1"

the increment applies case when length > "0.1"

====================================================

when new row has been insert

write id , route_id , new begin_point, new end_point, new length (new end_point - new begin_point)

insert row until length < "0.1"

====================================================

please me out on or address me vba code done. specify question format desire answer below.

i appreciate help!

question

id | route_id | begin_point | end_point | length |

1105 | a_st | 1.166 | 1.271 | 0.105

99 | c_blvd | 0 | 0.08 | 0.08

24 | b_ave | 0.447 | 0.627 | 0.18

desired answer

id | route_id | begin_point | end_point | length |

1105 | a_st | 1.166 | 1.266 | 0.1

1105 | a_st | 1.266 | 1.271 | 0.005

99 | c_blvd | 0 | 0.08 | 0.08

24 | b_ave | 0.447 | 0.547 | 0.1

24 | b_ave | 0.547 | 0.627 | 0.08

since tagged question c++, i'm assuming want c++ language this.

let's start structure defines record:

struct record {     unsigned int id;     std::string  route_id;     double       begin_point;     double       end_point;     double       length; }; 

my understanding generate new segments until segments less or equal 0.1 in length.

for convenience, let's store records std::vector:

std::vector<record> table; 

let's assume variable entry read database (excel or mysql).

a while loop used create multiple segments:

record entry;  // input entry here. //... while (entry.length > 0.1) {   record segment = entry; // make copy generate new segment.   if (segment.length > 0.1)   {     segment.length = 0.1;     entry.length -= 0.1;     segment.end_point = segment.begin_point + segment.length;     entry.begin_point = segment.end_point;     table.push_back(segment);   } } table.push_back(entry); 

note: above code has not been thoroughly tested , provided concept purposes demonstrate possible algorithm.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -