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!

write from one array to another

Status
Not open for further replies.

garethn

Programmer
Jul 3, 2001
12
GB
how do i write from one array in vb to another.
I have blanks in my first array and want to exclude these from my grid.
 
I don't see where the problem is here.
All that you need to know is the relevant index for each one
and simply set one to the other like
array1(index1) = array2(index2)
nothing fancy
 
I assume blanks are the problem. Say array1 has source data and array2 is for output without the blank records.
size array1 and 2 as same
Code:
j = 1
for i = 1 to ubound(array1)
if array1(valuex) <> &quot;&quot; then
array2(j) = array1(i)
j = j+ 1
next
at the end the array2 will have less values set than array1
ie j will be less than i. infact i-j= number of blank values in array1
luck!

 
still cant reomve blanks from an array

i have this code that creates an array which writes to a grid.When it populates the gris there are blanks in between the totals(these are the records that make up the totals)
I need to shuffle the grid or array up to remove the blanks....

aryProductWasteDetails.ReDim 0,recordset.RecordCount - 1, 0, 3

aryProductWasteDetails2.ReDim 0, 3, 0, 3

intloop = 0

Do While rstwastedetailsbylineproducttypearea.EOF = False

' If IsNull(rstwastedetailsbylineproducttypearea!wastetypeid) Then wastetypeid = &quot;&quot; Else wastetypeid = RTrim(rstwastedetailsbylineproducttypearea!wastetypeid)
If IsNull(rstwastedetailsbylineproducttypearea!ProductID) Then ProductID = &quot;&quot; Else ProductID = RTrim(rstwastedetailsbylineproducttypearea!ProductID)
If IsNull(rstwastedetailsbylineproducttypearea!ProductName) Then ProductName = &quot;&quot; Else ProductName = RTrim(rstwastedetailsbylineproducttypearea!ProductName)
If IsNull(rstwastedetailsbylineproducttypearea!kgs) Then kgs = &quot;&quot; Else kgs = RTrim(rstwastedetailsbylineproducttypearea!kgs)


rstwastedetailsbylineproducttypearea.MoveNext

If rstwastedetailsbylineproducttypearea.EOF = True Then

TotalProductWaste = TotalProductWaste + kgs
aryProductWasteDetails(intloop, 0) = ProductID
aryProductWasteDetails(intloop, 1) = ProductName
aryProductWasteDetails(intloop, 2) = TotalProductWaste

Else

If RTrim(rstwastedetailsbylineproducttypearea!ProductName) = ProductName Then

TotalProductWaste = TotalProductWaste + kgs

Else

aryProductWasteDetails(intloop, 0) = ProductID
aryProductWasteDetails(intloop, 1) = ProductName

TotalProductWaste = TotalProductWaste + kgs

aryProductWasteDetails(intloop, 2) = TotalProductWaste
TotalProductWaste = 0

End If

End If

intloop = intloop + 1

Loop

For r = 0 To aryProductWasteDetails.UpperBound(1)
If aryProductWasteDetails(r, 1) <> &quot;&quot; Then

aryProductWasteDetails2(r, 0) = aryProductWasteDetails(r, 0)
aryProductWasteDetails2(r, 1) = aryProductWasteDetails(r, 1)
aryProductWasteDetails2(r, 2) = aryProductWasteDetails(r, 2)

End If
Next r

TDBGrid1.Array = aryProductWasteDetails
TDBGrid1.ReBind
TotalProductWaste = 0

 
In the following loop, you are using the same row reference (r) for both arrays, which will not remove the blank entries

For r = 0 To aryProductWasteDetails.UpperBound(1)
If aryProductWasteDetails(r, 1) <> &quot;&quot; Then

aryProductWasteDetails2(r, 0) = aryProductWasteDetails(r, 0)
aryProductWasteDetails2(r, 1) = aryProductWasteDetails(r, 1)
aryProductWasteDetails2(r, 2) = aryProductWasteDetails(r, 2)

End If
Next r

I would suggest that you try the following

w = -1
For r = 0 To aryProductWasteDetails.UpperBound(1)
If Trim(aryProductWasteDetails(r, 1)) <> &quot;&quot; Then
w = w + 1
aryProductWasteDetails2(w, 0) = aryProductWasteDetails(r, 0)
aryProductWasteDetails2(w, 1) = aryProductWasteDetails(r, 1)
aryProductWasteDetails2(w, 2) = aryProductWasteDetails(r, 2)

End If
Next r
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top