Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - need to convert this code to sql server in vb6

Status
Not open for further replies.

tc3596

Technical User
Mar 16, 2001
283
Here is my sub...

Public Sub CompileReport()
Dim PrintFlag As Boolean
Dim OnChange$, OpenAmount As Double
Dim DateFlag As Boolean, InvoiceNo$
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Call CreateTemp
Set AccessDb = OpenDatabase(ReportPath$ & "oeslscom.mdb")
Set OESLSCOM = AccessDb.OpenRecordset("OESLSCOM", dbOpenTable)

PrintFlag = False
If txtSalesNo1 = "All" Then
SalesmanNo1$ = "000"
SalesmanNo2$ = "zzz"
Else
SalesmanNo1$ = txtSalesNo1
SalesmanNo2$ = txtSalesNo2
End If

DocumentDate1$ = ConvertDateTime(txtInvoiceDate1, "DS")
DocumentDate2$ = ConvertDateTime(txtInvoiceDate2, "DS")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
KEY_ARO$ = Space$(255)
AroStatus = BTRCALL(BGETFIRST, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)
Do Until AroStatus <> 0
If OnChange$ <> REC_ARO.AR_OPN_CUS_NO & REC_ARO.AR_OPN_APPLY_TO Then
OpenAmount = 0
InvoiceNo$ = ""
DateFlag = False
OnChange$ = REC_ARO.AR_OPN_CUS_NO & REC_ARO.AR_OPN_APPLY_TO
End If

OpenAmount = OpenAmount + (Comp3ToVariant(REC_ARO.AR_OPN_AMT1, 8, 2) + Comp3ToVariant(REC_ARO.AR_OPN_AMT2, 8, 2))
OpenAmount = Format$(OpenAmount, "0.00")

If (REC_ARO.AR_OPN_DOC_TP = "C" Or REC_ARO.AR_OPN_DOC_TP = "P") Then
If REC_ARO.AR_OPN_DOC_DT >= DocumentDate1$ And REC_ARO.AR_OPN_DOC_DT <= DocumentDate2$ Then
DateFlag = True
End If
End If

txtStatus = KEY_ARO$
DoEvents
AroStatus = BTRCALL(BGETNEXT, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If AroStatus <> 0 Or OnChange$ <> REC_ARO.AR_OPN_CUS_NO & REC_ARO.AR_OPN_APPLY_TO Then
If DateFlag And OpenAmount = 0 Then
KEY_ARO$ = OnChange$ & Space$(100)
AroStatus = BTRCALL(BGETGREATEROREQUAL, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)
Do Until AroStatus <> 0 Or Mid$(KEY_ARO$, 1, 20) > OnChange$
InvoiceNo$ = ""
If REC_ARO.AR_OPN_DOC_TP = "I" Then InvoiceNo$ = REC_ARO.AR_OPN_DOC_NO
If REC_ARO.AR_OPN_DOC_TP = "C" Then InvoiceNo$ = REC_ARO.AR_OPN_DOC_NO

Call WriteToTemp(InvoiceNo$, 1)
AroStatus = BTRCALL(BGETNEXT, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)
Loop
End If
End If
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
End Sub

I was wondering if anyone could translate this for me....

AROPNFIL is the table
REC_ARO appears to be the recordset

I am thinking of creating an ADODB recordset...and looping thruough. I am confused about all the GetNext and BGETGREATEROREQUAL calls in the middle of the loop. How is it sorting the data?

Thanks for your help.
 
What are you trying to do?
THe BGETNEXT and BGETGREATEROREQUAL are operation codes in Btrieve. It's a different method of accessing data. It's not SQL.

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
I understand it's not SQL. My client is moving from Btrieve to SQL Server. Typically, in sql server, I would create a recordset using ADO and begin looping through the data.

It appears that I could take..

AroStatus = BTRCALL(BGETFIRST, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)
statement and do this....


loop through this recordset...
rst.open "select * from aropnfil", conn, ..., ...

the first record i would....

Do Until AroStatus <> 0
If OnChange$ <> REC_ARO.AR_OPN_CUS_NO & REC_ARO.AR_OPN_APPLY_TO Then
OpenAmount = 0
InvoiceNo$ = ""
DateFlag = False
OnChange$ = REC_ARO.AR_OPN_CUS_NO & REC_ARO.AR_OPN_APPLY_TO
End If

OpenAmount = OpenAmount + (Comp3ToVariant(REC_ARO.AR_OPN_AMT1, 8, 2) + Comp3ToVariant(REC_ARO.AR_OPN_AMT2, 8, 2))
OpenAmount = Format$(OpenAmount, "0.00")

If (REC_ARO.AR_OPN_DOC_TP = "C" Or REC_ARO.AR_OPN_DOC_TP = "P") Then
If REC_ARO.AR_OPN_DOC_DT >= DocumentDate1$ And REC_ARO.AR_OPN_DOC_DT <= DocumentDate2$ Then
DateFlag = True
End If
End If

txtStatus = KEY_ARO$
DoEvents


...then, this stuff comes in....

AroStatus = BTRCALL(BGETNEXT, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)

in sql i would say...

rst.movenext (go to the next record)...is the above saying the same thing?

..the code continues...

If AroStatus <> 0 Or OnChange$ <> REC_ARO.AR_OPN_CUS_NO & REC_ARO.AR_OPN_APPLY_TO Then
If DateFlag And OpenAmount = 0 Then
KEY_ARO$ = OnChange$ & Space$(100)
AroStatus = BTRCALL(BGETGREATEROREQUAL, AROPNFIL$, REC_ARO, BUF_ARO, ByVal KEY_ARO$, KEY_LEN, 1)


what is BGETGREATEROREQUAL this doing....

getgreater or equal to what?..........

then the loop at the bottom doesn't make sense as we've already done a few get next record statements.

very confusing...






 
Converting from Btrieve to SQL Server is not a trivial task. It's not simply a matter of converting one operation to another. You'd actually be rewriting whole sections. For example, a BGETFIRST / BGETNEXT loop would be a "recordset". With SQL, you get a result set when you issue a SELECT. With Btrieve, each operation affects at most one record (with a couple of exceptions).
The BGETGREATEROREQUAL is a positioning operation. It takes a value and searches the specified key for that value and finds the first value that is greater than or equal to that value. In your case, it's looking for the value of KEY_ARO$.



Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top