lothos12345 Posted October 28, 2005 Posted October 28, 2005 In visual basic.net I have an developed an application. Have a an arraylist with a list of, what I call targets, this list can grow and shrink. Each target in the arraylist has a value associated with it "True or False". So if the arraylist has three items, I need to account for all the possiblities of true and false that the value of these targets could be. Unforunately I have no ideal how to write an algorthim that would accomplish this. Any help would be greatly appreciated. Quote
*Experts* DiverDan Posted October 28, 2005 *Experts* Posted October 28, 2005 Are the items in your array list from a structure or did you just set a single value add add it to the array list? Can you post how the array list was developed? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
lothos12345 Posted October 28, 2005 Author Posted October 28, 2005 Arraylist I set a single value returned from a sql database and add it to the arraylist. A structure is not involved at all. Quote
*Experts* DiverDan Posted October 28, 2005 *Experts* Posted October 28, 2005 I'm guessing at what you want but you can loop through the array list and collect the number of "True" or "False" values a few different ways. Here are two: Dim i, trueStatements, falseStatements as Integer For i = 0 to myArrayList.Count -1 If myArrayList.Item(i).ToString = "True" Then trueStatements += 1 ElseIf myArrayList.Item(i).ToString = "False" Then falseStatements += 1 End If Next OR knowing that an array list is a standard object collection Dim trueStatements, falseStatements as Integer Dim obj As Object For Each obj in myArrayList If obj.ToString = "True" Then trueStatements += 1 ElseIf obj.ToString = "False" Then falseStatements += 1 End If Next I hope that this is what you are looking for. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
lothos12345 Posted October 28, 2005 Author Posted October 28, 2005 Arraylist Method Your second method is the way to go, however I need to set and integer value to the value in arraylist object. Everytime I try it gives me an invalid case exception, how do I accomplish this? Quote
*Experts* DiverDan Posted October 28, 2005 *Experts* Posted October 28, 2005 (edited) Is the integer value based on the database index or something else? I'm asking this as it might be better if you setup a structure utilizing the database index and the "True", "False" variables as booleans. This way you'll have the integer index value and its boolean state. Structure stuTarget Dim Index As Integer Dim State As Boolean End Structure Then when you obtain the "True", "False" state of the database you can also obtain it's index. Dim newTarget stuTarget 'loop through your database newTarget = New stuTarget target.Index = databaseIndex If SomethingBad Then target.State = False Else target.State = True myArrayList.Add(newTarget) 'end database loop Then to loop through myArrayList and obtain the state and index values: Dim target as stuTarget For Each target In myArrayList If target.State = False Then MessageBox.Show(target.Index) End If Next I hope this helps. Edited October 28, 2005 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
lothos12345 Posted October 28, 2005 Author Posted October 28, 2005 Arraylist No I am getting a list of numbers from the database in which I then need to feed to another method which will then toggle the values of true and false, The numbers are coming from the Database, thus it looks something like: Dim y as integer For Each x as object in TheArraylist y =x -- y needs to equal x as the value of x is a number. Next However I cannot get it to cast correctly, I am continueally getting casting errors. Any help given is greatly appreciated. Quote
*Experts* DiverDan Posted October 28, 2005 *Experts* Posted October 28, 2005 Please drop me a PM with your email address Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.