Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






Step 30. Saving your project’s settings.

A while back Welcometomylair1 asked a question about saving project settings so they would persist from one run to the next. In my reply I outlined a way to extend the existing SessToken.txt file to save project settings as well as the session token. G-Factor suggested a simpler way of doing this using VB’s inbuilt application settings facility. In this step we look at this.

1. Saving the value of a control’s property.

For example the Text property of a TextBox.

TextBoxes are handy controls which are commonly used to hold settings for your project, e.g. marketId, sample frequency, etc. For this exercise drag a TextBox from the ToolBox onto the TestForm and rename it to tParam (or anything you like).

With this TextBox selected so that its properties appear in the "Properties" widow, expand the (ApplicationSettings) node. Click on (PropertyBindings) then click (...) to show the "Applications Setting for tParam" form. Select the Text property then click (New...) in the property’s associated drop down list window to show the "New Application Setting" form. Enter these settings:

DefaultValue: 123
Name: Param1
Scope: User

Click OK, OK. With this procedure we have bound the tParam.Text property to an application setting we have created named Param1. Think of an application setting as being a special variable whose value is retained from one run to the next.

Now run the project. Notice that the default value we entered appears in the TextBox. Change this value to something else (e.g. 456), then close the form to stop the project running. Re-run the project and notice that the new value is now in the TextBox. Thus the TextBox always retains the most recently entered value. We have achieved this without writing any code.

2. Saving any value.

The application settings can be used to retain any value you like. You can create a new setting by clicking "BetfairX Properties" on the Project menu to show the Properties form. Select the "Settings" tab. Here you will see all the settings used by the project, including Param1 which we added above. You add a new setting by adding a new entry to the table. For example, add the name Param2, having value "This is Param2". This setting becomes a property of the My.Settings object and can be accessed from anywhere in you code with:

My.Settings.Param2

To demonstrate, put this code in Sub TestForm_Load:

Code:

.....

Print("Last run: " & My.Settings.Param2) 'Previous run time

My.Settings.Param2 = Now 'Re-assign the setting

Print("This run: " & My.Settings.Param2) 'Current run time

.....

and run the project a few times. You will see that Param2 initially holds the previous run time.

Note:

We could have used an application setting to hold the session token rather than storing it in the auxiliary file SessToken.txt.

Two "scopes" are available. With "User" scope the values of the settings apply only to the current (Windows) user. With "Application" scope the settings values apply to all users.



 


 

 


 

Step 1. Build a Test Form

Step 2. Connecting to the Global service

Step 3. Saving the Session Token

Step 4. Typical API call: getActiveEventTypes

Step 5. Accessing an Exchange API

Step 6. Unpacking Response Strings

Step 7. Restrictions of the Free API

Step 8. Using a Call Timer

Step 9. Making Async API Calls

Step 10. Calling getCompleteMarketPricesCompressed

Step 11. A Look at Multithreading

Step 12. Getting a List of Runners

Step 13. Enabling gzip Compression

Step 14. Calling getMarketPricesCompressed

Step 15. Using TreeView to show events and markets

Step 16. Unpacking Removed Runners

Step 17. Sorting Runner Info Arrays

Step 18. Horse Racing - Today’s Card

Step 19. Placing a Bet

Step 20. Monitoring Bet Status

Step 21. Cancelling a Bet

Step 22. Changing the bet size and price

Step 23. Changing a Bet

Step 24. Calling getMarketTradedVolumeCompressed

Step 25. Accessing Australian Markets

Step 26. Array fundamentals

Step 27. Understanding Object References

Step 28. Placing Multiple Bets with placeBets

Step 29. Adding controls to a form at run time

Step 30. Saving your project’s settings


Date: 2014-12-21; view: 1368


<== previous page | next page ==>
Step 29. Adding controls to a form at run time. | Writing Skills
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.006 sec.)