My Favourite Functions - Part 1
Dealing with Fonts and Printers
If you want the user to select from a list of fonts, forget API calls and all that rubbish. Remember that the intrinsic 'Printer' object includes a Fonts property. Try adding a ListBox to your Form, then running the following code:
For i = 0 To Printer.FontCount - 1 List1.AddItem Printer.Fonts(i)Next I
You should get a list of all the fonts on your system. You can then set the Font of a Text Box by running something like:
Text1.FontName = List1.Text
In fact, talking about the Printer object don't forget that if you're doing a little basic printing, you can handle it all from within Visual Basic so no need for exporting to Word, HTML files and so on. For more information, look up the 'Printer object' in the Help files. Hope you guys will find this useful!
-- Helen Doubtfire, VB Queen.
Rounding a Number (VB6 Only)
A new function in Visual Basic 6 allows you to round a number up or down.
You can use it like this:
MsgBox Round(Number, NumberOfDigitsAfterDecimalPoint)
MsgBox Round(3.5, 0)
Returns 4. Beware that:
MsgBox Round(3.45, 1)
Returns 3.4, which is clearly incorrect. So the Round function is buggy beyond 1 digit after the decimal point. You have been warned!
-- Val Benetton.
Reverse a String (VB6 Only)
You can reverse a string in Visual Basic 6 using the StrReverse() function.
Here's an example:
This returns "!olleH".
-- MiniMonkey from Somewhere Touching the Big Pond.
That's all for this week - surf back to VB-World next week when I'll be uncovering another array of little known, but oh-so-useful, Visual Basic tips and tricks.
Page 4 of 4