Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2006, 11:30 AM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listbox Conditional Iteration

Hi,

    I am iterating through a listbox control using for loop as:

Dim i1 as Int32
For i1 = listbox1.SelectedIndex + 1 To listbox1.Items.Count - 1
.............
.............
I need to know if somehow instead of reaching the end of list i should stop iterating upon finding a particular element say an element beginning with "T". I mean, i need to replace "listbox1.Items.Count - 1" with some condition. But the problem here is that for loop runs with integer type values. I have tried do/while loops but they seem to be going into infinite loops.

Any guidance is welcome!

Regards
Monica





 
Old September 1st, 2006, 11:43 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

why cann't just do an exit for???

HTH

Gonzalo
 
Old September 1st, 2006, 11:52 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

For i1 = listbox1.SelectedIndex + 1 To listbox1.Items.Count - 1
 if [some condition] exit for
Next

To reiterate what gbianchi said. =]

"The one language all programmers understand is profanity."
 
Old September 1st, 2006, 03:22 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Guys, thanks for replying. Here is my code:
I have 2 listboxes list1 & list2:

Dim g As Int32 = 0
Dim h As Int32 = 0

Dim iCountI As Integer
iCountI = list2.Items.Count - 1

Dim iCountCl As Integer
iCountCl = list1.Items.Count - 1

Dim str1 As String = " "
str1 = list2.Items(iCountI - 1).Value.Substring(0)

If list1.SelectedIndex < iCountCl Then
    h = list1.SelectedIndex + 1
End If

If list2.SelectedIndex < iCountI Then
    g = list2.SelectedIndex + 1
End If

If list1.SelectedItem.Value.Substring(0, 1) <> "T" And list2.SelectedItem.Value.Substring(0, 1) <> "C" And list1.Items(h).Value.Substring(0, 1) <> "C" And list2.Items(g).Value.Substring(0, 1) <> "T" Then

Dim c1 As Int32 = 0
Dim i1 As Int32 = 0
Dim var1 As String = list1.SelectedItem.Value.Substring(1)
Dim var2 As String = list2.SelectedItem.Value.Substring(1)
Dim tvar1 As String = list2.Items(g).Value.Substring(0, 1)

If list1.SelectedIndex <> -1 And lbItems.SelectedIndex <> -1 And list1.SelectedIndex <= list1.Items.Count - 1 And list2.SelectedIndex <= list2.Items.Count - 1
Then
    For c1 = list1.SelectedIndex + 1 To list1.Items.Count - 1
      For i1 = list2.SelectedIndex + 1 To list2.Items.Count - 1
        If c1 > 0 And c1 <= list1.Items.Count - 1 And i1 > 0 And i1 <= list2.Items.Count - 1 Then
          If list1.Items(c1).Value.Substring(1) = list2.Items(i1).Value.Substring(1) Then
     somefunction()
    Exit Sub
             End If
         End If
    Next i1
    Next c1
  End If
 End If
End If
''''var1,var2 & tvar1 are used for debugging purpose

I need to iterate from the two lists. The lists are arranged as:

Day-LIST1 Topic-LIST2
--------- ----------
Day1 topic1
 -topic1 -Day1
 -topic3 -Day4
Day2 topic2
Day3 -Day3
 -topic3 topic3
 -topic2 -Day1
Day4 -Day3
 -topic1

I am attaching & dettaching days(LIST1) with topic(LIST2) & vice versa using the above code. Say if i select Day3 from List1 & topic2 from List2 and call somefunction() to de-attach, it removes topic2 from List1 & Day3 from List2 only against the selected value-set and not elsewhere. But again if i select Day3 from List1 but topic1 from List2, it is expected not to do anything as there is no matching pair in the subset,but it is removing Day3 from List2. I need to stop this. Also as shown in the code,the Ist character of any DAY begins with 'C' and the Ist character of any TOPIC begins with 'T' . I have been using it above for few validations check.
The datatypes are varchar.
I hope its clear now. I need to validate the dettaching thing.

 
Old September 1st, 2006, 04:26 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In my last post list2 was wrongly printed as lbItems at 1 place.
Apologies...

Regards

 
Old September 1st, 2006, 05:36 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

dim li1, li2 as ListItem

for each li1 in list1.items
   for each li2 in list2.itmes
   next
next

Program logic is up to you but that will iterate through the listbox collections and then you can compare the values.

"The one language all programmers understand is profanity."




Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting a Listbox - refining it jeremy1048 Access 3 June 23rd, 2008 07:58 AM
iteration bostek Excel VBA 5 August 30th, 2006 01:23 AM
Picture iteration bahachin Excel VBA 3 September 28th, 2005 12:44 PM
Iteration in struts sridevi Servlets 2 July 1st, 2005 07:01 AM
Iteration through a dropdown. tryxxter PHP How-To 1 February 9th, 2005 11:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.