We help IT Professionals succeed at work.

array problem

ray14
ray14 asked
on
Hi,

Please read the following code and modify it:

Private Sub command1_click()
Dim temp(3) As long
Dim YSA As Field
Dim SB As String , I as integer

Adodc1.Recordset.MoveFirst
For Each YSA In Adodc1.Recordset.Fields

If YSA.Value = SB And Not IsNull(YSA.Value) Then
For I = 1 To 3
temp(I) = YSA.Name
Next I
End If
Next YSA

Label1 = temp(1)
Label2 = temp(2)
Label3 = temp(3)
End Sub

I use Adodc1 to connect with Access 97 mdf which include a table containing SB three times in the first record in different fields names
I want to fill the array temp() by the fields names which contain SB
In the code above it gives me the last field name only which contains SB
Please I need your help to modify the code to let the array contains the 3 fields names not the last one only.

Thanx
Comment
Watch Question

BRONZE EXPERT

Commented:
here is the patch, if you will. I think you can get it in places.

Dim temp(1, 3) As long

REDIM PRESERVE temp(x + 1, 3)

temp( x, 1 ) = value
temp( x, 2 ) = value
temp( x, 3 ) = value


Commented:
Private Sub command1_click()
Sorry 4 being late

Dim temp(3) As long
Dim YSA As Field
Dim SB As String , I as integer

Adodc1.Recordset.MoveFirst
For Each YSA In Adodc1.Recordset.Fields

   If YSA.Value = SB And Not IsNull(YSA.Value) Then
      'For I = 1 To 3
      I=I+1  
      temp(I) = YSA.Name
      'Next I
   End If
Next YSA

Label1 = temp(1)
Label2 = temp(2)
Label3 = temp(3)
End Sub

Commented:
explanation

for each field    For next is started from beg.  this is a bug!!!!
Hope that helps

Explore More ContentExplore courses, solutions, and other research materials related to this topic.