Solved

VB.Net - Conversion from VB6 to VB.Net Looping Translation

Posted on 2013-01-29
2
215 Views
Last Modified: 2013-02-04
Good Day Experts!

The end is in site for my little conversion project.  This is the last part of the code that has errors.  I just am not sure how the VB6 constructs are working here to follow a couple parts in the code.  

***tblRS is a detached “table” recordset populated in code above this block
***SQLrs2 is a recordset from a query farther up in the code
I just don’t understand looping on tblRS since once inside the Loop for SQLrs2
tblRS.Find is executed.  Also, I cannot follow the MoveNext, First and Last near
the bottom.  

Can you help translate?

Do Until tblRS.EOF = True
SQLrs2.MoveFirst
        Do Until SQLrs2.EOF = True
            tblRS.Find "[GL CODE]='" & SQLrs2("GL CODE") & "'"
            Debug.Print "[GL CODE]='" & SQLrs2("GL CODE") & "'"
            If tblRS.EOF = True Or tblRS.BOF = True Then
               Debug.Print "NOT FOUND ADDING " & SQLrs2("GL CODE")
               'Not found add new record...
               Dim fieldsArray1(2) As Variant
               fieldsArray1(0) = "GL CODE"
               fieldsArray1(1) = "TotalPaid"
               fieldsArray1(2) = "TotalWeight"
               Dim values1(2) As Variant
               values1(0) = SQLrs2("GL CODE")
               values1(1) = SQLrs2("TotalPaid")
               values1(2) = SQLrs2("TotalWeight")
               tblRS.AddNew fieldsArray1, values1
               tblRS.Update
            Else        
                'Add the total paid to the Original Query results
                tblRS("TotalPaid") = CDec(tblRS("TotalPaid").Value) + CDec(SQLrs2("TotalPaid").Value)
                tblRS("TotalWeight") = CDec(tblRS("TotalWeight").Value) + CDec(SQLrs2("TotalWeight").Value)
            End If
            SQLrs2.MoveNext
            tblRS.MoveFirst
        Loop
        tblRS.MoveLast
        tblRS.MoveNext
    Loop
0
Comment
Question by:Jimbo99999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38832426
I understand you do not want to rewrite this code but this code can be improved and simplified a lot by writing it the .NET way. It is basically looping through one table and if a record is found in other table then it updates fields and adds a record otherwise.
0
 

Author Closing Comment

by:Jimbo99999
ID: 38851200
I will look at doing that if I cannot find a resultion to direct translate.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question