Consulting

Results 1 to 4 of 4

Thread: Creating a State Machine using VBA

  1. #1
    VBAX Contributor
    Joined
    Sep 2017
    Posts
    128
    Location

    Creating a State Machine using VBA

    State Machine.docxBetAngel_Multiple.xlsm

    Hello VBAExpress community!

    I was wondering whether anybody had done something like this before or had any idea how to create such a thing using VBA? I have attached a diagram of the system in question as a word file and the type of worksheet I will be using also.

    Basically, I have a coupe of cells acting as 'triggers' for Cell L9 to display either: BACK, LAY or CLOSE_TRADE (this is a trading app in progress). The problem is that control logic changes during development; triggers are ticking at very quick frequencies (milliseconds). CLOSE_TRADE's should only follow BACK/LAY orders and vice versa.

    Another problem I've been having is when I try to close a bet, I could get an error back due to that price (Cell G9) disappearing before I can trade it? Once an order has been placed, I am at the back of a queue to get matched so although my system is very fast, it has to play fair and wait an undeterminable amount of time. The market in question is BetFair exchange which I've been told has many characteristics similar to a type 2 trading market.

    Again, if anybody has done something similar to this before or could point me in the right direction to get a state machine type code, it would help me loads!

    Thank you,
    CPerry

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    For an example of the design and creation of a VBA Finite State Machine, see: http://www.vbaexpress.com/forum/show...ngel-and-Excel
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Here is a workbook that operates as your state machine. I have done this for you to show you how the state machine logic can all be done in a generic way. So the states and the rules to change between them can be programmed as "data" and not actuall program logic.
    I have done this to demonstrate the technique and not to produce the sort of code you need for you application.

    The worksheet should be obvious the triggers are in column B wit the description in column A, The states are in columnC and the rules governing the permissable changes of state are in columns E to G
    Just type true in B3 to turn it on , then try triger a lay by putting true in B5, and carrry on.
    Attached Files Attached Files

  4. #4
    VBAX Contributor
    Joined
    Sep 2017
    Posts
    128
    Location
    This is fantastic! Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •