Solved

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

Posted on 2013-01-29
2
209 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

23 Experts available now in Live!

Get 1:1 Help Now