So if I have some arrays (basically, a bunch of data pulled from a few different database tables), simplified:
IdProduct(1) = 359
sProduct(1)="Garage Sale"
IdProduct(2) = 368
sProduct(2) = "Concert"
IdProduct(3) = 399
sProduct(3) = "Wedding"
Created from different read of the database, so the array order is different:
[NOTE I'm not "merely joining" tables in my query because then I get duplicate data returned, since every product has multiple dates]
IdDateBeginProduct(1) = 368
dDateBegin(1) = "1/3/2017"
dDateEnd(1) = "1/3/2017"
IdDateBeginProduct(2) = 359
dDateBegin(2) = "1/19/2017"
dDateEnd(2) = "1/20/2017"
IdDateBeginProduct(3) = 399
dDateBegin(3) = "2/5/2017"
dDateEnd(3) = "2/5/2017"
OK so what I'm looking at is that I'm looking through the products, and FOR EACH PRODUCT, I want to search through the date arrays to find begin and end dates, based on the Product ID:
So... THAT seems like a cumbersome way to do it.
Is there a way to index or otherwise search through arrays?
Or if I use Types, would that make it more efficient?
IdProduct(1) = 359
sProduct(1)="Garage Sale"
IdProduct(2) = 368
sProduct(2) = "Concert"
IdProduct(3) = 399
sProduct(3) = "Wedding"
Created from different read of the database, so the array order is different:
[NOTE I'm not "merely joining" tables in my query because then I get duplicate data returned, since every product has multiple dates]
IdDateBeginProduct(1) = 368
dDateBegin(1) = "1/3/2017"
dDateEnd(1) = "1/3/2017"
IdDateBeginProduct(2) = 359
dDateBegin(2) = "1/19/2017"
dDateEnd(2) = "1/20/2017"
IdDateBeginProduct(3) = 399
dDateBegin(3) = "2/5/2017"
dDateEnd(3) = "2/5/2017"
OK so what I'm looking at is that I'm looking through the products, and FOR EACH PRODUCT, I want to search through the date arrays to find begin and end dates, based on the Product ID:
B4X:
for i = 0 to IdProductID.length
IdProduct=IdProduct(i)
for x = 0 to IDDateBeginProduct.length
if (IdDateBeginProduct(x)=IDProduct) then
iThisOne=x
exit
end if
next
log(sProduct(i) & CRLF)
log(dDateBegin(iThisOne) & CRLF)
log(dDateEnd(iThisOne) & CRLF)
next
So... THAT seems like a cumbersome way to do it.
Is there a way to index or otherwise search through arrays?
Or if I use Types, would that make it more efficient?
Last edited: