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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For each step 2

Status
Not open for further replies.

crabback

Technical User
Jan 29, 2007
64
IE
Hey,

I have a For Each loop in my code that returns every book's details, from a category, into a table. The details of the book are displayed in a table:


I want to display the list in 2 columns on my page.
Is there a way to use the for each loop but only display every odd numbered book or even-numbered?
Or does anyone know a simpler way to achieve this?

Thanks


Crabback
 

how about using a simple Boolean variable and change it True / False on the fly....?
Code:
Dim blnShow As Boolean = False
For Each ....
   If blnShow Then
      [green]'your code here[/green]
      blnShow = Not(blnShow)
   End If

Would that work for you?


Have fun.

---- Andy
 

Oooops, move a line of code:
Code:
Dim blnShow As Boolean = False
For Each ....
   If blnShow Then
      'your code here
   End If
   [blue]blnShow = Not(blnShow)[/blue]


Have fun.

---- Andy
 
Thanks Andy!
Nice and simple :) of course!!!
I created a variable that contained an identity field (incrementing by 1) from one of the tables. Then used the Mod operator to find if it was odd or even:

Dim iMod As Integer = pRow("iOrder")
If iMod Mod 2 Then
..... left column code here
else
..... right column code here
End if

Nice. |Thanks

Crabback
 
hmmm... Just adding this for future references.
I realised the order I wanted to display may change. Also, if a book is deleted from the database the identity field would not be reliable. So, instead iMod variable was set to 1 within the For Each loop, incrementing each time the loop looped:
Dim iMod as integer
For Each item in collection
iMod += 1
If iMod Mod 2 Then
..... left column code here
else
..... right column code here
End if
Next



Crabback
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top