Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
  • *Experts*
Posted
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?

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted

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.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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?

  • *Experts*
Posted (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 by DiverDan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...