|
|
 |
 |
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
If what you want, like hyperbolic cosecant, is not in Table 3.8, use Table 3.9, which shows you how to calculate other results using the built-in Visual Basic functions. Theres enough math power in Table 3.9 to keep most astrophysicists happy.
Table 3.9 Calculated math functions.
| Function
| Calculate This Way
|
| Secant
| Sec(X) = 1 / Cos(X)
|
| Cosecant
| Cosec(X) = 1 / Sin(X)
|
| Cotangent
| Cotan(X) = 1 / Tan(X)
|
| Inverse sine
| Arcsin(X) = Atn(X / Sqr(-X * X + 1))
|
| Inverse cosine
| Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
|
| Inverse secant
| Arcsec(X) = Atn(X / Sqr(X * X - 1)) + Sgn((X) - 1) * (2 * Atn(1))
|
| Inverse cosecant
| Arccosec(X) = Atn(X / Sqr(X * X - 1)) + (Sgn(X) - 1) * (2 * Atn(1))
|
| Inverse cotangent
| Arccotan(X) = Atn(X) + 2 * Atn(1)
|
| Hyperbolic sine
| HSin(X) = (Exp(X) - Exp(-X)) / 2
|
| Hyperbolic cosine
| HCos(X) = (Exp(X) + Exp(-X)) / 2
|
| Hyperbolic tangent
| HTan(X) = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))
|
| Hyperbolic secant
| HSec(X) = 2 / (Exp(X) + Exp(-X))
|
| Hyperbolic cosecant
| HCosec(X) = 2 / (Exp(X) - Exp(-X))
|
| Hyperbolic cotangent
| HCotan(X) = (Exp(X) + Exp(-X)) / (Exp(X) - Exp(-X))
|
| Inverse hyperbolic sine
| HArcsin(X) = Log(X + Sqr(X * X + 1))
|
| Inverse hyperbolic cosine
| HArccos(X) = Log(X + Sqr(X * X - 1))
|
| Inverse hyperbolic tangent
| HArctan(X) = Log((1 + X) / (1 - X)) / 2
|
| Inverse hyperbolic secant
| HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)
|
| Inverse hyperbolic cosecant
| HArccosec(X) = Log((Sgn(X) * Sqr(X * X + 1) + 1) / X)
|
| Inverse hyperbolic cotangent
| HArccotan(X) = Log((X + 1) / (X - 1)) / 2
|
| Logarithm to base N
| LogN(X) = Log(X) / Log(N)
|
Handling Dates And Times
One of the biggest headaches a programmer can have is working with dates. Handling hours, minutes, and seconds can be as bad as working with pounds, shillings, and pence. Fortunately, Visual Basic has a number of date- and time-handling functions, which appear in Table 3.10you can even add or subtract dates using those functions.
Table 3.10 Visual Basic date keywords.
| To Do This
| Use This
|
| Get the current date or time
| Date, Now, Time
|
| Perform date calculations
| DateAdd, DateDiff, DatePart
|
| Return a date
| DateSerial, DateValue
|
| Return a time
| TimeSerial, TimeValue
|
| Set the date or time
| Date, Time
|
| Time a process
| Timer
|
Theres something else you should knowthe Format$() function makes it easy to format dates into strings, including times. For easy reference, see Table 3.11, which shows how to display the date and time in a stringnote how many ways there are to do this.
Table 3.11 Using Format$() to display dates and times.
| Format Expression
| Yields This on January 1, 2000 at 1:00 A.M.
|
| Format$(Now, m - d - yy)
| 1-1-00
|
| Format$(Now, m / d / yy)
| 1 / 1 / 00
|
| Format$(Now, mm - dd - yy)
| 01-01-00
|
| Format$(Now, ddd, mmmm d, yyy)
| Friday, January 1, 2000
|
| Format$(Now, d mmm, yyy)
| 1 Jan, 2000
|
| Format$(Now, hh:mm:ss mm/dd/yy)
| 01:00:00 01/01/00
|
| Format$(Now, hh:mm:ss AM/PM mm- dd- yy)
| 01:00:00 AM 01-01-00
|
You can also compare dates and times directly. For example, heres how you loop until the current time (returned as a string by Time$) exceeds the time the user has entered in a text box (for example, 15:00:00); when the time is up, the program beeps and displays a message box:
While Time$ < Text1.Text
Wend
Beep
MsgBox ("Times up!")
Warning! Dont use this code snippet for more than an example of how to compare times! The eternal looping while waiting for something to happen is a bad idea in Windows, because your program monopolizes a lot of resources that way. Instead, set up a Visual Basic Timer object and have a procedure called, say, every second.
|