Repost from this AM - Bill? Others?

# Thread: Repost from this AM - Bill? Others?

1. Senior Member
Join Date
Dec 1969
Posts
1,843

## Repost from this AM - Bill? Others?

Check this out: <BR><BR>http://www.aspmessageboard.com/forum/asp.asp?M=576922&T=576922&F=20&P=1<BR><BR>I would love any general ideas / pointers... <BR><BR>I&#039;m convinced that I&#039;ll have to rewrite this, so before I do I want to have some solid ideas.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

.

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## *** SHANE *** see new msg in thread

.<BR>

4. Senior Member
Join Date
Dec 1969
Posts
1,843

## yea, I saw it....

just don&#039;t tell my boss that I wasted half a day :) <BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## I'm pretty amazed...

...that you got it to work in only half a day!<BR><BR>Wow.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
1,843

## Just for fun....

and since it will never actually be used now, look at the code. It gets ugly at points but it works:<BR><BR>&#060;%<BR><BR>Function SortArray(arrArray(),MultiSortCol)<BR> &#039;PASS IN ARRAY TO BE SORTED AND A COLUMN NUMBER (OR COMMA-DELIMITED LIST OF COLUMN NUMBERS) T0 S0RT ON<BR> &#039;EXAMPLE: CALL SORTARRAY(MyArray,"0,1,2,3")<BR> SortOrder = Split(MultiSortCol,",")<BR> <BR> For iiii = 0 to UBound(SortOrder)<BR> For i = UBound(arrArray,2) - 1 To 0 Step -1<BR> For ii= 0 to i<BR> If arrArray(SortOrder(iiii),ii) &#062; arrArray(SortOrder(iiii),ii+1) Then<BR> For iii = 0 to ubound(arrArray)<BR> Temp = arrArray(iii,ii+1)<BR> arrArray(iii,ii+1) = arrArray(iii,ii)<BR> arrArray(iii,ii) = Temp<BR> Next<BR> End If<BR> Next<BR> Next<BR> Next<BR> SortArray = arrArray<BR>End Function<BR><BR>Sub OrderOfOperations(Formula)<BR> &#039;PASS IN A FORMULA AND IT WILL DETERMINE THE ORDER OF OPERATIONS FOR THAT FORMULA USING DATA CONTAINED IN arrOPERATORS ARRAY<BR><BR> Dim arrOperators(1,3)<BR> arrOperators(0,0) = "*"<BR> arrOperators(1,0) = 1<BR> arrOperators(0,1) = "/"<BR> arrOperators(1,1) = 1<BR> arrOperators(0,2) = "+"<BR> arrOperators(1,2) = 2<BR> arrOperators(0,3) = "-"<BR> arrOperators(1,3) = 2<BR> <BR> ReDim arrOrder(2,50)<BR> <BR> LineCount = -1<BR> For i = 0 to ubound(arrOperators,2)<BR> Processed = False<BR> StartAt = 1<BR> Do While Processed = False<BR> TempLoc = Instr(StartAt, Formula, arrOperators(0,i))<BR> If TempLoc &#060;&#062; 0 Then<BR> StartAt = TempLoc+1<BR> LineCount = LineCount + 1<BR> arrOrder(0,LineCount) = arrOperators(0,i)<BR> arrOrder(1,LineCount) = arrOperators(1,i)<BR> arrOrder(2,LineCount) = TempLoc<BR> Else<BR> Processed = True<BR> End If<BR> Loop<BR> Next<BR> <BR> Redim Preserve arrOrder(2,LineCount)<BR> <BR> arrOrderOfOps = SortArray(arrOrder,"2,1")<BR>End Sub<BR><BR>Function EvaluateMath(Formula)<BR> &#039;PASS IN A FORMULA AND IT WILL EVALUATE IT BASED ON THE ORDER OF OPERATIONS COMMANDS IT RECEIVES FROM THE OrderOfOperations SUBROUTINE<BR> Call OrderOfOperations(Formula)<BR> <BR> &#039;Loop through order of operations<BR> For i = 0 to ubound(arrOrderOfOps,2)<BR> <BR> &#039;create a temp array<BR> arrTemp = split(Formula, arrOrderOfOps(0,i))<BR> <BR> &#039;we&#039;ll use the first two columns of the temp array to make our calculations. Split each of those columns into another temp array<BR> arrTempExpOne = Split(Trim(arrTemp(0))," ")<BR> arrTempExpTwo = Split(Trim(arrTemp(1))," ")<BR> <BR> Select Case arrOrderOfOps(0,i)<BR> &#039;based on the operation we&#039;re doing; take the last number from the first column and the first number from the second and calculate<BR> Case "*"<BR> Sum = cDBL(arrTempExpOne(ubound(arrTempExpOne))) * cDBL(arrTempExpTwo(0))<BR> Case "/"<BR> Sum = cDBL(arrTempExpOne(ubound(arrTempExpOne))) / cDBL(arrTempExpTwo(0))<BR> Case "+"<BR> Sum = cDBL(arrTempExpOne(ubound(arrTempExpOne))) + cDBL(arrTempExpTwo(0))<BR> Case "-"<BR> Sum = cDBL(arrTempExpOne(ubound(arrTempExpOne))) - cDBL(arrTempExpTwo(0))<BR> End Select<BR> <BR> &#039;Replace the last number in the first column with the sum, replace the first number in the second column with nothing thus eliminating the original figures<BR> arrTempExpOne(ubound(arrTempExpOne)) = Replace(arrTempExpOne(ubound(arrTempExpOne)),arrTe mpExpOne(ubound(arrTempExpOne)),Sum)<BR> arrTempExpTwo(0) = Replace(arrTempExpTwo(0),arrTempExpTwo(0),"")<BR> <BR> &#039;Replace the first two columns of arrTemp with the new data from above<BR> arrTemp(0) = Replace(arrTemp(0),arrTemp(0),join(arrTempExpOne)) <BR> arrTemp(1) = Replace(arrTemp(1),arrTemp(1),join(arrTempExpTwo)) <BR> <BR> &#039;Loop through the formula and put back any operators that were removed during the split() but were not evaluated this cycle<BR> For j = 2 to ubound(arrTemp)<BR> arrTemp(j) = arrOrderofOps(0,i) & " " & arrTemp(j)<BR> Next<BR> <BR> Formula = Join(arrTemp)<BR> <BR> Next<BR> EvaluateMath = Formula<BR>End Function<BR><BR><BR>Dim arrOrder<BR>Dim arrOrderOfOps<BR>Formula = " 27775 + 187587 + 1986986687657658795776086096 / 468498698686487479 * 554 + 1667 * 334 + 4 + 5 + 4 + 6 + 67 / 34 * 445 "<BR>Response.Write(EvaluateMath(Formula))<BR>

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Heh! Aren't you happy...

...though that it will now run *so* much faster? Won&#039;t your boss be happier?<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•