Philippe Renaud
asked on
Retrieve data from array
Idle_Mind,
Remember this code you did for me ?
The result is o ListBox is like:
600 400
300 250 100 50
etc..
but What If I would need the index of the amount ? (in an array or another list box doesn matter)
like that:
600 400 4,7
300 250 100 50 1,2,3,6
Like that I could know where was the amount. Becasue if there are two same amounts I cannot know wich it tooks...
any ideas?
Remember this code you did for me ?
The result is o ListBox is like:
600 400
300 250 100 50
etc..
but What If I would need the index of the amount ? (in an array or another list box doesn matter)
like that:
600 400 4,7
300 250 100 50 1,2,3,6
Like that I could know where was the amount. Becasue if there are two same amounts I cannot know wich it tooks...
any ideas?
Private Sub bgw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles bgw.DoWork
Dim values() As Decimal = DirectCast(e.Argument, Decimal())
For i As Integer = 1 To values.Length
Dim combos As Combinations(Of Decimal)
combos = New Combinations(Of Decimal)(values, i)
Dim matches = From combo In (From _set In combos Select _set) _
Where combo.Sum() = target _
Select combo
For Each c As Object In matches
solutions.Add(c.ToArray())
Next
For Each solution As Decimal() In solutions
Dim str As String = ""
For Each dec As Decimal In solution
str += dec.ToString() + " "
Next
AddTextToListBox(Trim(str))
str = ""
Next
solutions.Clear()
Next
End Sub
Hmmm...so if your original data was:
private double[] values = { 200, 2000, 250, 10, 600, 500, 300, 400, 100};
And {600, 400} was a solution...you need to know that 600 was at Index 4?...and that 400 was at Index 7?
private double[] values = { 200, 2000, 250, 10, 600, 500, 300, 400, 100};
And {600, 400} was a solution...you need to know that 600 was at Index 4?...and that 400 was at Index 7?
ASKER
That's correct. And if there were multiple solutions.. I would need for each of them the index..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
*Note that the LINQ query has changed to:
...so that we are getting the sum of the Value() member of our Data class.
Dim matches = From combo In (From _set In combos Select _set) _
Where combo.Sum(Function(x) x.Value) = target _
Select combo
...so that we are getting the sum of the Value() member of our Data class.
ASKER
Yes perfect... thanks a lot Idle!
ASKER
ASKER
Idlemind how are you :)
https://www.experts-exchange.com/questions/27027337/vb-net-playing-with-numbers-challenge.html
new quesiton for you :)
https://www.experts-exchange.com/questions/27027337/vb-net-playing-with-numbers-challenge.html
new quesiton for you :)
{listboxname}.Index or SelectedIndex, or SelectedItem (returns the ListBoxItem object)
Greetings.