The Do - Loop While BO.MoveNext does not cycle through all of the records


Author
Message
Jeff Pagley
Jeff Pagley
StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
 Hi SF Team,

Below is an example of some logic I am using in my app and found it was not cycling through all of the records.    Unless I execute the BO.MoveFirst() method before the do loop,  it does not cycle through all of the records .   Why do I have to execute the .MoveFirst method to use this logic?   Would it be better to use .GetEnumerable method of the BO instead?

Thanks Guys,

Jeff

 

Using lo As New DepartmentsBO

lo.FillDataTable("SELECT * FROM CMPRDepartments")

lo.MoveFirst()

Do

Debug.Print(count & " - Department = " & lo.DepartmentDescription)

Loop While lo.MoveNext

End Using


Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
That is correct, but you should really be using the GetEnumerable if you don't want to worry about the MoveFirst:

For Each bo As MyBO in MyBOInstance.GetEnumerable()
   '---
Next

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm not sure about why you have use MoveFirst(), but I've run into this before, on a freshly filled BO. In any case, GetEnumerable() is the better choice. It will cycle through all the rows and it makes sure the current index is restored when done.

Peter Jones
Peter Jones
Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)Advanced StrataFrame User (510 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Jeff,

We just use GetEnumerable once we found out about it and refactored all old code. Prior to that we did (without any problems):

    If BO.MoveFirst() Then
        Do


        Loop While BO.MoveNext()
    End If

This code is better as I believe your example will error if the BO is empty on the MoveFirst.

Cheers, Peter

Jeff Pagley
Jeff Pagley
StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)StrataFrame User (465 reputation)
Group: StrataFrame Users
Posts: 223, Visits: 893
Hi Peter,

You are absolutely right.  I am now to using GetEnumerable and I am refactoring all of the old code.

Thanks, Jeff

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search