StrataFrame Forum

Can not Get Loop to Work

http://forum.strataframe.net/Topic29620.aspx

By Terry Bottorff - 2/26/2011

What am I missing? I tried the following code:

        'For Each lobo As ResultsPerfsChecksRoughStockBO In Me.ResultsPerfsChecksRoughStockBO1.GetEnumerable
        '    cword = DecimalToText.ConvertDecimalToText(Me.ResultsPerfsChecksRoughStockBO1.netcheck)
        '    Me.ResultsPerfsChecksRoughStockBO1.amountinwords = cword
        '    y += 1
        'Next

        ' Could Not Get the Above to Work because it would only do the First Record. So I put the following in
        MessageBox.Show(Me.ResultsPerfsChecksRoughStockBO1.Sort)
        MessageBox.Show(Me.ResultsPerfsChecksRoughStockBO1.Filter)
        MessageBox.Show(Me.ResultsPerfsChecksRoughStockBO1.Count.ToString())

The First two messageboxes show nothing and the last one shows 10 which is correct. So I tried the following code and it only does the first record also?????

               If Me.ResultsPerfsChecksRoughStockBO1.MoveFirst() Then
            ' Loop Thru All Records Making Sure NetCheck is Correct and Getting Words for Netcheck
            
            Do
                nnet = Me.ResultsPerfsChecksRoughStockBO1.checkamt + Me.ResultsPerfsChecksRoughStockBO1.groundmoney -  Me.ResultsPerfsChecksRoughStockBO1.tax
                cword = DecimalToText.ConvertDecimalToText(Me.ResultsPerfsChecksRoughStockBO1.netcheck)
                Me.ResultsPerfsChecksRoughStockBO1.amountinwords = cword
                nnet = 0.0
            Loop While Me.ResultsPerfsChecksRoughStockBO1.MoveNext()
        End If

I just can not see the trees for the forest. I know it has to be something weird I am doing but I don't know what it is. Any help would be appreciated. TIA.
By Ivan George Borges - 2/26/2011

Hi Terry.

Try this one:

        For Each lobo As ResultsPerfsChecksRoughStockBO In Me.ResultsPerfsChecksRoughStockBO1.GetEnumerable
            cword = DecimalToText.ConvertDecimalToText(lobo.netcheck)
            lobo.amountinwords = cword
            y += 1
        Next


Notice you are dealing with the lobo instance created for the loop.
By Terry Bottorff - 2/26/2011

Sorry to say that did not work either????
By Edhy Rijo - 2/26/2011

Hi Terry,
Ivan's code is the correct way to handle the BO.GetEnumerable().
In your code I assume that the cword has been previously defined, but it is not really needed you can do it in a single line of code
lobo.amountinwords =  DecimalToText.ConvertDecimalToText(lobo.netcheck)

The only reason I have seen BO.GetEnumerable() going crazy is when you have a Sort or Filter and based on your original post those are cleared, so I suggest you debug the loop to see what may be happening.
By Terry Bottorff - 2/27/2011

Well an interesting thing happened. While trying to debug the above problem as Edhy recommended, since I have a DevExpress Grid on my form with a BBS I was just entering different values to see if I could find out why it did the first record and skipped all of the rest. Since I have such a few records I have always been entering data to the bottom of the grid. But this time I stopped entering about half way through the records, and in debugging I noticed it did the first record and skipped to the record that I left it on in the grid????????  I was floored. I still have no clue as to why that happens since I even reloaded my BO because I could not get the loop to work? 
But I put this statement in my code before the loop and it now seems to work great. 

Me.GridView1.MoveFirst()

I'm sure this might be logical but it seems strange to me since I did reload my BO.?
TIA.