Placing bet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #16
    I'm sure we can sort it.

    Is the datagrid filled in with the selection just before the race or with all selections at the start of the day?
    Last edited by jabe; 25-01-2021, 05:26 PM.

    Comment

    • tippete
      Junior Member
      • Mar 2016
      • 42

      #17
      Originally the datagrid had every horse running in every race in the uk that day. Now it is loaded one race at a time, as selected from the list of todays races.

      Comment

      • jabe
        Senior Member
        • Dec 2014
        • 705

        #18
        Is there a bet in every race?

        If there's only one bet per race, does it want to be placed before the race?

        If the answer is yes to both of these, here's what you want:

        1 Load up the day's races and sort them on start time.
        2 Keep checking how close the next race is and when the current time is close to the start of a race, select the horse to bet on.
        3 Place the bet.
        4 When there are no races left, stop.

        In 2, you know what the selectionId is, you know what the stake is, you've an idea what the current odds are, and you know what the marketId is. You can always knock a few ticks off the odds and it will match with whatever there is above or at the odds you name. You know it's a back bet.

        You mentioned that the Datagrid click routine causes a bet to be placed. Have a look at how it passes the relevant data and do the same thing as soon as the selection is chosen,

        Comment

        • tippete
          Junior Member
          • Mar 2016
          • 42

          #19
          Again, this is the part of the program that takes a selection and passes it on to the bet.

          What i understand is the sub is carried out when a cell is clicked.

          In this case it looks for a cell in column 6 being pressed. This is the column that contains the runners names.

          When a name is selected it opens a new form called runnerform

          It checks which row the selection is on and gets the row index .

          The details for the horse are sent to the top of the form so it shows runners name, start time, course, market id and selection id.

          The UserControl is then used to complete the betting form by printing a datagrid with side, size and price requested.

          The rest is automated

          Private Sub DataGridView1_CellContentClick(sender As Object,
          e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

          If e.ColumnIndex = 6 Then

          Dim runnerForm As New RunnerForm(DataGridView1.Item("runnerName", e.RowIndex).Value _
          & " - " & DataGridView1.Item("marketStartTime", e.RowIndex).Value & " " &
          DataGridView1.Item("course", e.RowIndex).Value,
          DataGridView1.Item("marketId", e.RowIndex).Value,
          DataGridView1.Item("selectionId", e.RowIndex).Value)


          runnerFormDictionary.Add(DataGridView1.Item("selec tionId", e.RowIndex).Value,
          runnerForm)
          End If

          End Sub

          The problem i am having is opening the runnerform, which needs the click in this situation to open.

          Comment

          • jabe
            Senior Member
            • Dec 2014
            • 705

            #20
            I may have a way round it that still allows your prog to bet via the runnerform, though I'm not certain about some of it. Hopefully you'll be able to play around with it if the following doesn't work immediately.


            I've been trying to work out how to simulate the click on the runner name.

            It can be done, but I'm not 100% sure where the simulated click would be coded. There should be code somewhere putting the selected runner into DataGridView1 and the line to simulate the click will need to be somewhere afterwards.

            It'll look something like this:

            Code:
            DataGridView1_CellContentClickEventHandler(new object(), new eventargs()
            )

            I'm not at all certain about the coding of this. It came up via a search online.
            (My version of Visual Studio doesn't appear to have an event called CellContentClick, but no matter).

            There will have to be changes in the routine that deals with the click. You mentioned that there would only be one horse in the grid. e.RowIndex will need to be replaced with a value - either 0 or 1, probably 0, but I'm not certain. The test for e.columnindex = 6 needs discarding. Probably the easiest way is to create a variable just named RowIndex and set it to 0 or 1, then lose the e. in the rest of the subroutine. Then if the value needs changing, you've only to do it in one place.

            Comment

            • tippete
              Junior Member
              • Mar 2016
              • 42

              #21
              I think the row index is used to find the info in the row (rowIndex) in the Datagrid.
              I can determine this by program and am able to put this in 5 textboxes. What i need is to open the "runnerform" and place the info on it in the usercontrol OR
              take the info from the databoxes and place the order
              What you see in the upload is the 5 textboxes and the runnerform after i have clicked the selections name in the datagrid.
              You do not have permission to view this gallery.
              This gallery has 1 photos.

              Comment

              • jabe
                Senior Member
                • Dec 2014
                • 705

                #22
                The purpose of simulating the click on the cell is to remove the need for the manual click. However, simulating the manual click means that the DataGridView1_CellContentClick routine is reached without information for e.ColumnIndex and e.RowIndex, which is why they can't be used. Using a variable set to whatever e.RowIndex would have been should satisfy the processing because there is only ever one row with data in it. The check for e.ColumnIndex = 6 doesn't appearto have a point.

                If I were writing this program, it would be rather different. The suggestions I made ought to minimise the changes required to get it to work.

                Comment

                • tippete
                  Junior Member
                  • Mar 2016
                  • 42

                  #23


                  If I were writing this program, it would be rather different. The suggestions I made ought to minimise the changes required to get it to work.[/QUOTE]

                  What suggestions were they Jabe?

                  Comment

                  • jabe
                    Senior Member
                    • Dec 2014
                    • 705

                    #24
                    1. Find the code that populates DataGridView1 and add this after it:

                    DataGridView1_CellContentClickEventHandler(new object(), new eventargs())

                    2. In DataGridView1_CellContentClick

                    Delete these two lines:
                    If e.ColumnIndex = 6 Then
                    End if

                    Add this line so it's first in the subroutine:
                    Dim RowIndex = 0

                    Change all occurrences of e.RowIndex to just RowIndex


                    Unfortunately I can't guarantee the code in 1. Do the changes and test it and if it doesn't do the job I'll see what else I can think of.

                    Comment

                    • tippete
                      Junior Member
                      • Mar 2016
                      • 42

                      #25
                      Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
                      Dim rowIndex = 0

                      Dim runnerForm As New RunnerForm(DataGridView1.Item("runnerName", rowIndex).Value _
                      & " - " & DataGridView1.Item("marketStartTime", rowIndex).Value & " " &
                      DataGridView1.Item("course", rowIndex).Value,
                      DataGridView1.Item("marketId", rowIndex).Value,
                      DataGridView1.Item("selectionId", rowIndex).Value)

                      runnerFormDictionary.Add(DataGridView1.Item("selec tionId", rowIndex).Value,
                      runnerForm)

                      End Sub

                      With the above code we still need to click in the datagrid.
                      Now we always get the first row no matter what we select.
                      I will have a look again tomorrow.

                      Comment

                      • jabe
                        Senior Member
                        • Dec 2014
                        • 705

                        #26
                        You said there was only ever one selection.

                        Where did you put the line to simulate the click on the cell? Can you show me the subroutine you added that to?

                        Comment

                        • tippete
                          Junior Member
                          • Mar 2016
                          • 42

                          #27
                          1. when i said one selection . i meant one selection from up to 8 runners.(I can output the rowIndex to a TextBox though.
                          2. I only altered the above sub.
                          3. Today i will try to change line one to do away with the click.

                          Comment

                          • tippete
                            Junior Member
                            • Mar 2016
                            • 42

                            #28
                            Ok Jabe i've made some progress linking the sub to a timer instead of the datagrid click.It is now firing automatic but opens 2 runnerforms and places the bet twice . Any ideas?
                            Oh and theres an exception shown in photo.


                            Private Sub CheckBets()
                            Dim rowIndex = 0

                            Dim runnerForm As New RunnerForm(DataGridView1.Item("runnerName", rowIndex).Value _
                            & " - " & DataGridView1.Item("marketStartTime", rowIndex).Value & " " &
                            DataGridView1.Item("course", rowIndex).Value,
                            DataGridView1.Item("marketId", rowIndex).Value,
                            DataGridView1.Item("selectionId", rowIndex).Value)

                            runnerFormDictionary.Add(DataGridView1.Item("selec tionId", rowIndex).Value,
                            runnerForm)


                            End Sub
                            You do not have permission to view this gallery.
                            This gallery has 1 photos.
                            Last edited by tippete; 28-01-2021, 10:50 AM.

                            Comment

                            • tippete
                              Junior Member
                              • Mar 2016
                              • 42

                              #29
                              Latest development . I found there was a problem that the bet was firing twice, but i didn't realise at the last post that the bets were firing at start up without
                              any selection taking place . I have amended the code to check the time i want to fire the bet against the time now. (Label1 contains the time now and label2 is
                              the time i want the bet to fire.

                              TO prevent a 2nd bet i intrroduced sumBacked = 0 as a condition of the bet .
                              sumBacked = 100 makes the condition stop on the 2nd loop.

                              The only problem now is to use the correct row of the selections .
                              I already have a textBox output that tells me the rowIndex so i just need to put this variable into the Dim rowIndex = 0 line.

                              Private Sub CheckBets()
                              Dim rowIndex = 0

                              If Label1.Text = Label2.Text And sumBacked = 0 Then

                              Dim runnerForm As New RunnerForm(DataGridView1.Item("runnerName", rowIndex).Value _
                              & " - " & DataGridView1.Item("marketStartTime", rowIndex).Value & " " &
                              DataGridView1.Item("course", rowIndex).Value,
                              DataGridView1.Item("marketId", rowIndex).Value,
                              DataGridView1.Item("selectionId", rowIndex).Value)

                              runnerFormDictionary.Add(DataGridView1.Item("selec tionId", rowIndex).Value,
                              runnerForm)

                              sumBacked = 100

                              End If
                              End Sub

                              Comment

                              • jabe
                                Senior Member
                                • Dec 2014
                                • 705

                                #30
                                Looks like we got our wires crossed. And it sounds like you've made good progress.

                                The double bet sounds like a problem I had with the procedure for logging into the Betfair API. I had to add a condition to get round the first useless time.
                                Last edited by jabe; 28-01-2021, 04:22 PM.

                                Comment

                                Working...
                                X