BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"Optional Parameters in Functions"
, by ghost dancer
Not sure if this is undocumented, but it is certainly difficult to find! Anyway, it shows you how to use optional parameters in your functions!
Code
;Simple demo of using optional parameters in functions. ;By Ghost Dancer ;Although I'm sure this is documented somewhere, it is difficult to find! ;This gives you great flexibility in your coding - I have my own library of generic functions which is used by ;most of my programs. This is great if find when I need to add a param to the function without affecting existing ;code that uses it - I just make the new param an optional one :-) AppTitle "Optional Function Parameters" Graphics 800, 600 textBox("Test 1 - specifying border gap of 10 pixels", 50, 100, 10) textBox("Test 2 - using default value", 50, 200) WaitKey End Function textBox(textString$, x, y, borderGap = 2) ;Note that it is not really optional, we are just supplying a default value ;which gets used if none is specified! ;All params you pass to the function after the optional one(s) must also be optional xPos = x - borderGap - 1 ;specified x position, minus gap, minus actual border yPos = y - borderGap - 1 ;specified y position, minus gap, minus actual border width = StringWidth(textString) + (borderGap * 2) + 2 ;string width, + gap each side, + border each side height = StringHeight(textString) + (borderGap * 2) + 2 ;string width, + gap each side, + border each side Rect xPos, yPos, width, height, False Text x, y, textString End Function
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations