Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help speeding this database program up

mike02223mike02223 Posts: 4Member
Ok so here is what I am doing. I created a database called powerball in sqlserver2008 express. It has 1 table that is called combinations.
This table is to hold all 195 million combinations of the powerball lottery in order. I created all the code in visual basic express 2008 which goes through and creates every combination in order via nested loops. The problem is this takes an extremely long time to execute. I let it run for 1 whole day and it had only made it up to combination 15 million. I am up to any suggestions on speeding this program up.

the table columns consist of

Combination, White Ball1, White Ball2, White Ball3, White Ball4, White Ball5, Power Ball

Here is the code for the function
[code]
Dim ball1 As Integer = 1
Dim ball2 As Integer = 2
Dim ball3 As Integer = 3
Dim ball4 As Integer = 4
Dim ball5 As Integer = 5
Dim powerball As Integer = 0
Dim combination As Long = 0
Dim counter As Long = 0

Do Until ball1 >= 56
Do Until ball2 >= 57
Do Until ball3 >= 58
Do Until ball4 >= 59
Do Until ball5 >= 60
Do Until powerball >= 39

powerball = powerball + 1
combination = combination + 1
Me.CombinationsBindingSource.AddNew()
Me.White_Ball1TextBox1.Text = ball1
Me.White_Ball2TextBox1.Text = ball2
Me.White_Ball3TextBox1.Text = ball3
Me.White_ball4TextBox1.Text = ball4
Me.White_Ball5TextBox1.Text = ball5
Me.Power_BallTextBox1.Text = powerball
Me.CombinationTextBox1.Text = combination

counter = counter + 1
If counter = 10000 Then
Me.Validate()
Me.CombinationsBindingSource.EndEdit()


Me.CombinationsTableAdapter.Update(Me.PowerballDataSet.Combinations)
counter = 0
End If
Loop
powerball = 0
ball5 = ball5 + 1
Loop
ball5 = ball4 + 2
ball4 = ball4 + 1
Loop
ball4 = ball3 + 1
ball3 = ball3 + 1
Loop
ball3 = ball2 + 1
ball2 = ball2 + 1
Loop
ball1 = ball1 + 1
Loop

Me.Validate()
Me.CombinationsBindingSource.EndEdit()

Me.CombinationsTableAdapter.Update(Me.PowerballDataSet.Combinations)[/code]

Comments

  • ravigandhiravigandhi Posts: 1Member
    Try using threads for each ball (i.e 1-5) and run the process in parallel
  • mike02223mike02223 Posts: 4Member
    Thanks for the advice but i believe that running these in parallel will result in:
    [code]
    ball1 ball2 ball3 ball4 ball5 pb
    1 2 3 4 5 1
    2 3 4 5 6 2
    3 4 5 6 7 3
    4 5 6 7 8 4
    5 6 7 8 9 5
    6 7 8 9 10 6
    7 8 9 10 11 7 [/code]

    which wont be correct it needs to be like this

    [code]
    ball1 ball2 ball3 ball4 ball5 pb
    1 2 3 4 5 1
    1 2 3 4 5 2
    1 2 3 4 5 3
    1 2 3 4 5 4
    1 2 3 4 5 5
    1 2 3 4 5 6
    1 2 3 4 5 7
    [/code]

    until pb = 39 then ball5 = 6
    and when ball 5=59 then ball4=5 and so on until the combinations
    will equal:

    [code]
    ball1 ball2 ball3 ball4 ball5 pb
    55 56 57 58 59 39
    [/code]

    and the only way i can see to do this is with nested loops like i have in my previous post unless with the parallel threads are running separate functions one for each ball but they do not increment until the value of the next ball reaches its max. But I have not idea how to implement threads that would do this
Sign In or Register to comment.