|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
for each loop?
i dont have any of my books here at work, so i figured id ask here.
let me explain my situation, and go from there. i have two tables (lets call them t1 and t2) that have the same exact fields, just different data. i need to compare each field in t1 to each field in t2. then go back and compare each record in t2 to each record in t1. i was thinking a nested for loop (coming from a C++ background) but i remember something about a for each loop in vb? can you have a for each loop and have the lcv be the recordset? for example: for each recordSet in something? thanks alot! |
|
#2
|
||||
|
||||
|
yeah... there are two properties that you will want to use - recordcount and field... here's an abbreviated example
Code:
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
Dim otherrs As New ADODB.Recordset
Dim i As Integer
Dim j As Integer
For i = 0 To (rs.RecordCount - 1)
For j = 0 To (rs.Fields.Count - 1)
'Do field comparison here
rs.Fields(j) = otherrs.Fields(j)
Next j
'do record comparisons here
'then do
rs.MoveNext
otherrs.MoveNext
Next i
End Sub
|
|
#3
|
|||
|
|||
|
awesome... im not exactly sure that is what im looking for, but it is definetely a start. the recordcount property is going to be what ill use, more than likely. i think the code you wrote out, compares each field in each record. i only need to compare sku #s, one per record.... i can modify the code to get it to do what i want... thanks alot! looks like i dont need a for each loop!
|
|
#4
|
||||
|
||||
|
nope.. but you can use the fields() method with the zero-based index of the fields that you want to compare.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > for each loop? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|