Solved

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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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