My Favourite Functions - Part 1, Page 3
I don't know about you, but it seems strange how few people really use the Format() function. It is very powerful. I particularly like the way it handles dates:
MsgBox Format(Date, "dddd dd mmmm yyyy")
This returns "Monday 03 April 2000", or whatever the current date is. Here are the extra options you can insert in the second argument:
- dddd the day, ie Monday
- ddd the short day name, ie Mon
- dd two-digit day number, ie 05
- d day number, ie 5 or 14
- mmmm the month, ie October
- mmm the short month name, ie Oct
- yyyy the year, ie 2000
- yy the short year, ie 00
- dd/mm/yyyy plain date, ie. 01/03/2000
You can use the following when the first parameter passed is the Time() function, instead of Date():
- am/pm returns am or pm
- hh returns the two-digit hour number, ie 04
- h returns the hour number, ie 4 or 11
- mm - returns the two-digit minute, ie 08 or 32
- m return the minute, ie 8 or 32
- ss returns the two-digit second, ie 04 or 54
- s returns the second, ie 4 or 54
- hh:mm:ss returns a typical time, ie 04:59:03
You can also format numbers and so on using this cool command for instance, you can insert commas at the thousand markers and so on. Check out the Help for more information.
Hope someone finds this useful!
-- Jack Croydon, London.
Ending your Program
If you want to end your program at any time, just type 'End' in your code!
-- Ben Davis (again).
Resetting the Combo Box
If you want to reset the value of a combo box to nothing, try setting its ListIndex property to 1.
-- Ben Davis (yet again ;-).
You can replace text in Visual Basic 6 by using the new Replace() function.
You can use this as such:
Replace(YourString, StringToFind, StringToReplaceItWith)
Here's an example:
MsgBox Replace("This is my test string", "string", "")
This returns the string "This is my test ". Here's another one:
MsgBox Replace("Visual Basic is cool", "cool", "very cool")
This returns "Visual Basic is very cool".
Those with older versions of Visual Basic can use the version of Replace here (http://killervb.com/code/commonbas/Replace.htm.
Page 3 of 4