|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Best Approach (psuedocode) for summing structure element valuesa values into a year/date column and an amount column. If the user enters multiple years then I need to sum the values. I thought this might be easier in VB so what I had in mind was: 1) Create two identical structures (type) of: Type TWSInfo thisYr As Integer thisValue As Single End type Dim TThisWS(rowcount) as TWSInfo Dim TThisSum(rowcount) As TWSInfo 2) Read in each Excel row into the structure 3) Sort the structure by Year 4) Loop the structure array comparing the next "thisYr" element to the previous "thisYr" element, and if the years match, summing the values 5 ) Storing the Yr and summed value in the structure TThisSum ====================================== Anyone have an easier / better way? Thanks David
Show quote
Hide quote
"David" <NoWh***@earthlink.net> wrote in message i don't know about easier or better, but one alternative is use a news:ukBb5ynPLHA.620@TK2MSFTNGP06.phx.gbl... > I'm dealing with an Excel worksheet which allow the user to enter > a values into a year/date column and an amount column. If the > user enters multiple years then I need to sum the values. > > I thought this might be easier in VB so what I had in mind was: > > 1) Create two identical structures (type) of: > > Type TWSInfo > thisYr As Integer > thisValue As Single > End type > > Dim TThisWS(rowcount) as TWSInfo > Dim TThisSum(rowcount) As TWSInfo > > 2) Read in each Excel row into the structure > > 3) Sort the structure by Year > > 4) Loop the structure array comparing the next "thisYr" element to the > previous "thisYr" element, and if the years match, summing the values > > 5 ) Storing the Yr and summed value in the structure TThisSum > > ====================================== > > Anyone have an easier / better way? > > Thanks > David > > > > > cSortedDictionary (Olaf Schmidt's dhRichClient3.dll) use year as key, (automatically sorted),...something like 'pseudocode Private mSumDict as cSortedDictionary Sub StoreYearSum(year as string, sum as single) if mSumDict is Nothing then set mSumDict = New cSortedDictionary if mSumDict.Exists (year) then mSumDict.Item(year) = mSumDict.Item(year) + sum else mSumDict.Add(year,sum) End if End Sub Sub ReadTotals() dim i as long for i = 0 to mSumDict.count -1 debug.print "Year", mSumDict.KeyByIndex(i), "Sum", mSumDict.ItemByIndex(i) next i End Sub fwiw mark Thanks for response mark.
Not familiar with (Olaf Schmidt's dhRichClient3.dll) but will search the net and check it out. David Show quoteHide quote "mp" <nospam@Thanks.com> wrote in message news:i4flh2$3mh$1@news.eternal-september.org... > > "David" <NoWh***@earthlink.net> wrote in message > news:ukBb5ynPLHA.620@TK2MSFTNGP06.phx.gbl... >> I'm dealing with an Excel worksheet which allow the user to enter >> a values into a year/date column and an amount column. If the >> user enters multiple years then I need to sum the values. >> >> I thought this might be easier in VB so what I had in mind was: >> >> 1) Create two identical structures (type) of: >> >> Type TWSInfo >> thisYr As Integer >> thisValue As Single >> End type >> >> Dim TThisWS(rowcount) as TWSInfo >> Dim TThisSum(rowcount) As TWSInfo >> >> 2) Read in each Excel row into the structure >> >> 3) Sort the structure by Year >> >> 4) Loop the structure array comparing the next "thisYr" element to the >> previous "thisYr" element, and if the years match, summing the values >> >> 5 ) Storing the Yr and summed value in the structure TThisSum >> >> ====================================== >> >> Anyone have an easier / better way? >> >> Thanks >> David >> >> >> >> >> > > i don't know about easier or better, but one alternative is use a > cSortedDictionary (Olaf Schmidt's dhRichClient3.dll) > use year as key, (automatically sorted),...something like > 'pseudocode > Private mSumDict as cSortedDictionary > > Sub StoreYearSum(year as string, sum as single) > if mSumDict is Nothing then set mSumDict = New cSortedDictionary > if mSumDict.Exists (year) then > mSumDict.Item(year) = mSumDict.Item(year) + sum > else > mSumDict.Add(year,sum) > End if > End Sub > > Sub ReadTotals() > dim i as long > for i = 0 to mSumDict.count -1 > debug.print "Year", mSumDict.KeyByIndex(i), "Sum", > mSumDict.ItemByIndex(i) > next i > End Sub > > fwiw > mark >
http://www.thecommon.net/2.html
to download olafs' dlls the archives from this group will also have some previous references/questions/answers Show quoteHide quote "David" <NoWh***@earthlink.net> wrote in message news:uKXRBnuPLHA.620@TK2MSFTNGP06.phx.gbl... > Thanks for response mark. > > Not familiar with (Olaf Schmidt's dhRichClient3.dll) > but will search the net and check it out. > > David > > > > "mp" <nospam@Thanks.com> wrote in message > news:i4flh2$3mh$1@news.eternal-september.org... >> >> "David" <NoWh***@earthlink.net> wrote in message >> news:ukBb5ynPLHA.620@TK2MSFTNGP06.phx.gbl... >>> I'm dealing with an Excel worksheet which allow the user to enter >>> a values into a year/date column and an amount column. If the >>> user enters multiple years then I need to sum the values. >>> >>> I thought this might be easier in VB so what I had in mind was: >>> >>> 1) Create two identical structures (type) of: >>> >>> Type TWSInfo >>> thisYr As Integer >>> thisValue As Single >>> End type >>> >>> Dim TThisWS(rowcount) as TWSInfo >>> Dim TThisSum(rowcount) As TWSInfo >>> >>> 2) Read in each Excel row into the structure >>> >>> 3) Sort the structure by Year >>> >>> 4) Loop the structure array comparing the next "thisYr" element to the >>> previous "thisYr" element, and if the years match, summing the >>> values >>> >>> 5 ) Storing the Yr and summed value in the structure TThisSum >>> >>> ====================================== >>> >>> Anyone have an easier / better way? >>> >>> Thanks >>> David >>> >>> >>> >>> >>> >> >> i don't know about easier or better, but one alternative is use a >> cSortedDictionary (Olaf Schmidt's dhRichClient3.dll) >> use year as key, (automatically sorted),...something like >> 'pseudocode >> Private mSumDict as cSortedDictionary >> >> Sub StoreYearSum(year as string, sum as single) >> if mSumDict is Nothing then set mSumDict = New cSortedDictionary >> if mSumDict.Exists (year) then >> mSumDict.Item(year) = mSumDict.Item(year) + sum >> else >> mSumDict.Add(year,sum) >> End if >> End Sub >> >> Sub ReadTotals() >> dim i as long >> for i = 0 to mSumDict.count -1 >> debug.print "Year", mSumDict.KeyByIndex(i), "Sum", >> mSumDict.ItemByIndex(i) >> next i >> End Sub >> >> fwiw >> mark >> > > Thanks mp -- found it.
Don't really like using someones dll where I don't have source. But nice to know its available. Consider this thread closed. Have a nice day. David Show quoteHide quote "mp" <nospam@Thanks.com> wrote in message news:i4hdf1$rii$1@news.eternal-september.org... > http://www.thecommon.net/2.html > to download olafs' dlls > the archives from this group will also have some previous > references/questions/answers > > "David" <NoWh***@earthlink.net> wrote in message > news:uKXRBnuPLHA.620@TK2MSFTNGP06.phx.gbl... >> Thanks for response mark. >> >> Not familiar with (Olaf Schmidt's dhRichClient3.dll) >> but will search the net and check it out. >> >> David >> >> >> >> "mp" <nospam@Thanks.com> wrote in message >> news:i4flh2$3mh$1@news.eternal-september.org... >>> >>> "David" <NoWh***@earthlink.net> wrote in message >>> news:ukBb5ynPLHA.620@TK2MSFTNGP06.phx.gbl... >>>> I'm dealing with an Excel worksheet which allow the user to enter >>>> a values into a year/date column and an amount column. If the >>>> user enters multiple years then I need to sum the values. >>>> >>>> I thought this might be easier in VB so what I had in mind was: >>>> >>>> 1) Create two identical structures (type) of: >>>> >>>> Type TWSInfo >>>> thisYr As Integer >>>> thisValue As Single >>>> End type >>>> >>>> Dim TThisWS(rowcount) as TWSInfo >>>> Dim TThisSum(rowcount) As TWSInfo >>>> >>>> 2) Read in each Excel row into the structure >>>> >>>> 3) Sort the structure by Year >>>> >>>> 4) Loop the structure array comparing the next "thisYr" element to the >>>> previous "thisYr" element, and if the years match, summing the >>>> values >>>> >>>> 5 ) Storing the Yr and summed value in the structure TThisSum >>>> >>>> ====================================== >>>> >>>> Anyone have an easier / better way? >>>> >>>> Thanks >>>> David >>>> >>>> >>>> >>>> >>>> >>> >>> i don't know about easier or better, but one alternative is use a >>> cSortedDictionary (Olaf Schmidt's dhRichClient3.dll) >>> use year as key, (automatically sorted),...something like >>> 'pseudocode >>> Private mSumDict as cSortedDictionary >>> >>> Sub StoreYearSum(year as string, sum as single) >>> if mSumDict is Nothing then set mSumDict = New cSortedDictionary >>> if mSumDict.Exists (year) then >>> mSumDict.Item(year) = mSumDict.Item(year) + sum >>> else >>> mSumDict.Add(year,sum) >>> End if >>> End Sub >>> >>> Sub ReadTotals() >>> dim i as long >>> for i = 0 to mSumDict.count -1 >>> debug.print "Year", mSumDict.KeyByIndex(i), "Sum", >>> mSumDict.ItemByIndex(i) >>> next i >>> End Sub >>> >>> fwiw >>> mark >>> >> >> > >
GDI+ and resizing a PictureBox
KBasic Re: How to get the File Properties Latest VB6 Cumulative Update? .NUT Fail Microsoft may back off of .NET languages .Net slipped itself in while I wasn't looking! Specify DLL version when using mc.exe, rc.exe and/or link.exe Running more then one Functions at once, HOW? Re: Problem with Direct Sound / VB6 |
|||||||||||||||||||||||