Solved

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

Posted on 2013-01-29
2
208 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
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
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
Comment Utility
I will look at doing that if I cannot find a resultion to direct translate.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now