Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • granted
    Junior Member
    • Jun 2009
    • 14

    #661
    Left Mouse Click - how to use it

    I was trying to figure out how to use the mouses left click on a button..

    i tried:

    Code:
    if mousebuttons = windows.forms.mousebuttons.left then
    ....of course this didnt work.

    does anyone know how i can impement the left mouse button to press a button on a form?

    thanks

    Comment

    • BigSprout
      Junior Member
      • Feb 2011
      • 60

      #662
      granted,
      not sure if I understand your question fully, but I will answer as I have interpreted it:

      I was trying to figure out how to use the mouses left click on a button..

      does anyone know how i can impement the left mouse button to press a button on a form?
      If you place a button on your form e.g. "Button1"
      Place the cursor over the button and double click on it with the left mouse button - this will put the code, if you have named your button something other than "Button1" then this will automatically be substituted:

      Code:
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              
          End Sub
      Enter this line in the Sub so it shows like this:
      Code:
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              Print("I have clicked the left mouse button")
          End Sub
      Run the program, place your cursor over the button and left click on the mouse, if you have the print sub written, this will show:

      "I have clicked the left mouse button"

      If this doesn't answer your question then you may have to be a little more specific of your requirements

      Of course this option may be more in line with what you are trying to do:
      Code:
          Private Sub Button1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick
              If e.Button = Windows.Forms.MouseButtons.Left Then Print("I have clicked the left mouse button")
          End Sub
      cheers
      Last edited by BigSprout; 02-07-2011, 10:21 AM.

      Comment

      • BigSprout
        Junior Member
        • Feb 2011
        • 60

        #663
        granted,
        just incase you are trying to write code to use either the left or right mouse click on a control e.g a panel(pStats):

        Code:
            Private Sub pStats_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pStats.MouseClick
                If e.Button = Windows.Forms.MouseButtons.Left Then Print("Left")
                If e.Button = Windows.Forms.MouseButtons.Right Then Print("Right")
            End Sub

        Comment

        • granted
          Junior Member
          • Jun 2009
          • 14

          #664
          detecting Right Click....

          i have seen on some programs that when you left click the price it places the back bet but when you right click it, it places a lay bet

          this is what i am trying to figure out...the buttons don't exist until you load the market, so the form that holds the buttons doesnt exist in visual basic, so how do they detect right click and then set the bet to be a lay instead of a back bet

          Comment

          • BigSprout
            Junior Member
            • Feb 2011
            • 60

            #665
            Hi granted,
            I tried using left/right mouse clicks but the right didn't seem to work on a button, that's why I tried and suggested using a panel.

            My simplistic solution would be to use panels in the size of a button whereby left/right mouse clicks will then register - load panels at run time instead of buttons.

            Others with more experience may be able to offer a simpler solution.

            cheers

            Comment

            • davecon
              Junior Member
              • Dec 2010
              • 86

              #666
              Hi Granted and BigSprout

              The Mouse Right Click Function(Or Left Click if you are left handed) is reserved mainly for use with the Context Menu on nearly every application (The Short Cut Menu) I would be lost without it
              You can set a ContextMenuStrip to the Main Form Itself And/Or All each seperate controls in VB as many as desired

              I assume you are not using any at the moment so you could in fact just Use the MouseDown Event for your Button (Or most controls) as so:

              '** for a TestButton "btnTestButton" **

              Private Sub btnTestButton_MouseDown _
              (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
              Handles btnTestButton.MouseDown

              '///// e.Button = Windows.Forms.MouseButtons \\\\\

              If e.Button = MouseButtons.Right Then

              Print("Right Button Pressed")
              'Put your code here

              ElseIf e.Button = MouseButtons.Left Then
              Print("Left Button Pressed")
              'Put your code here

              ElseIf e.Button = MouseButtons.Middle Then
              Print("Middle Buttton Pressed")
              'Put your code here

              End If 'e.Button

              'There is also
              'e.Button = MouseButtons.XButton1
              'e.Button = MouseButtons.XButton2
              'e.Button = MouseButtons.None

              End Sub 'btnTestButton_MouseDown

              However the best way in my opinion would be to make use of the ContextMenuStrip to achieve just a Right Click if Required (and a host of other commands) while at the same time you can see how it works

              In the Toolbox look for Menus & Toolbars and Drag or Double Click a "ContextMenuStrip" Control onto the Form
              You will see it at the Bottom (With Timers etc) with default name "ContextMenuStrip1"

              (Left Click on the Control and you will see at the Top of your Form the Menu with a "Type Here" thingy - This is where you would put your Items in a Drop Down Menu and set each one of them like any other Control such as the Click Event as Desired
              You can access this at any time to add or modify commands by just left clicking the Control (Dont use the Properties at first its far too complex)

              However ignore the MenuItems for now and just Re- Name your ContextMenuStrip1 in the Properties Window as you would any other Control (If desired) I have named it cmBtnTestButton

              Then once Re-named Double Click the Control at the Bottom(Not the Menu Items) and it will open up the Controls "Opening" Event

              Private Sub cmBtnTestButton_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmBtnTestButton.Opening

              cmBtnTestButton.Visible = False 'If you dont want to see anything else and just do a Right Click command

              Print("Mouse Right Click")
              'Put Code Here

              End Sub 'cmBtnTestButton Opening

              Finally you need to set your ContextMenuStrip to the Desired Control in this case our TestButton - So Click on your TestButton and in the Properties Window you will see the Property "ContextMenuStrip" Set to None
              Just Click on this and you will see your cmStrip Listed And Click to set it to the Control

              Now when you Right Click on your Button it will act as you desire (hopefully)
              And of Course assuming you have cancelled out the MouseDown Code

              The ContextMenuStrip is a great tool to play around with and will only enhance your Program

              Hope this helps Guys
              Cheers
              Dave

              Comment

              • BigSprout
                Junior Member
                • Feb 2011
                • 60

                #667
                Dave,
                thanks for that, I certainly will have a play with it now to learn all its functions,

                cheers Les

                Comment

                • antonello273
                  Junior Member
                  • Feb 2010
                  • 12

                  #668
                  Market Soccer

                  Good day to all, i say because how can i download the market of soccer?

                  Comment

                  • NFLMAN
                    Junior Member
                    • Jun 2010
                    • 17

                    #669
                    Originally posted by antonello273 View Post
                    Good day to all, i say because how can i download the market of soccer?
                    I would suggest starting on page 1 of this thread and posting here if and when you get stuck. If you follow all the steps in sequence you will discover how to get the soccer markets.

                    Comment

                    • Mumbles0
                      Junior Member
                      • Jan 2009
                      • 240

                      #670
                      Optimus,

                      The market data returned from the getAllMarkets call is unpacked into the .marketData() array within the AllMarkets object, so you don’t need a separate array. All you have to do is put the AllMarkets object variable outside the sub:

                      Code:
                      [COLOR="Gray"][COLOR="Black"]Dim AllMarkets As UnpackAllMarkets[/COLOR]
                      
                      Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bMarkets.Click
                        Print("******** Markets *********")
                        Dim oMarketsReq As New BFUK.GetAllMarketsReq
                        Dim oMarketsResp As BFUK.GetAllMarketsResp
                        With oMarketsReq
                          .header = oHeaderUK()
                          ReDim .eventTypeIds(0) : .eventTypeIds(0) = 2
                          .fromDate = Today
                          .toDate = Now.AddDays(1)
                        End With
                        oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
                        With oMarketsResp
                          CheckHeader(.header)
                          Print("ErrorCode = " & .errorCode.ToString)
                          If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                            [COLOR="Black"]AllMarkets = New UnpackAllMarkets(.marketData)  'Unpack the market data[/COLOR]
                          End If
                        End With
                      End Sub[/COLOR]
                      If you want your MpricesReq function to cycle continuously through the .marketData() array each time it is called, define a simple index variable to point to the next .marketData() element to be returned:

                      Code:
                      [COLOR="Gray"][COLOR="Black"]Dim iMarket As Integer  'Index for AllMarkets.marketData array[/COLOR]
                      
                      Function MpricesReq() As BFUK.GetMarketPricesReq
                        Dim oMPReq As New BFUK.GetMarketPricesReq
                        With oMPReq
                          .header = oHeaderUK()
                      [COLOR="Black"]    .marketId = AllMarkets.marketData(iMarket).marketId  'The next marketId in the array
                          iMarket += 1  'Increment the index
                          If iMarket = AllMarkets.marketData.Length Then iMarket = 0 'Reset the index when end of array is reached[/COLOR]
                        End With
                        Return oMPReq
                      End Function[/COLOR]
                      When the end of the .marketData array is reached, the index is reset back to the start.

                      Comment

                      • davecon
                        Junior Member
                        • Dec 2010
                        • 86

                        #671
                        Originally posted by Optimus Prime Number
                        Hi OPN
                        You seem to be trying to run before you can crawl here my friend - No offence
                        Thanks to Mumbles who has shared with us all his vast experience regarding the API and programming VB in general,
                        not to mention the vast amount of time sacrificed to assist us all whenever possible, for which, I myself and sure countless others are truly grateful ( Thanks mumbles mate )
                        However, he is not employed by us - We need to learn ourselves based on the guys free gift to us all
                        Speaking for myself I had virtually zilch programming knowledge except for playing around with VB6 years ago and was completely clueless how to access the API before I came upon this thread
                        Yet in just a couple of short Months I have built myself a bot that can do things that I could have only dreamed about and have astounded myself at what I have achieved and am still learning every single Day and find the journey totally fascinating ( Thanks Mumbles mate )
                        I soon realized that I had to grasp a better understanding of all the basics in VB before I started digging into the advanced stuff in this great tutorial (btw Arrays still do my head in!!)
                        You can purchase many Books on the subject from Amazon for next to nothing (I got a 2008 one for a penny! )
                        Or alternatively you can download all the latest books for free (Not sure about the legality and please do so at your own risk)
                        http://www.free-ebooks-download.org/...basic-2010.php
                        There are loads of ways to achieve what you are attempting although just quite not sure what that is lol
                        VB has a host of just basic controls that you could use for your purpose until you advance at your own pace such as list boxes, combos and the like
                        Soon you will find yourself in a very short time building some astounding applications from this brilliant thread
                        I wish you all the greatest success in your own journey and hope it will be as fruitful as mine
                        Dave
                        ps Did I fail to mention
                        (Thanks Mumbles mate )

                        Comment

                        • Geierkind
                          Junior Member
                          • May 2011
                          • 10

                          #672
                          Originally posted by Mumbles0 View Post
                          Optimus,

                          The market data returned from the getAllMarkets call is unpacked into the .marketData() array within the AllMarkets object, so you don’t need a separate array. All you have to do is put the AllMarkets object variable outside the sub:



                          When the end of the .marketData array is reached, the index is reset back to the start.
                          Well, I'm not the most established person around, but tomorrow I will try to get this thing (I have the exact same problem as Optimus as it seems) running Would be really great. So thanks for your big help here! You are kind of a savior

                          Comment

                          • Sports API + VB .Net
                            Junior Member
                            • Sep 2010
                            • 11

                            #673
                            In-Play Markets

                            I want to make a tab INPLAY in which there should be a treeview having all the inplay events like

                            Cricket
                            === Ind vs Pak
                            Race
                            === Newt
                            Soccer
                            === Manutd vs Fulham

                            i already have designed a treeview having all the markets (active , inplay) as betfair treeview but now i want this one....

                            can some one help me out which service of api allow me to retrieve only inplay markets i will be waiting for your reply

                            Comment

                            • McTash
                              Junior Member
                              • Feb 2010
                              • 14

                              #674
                              Have a look here

                              https://docs.developer.betfair.com/b...MC.00008338-MC

                              The GetInPlayMarkets should give you what you want.

                              That link takes you to the API docs. They are very useful if you want see what calls are available for each service etc.

                              Comment

                              • Geierkind
                                Junior Member
                                • May 2011
                                • 10

                                #675
                                Originally posted by Mumbles0 View Post
                                Optimus,

                                If you want your MpricesReq function to cycle continuously through the .marketData() array each time it is called, define a simple index variable to point to the next .marketData() element to be returned:

                                Code:
                                [COLOR="Gray"][COLOR="Black"]Dim iMarket As Integer  'Index for AllMarkets.marketData array[/COLOR]
                                
                                Function MpricesReq() As BFUK.GetMarketPricesReq
                                  Dim oMPReq As New BFUK.GetMarketPricesReq
                                  With oMPReq
                                    .header = oHeaderUK()
                                [COLOR="Black"]    .marketId = AllMarkets.marketData(iMarket).marketId  'The next marketId in the array
                                    iMarket += 1  'Increment the index
                                    If iMarket = AllMarkets.marketData.Length Then iMarket = 0 'Reset the index when end of array is reached[/COLOR]
                                  End With
                                  Return oMPReq
                                End Function[/COLOR]
                                When the end of the [FONT="Courier New"marketData[/FONT] array is reached, the index is reset back to the start.
                                Hi, I have 2 problems regarding Optimus Post, perhaps you, or any other kind person could give me some advice.

                                First Question: How do I modify the code further, so that the Prices function "calls itself" until all Prices are read?

                                Second Question: How do I export that big array of all those Prices to Excel the most convenient way?

                                Comment

                                Working...
                                X