Announcement

Collapse
No announcement yet.

Newbies - Don't pass templates by! Tips & Suggested Templates.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbies - Don't pass templates by! Tips & Suggested Templates.

    One of the common tasks I've been doing for months now, as I'm learning PowerBASIC, is typing in test code. I normally just have a few sample files in a folder and I call one up, modify it, and add the test code.

    Today, I finally got around to trying out templates. Much better! Any code you have can be a template, just put 3 lines at the top and save it into the PB\bin folder with a .pbtpl extension. Here are the 3 lines of code to use at the top of your template file.
    Code:
    1
    .bas
    Any Title - This is displayed in the PB IDE
    Here are four tips for using templates:

    1. They show up in the IDE sorted by the template file name, not by the title you give the template! I like mine in a certain order, so I renamed the files accordingly.

    2. When you load a template, you can't just press Compile to see what happens. You have to make a change to the loaded code (even as simple as pressing a space bar) before the IDE will compile the template code.

    3. The IDE also requires that you save the code to a file before it will compile. I created a file called "_.bas". With that name it will always be at the top of the Save As dialog and is ready-at-hand to select as the file name to be used for saving the modified template code. I treat it like a temp file, never putting anything of value in it and always overwriting it whenever I test new code snippets.

    4. The pipe symbol | is used in a template to tell the IDE where the cursor is to be placed when the template is loaded. However, the IDE doesn't seem to be willing to place a cursor at all depths. So stick with 1-3 indentations and you should be fine.

    I just put the code for 3 template suggestions in the Source Code forum.

    I'd be interested in seeing the templates anyone else has found useful.

    Unless you have discussion about your templates, I suggest you place them in the Source Code forum too.

    My templates can also be found and downloaded on my website at
    http://www.garybeene.com/power/pb-tutor-templates.htm.

  • #2
    Originally posted by Gary Beene View Post
    One of the common tasks I've been doing for months now, as I'm learning PowerBASIC, is typing in test code. I normally just have a few sample files in a folder and I call one up, modify it, and add the test code.

    [/URL].
    Gary,

    You might want to check out Test Driven Development (TDD). This has nothing to do with PB, but programming in general.

    I am working on a xUnit (TDD framework) for PowerBASIC but I don't have it far enough along.

    Comment


    • #3
      Gary, I've just had a look at your templates in the Source Code Forum.

      You may like to consider removing the blocks:

      Dialog New .....
      Control Add .....

      and so on and replace them with your own sub called, for example, CreateDialog( hDlg ).

      This gives a 'cleaner' template. You can also duplicate the function with CreateDialogTest( hDlg ) and use that one for 'tinkering' purposes knowing that if you foul up badly you can revert back to CreateDialog and have another think.

      In the Callback Functions you may like to consider using CB.HNDL instead of hDlg. Oddly, it is best described in the Help file under the upcoming defunct CBHNDL.

      Comment


      • #4
        Hi David,

        Thanks for the ideas.

        And one good? thing about your suggestion of CB.HNDL is that it avoids a global variable. I've gotten into the habit of hDlg being the one always-global variable and using it extensively.

        In a bigger program, with lots of Subs/Functions, I like the global variable so I don't have to pass the handle around as an argument many times. But for the Template, the cb.hndl actually cuts the number of lines (by one), at the cost of 7 keystrokes to 3. Gosh, which version of lazy do I want to be!

        Comment


        • #5
          In my opinion it's always a good idea to pass the window handle around so your templates are "window agnostic".

          As you can only reference CBHDNL or CB.HNDL within the callback function you need to convert them to some sort of variable outside the scope of the callback. I typcially supply them to functions as a passed hDlg local variable.

          I'm not one of those "global variables are evil" type people, but in the case of windows, especially multi window applications, it is always safer to be specific and supply it as a passed local variable instead of a global.
          Last edited by George Bleck; 2 Mar 2009, 08:22 AM.
          <b>George W. Bleck</b>
          <img src='http://www.blecktech.com/myemail.gif'>

          Comment

          Working...
          X