Word Document Properties


Part II: Learning the Ropes



Download 8,82 Mb.
Pdf ko'rish
bet94/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   90   91   92   93   94   95   96   97   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Part II: Learning the Ropes 
09_046500 ch04.qxp 12/5/06 5:54 PM Page 98


Using scientific values for math calculations
VBA provides a number of math functions normally used for scientific calcu-
lations. You can use the 
Atn

Cos

Sin
, and 
Tan
functions for trigonometric
calculations. The 
Abs
and 
Sgn
functions help you work with the sign of a
number. Listing 4-11 shows some of the math functions in action.
Listing 4-11
Performing Scientific Calculations
Public Sub ScientificCalcs()
‘ Define an input value.
Dim MyInt As Integer
MyInt = 45
‘ Create an output string.
Dim Output As String
‘ Display the trigonometric values for a 45 degree
‘ angle.
MsgBox “The original angle is: “ + CStr(MyInt) + _
vbCrLf + “Arctangent is: “ + CStr(Atn(MyInt)) +
_
vbCrLf + “Cosine is: “ + CStr(Cos(MyInt)) + _
vbCrLf + “Sine is: “ + CStr(Sin(MyInt)) + _
vbCrLf + “Tangent is: “ + CStr(Tan(MyInt)), _
vbOKOnly, _
“Trigonometric Values”
‘ Change the sign of the number using Sgn and Int.
‘ Add the value to Output each time.
Output = “The sign of 0 is: “ + CStr(Sgn(0))
MyInt = -45
Output = Output + vbCrLf + _
“The sign of “ + CStr(MyInt) + “ is: “ + _
CStr(Sgn(MyInt))
MyInt = Abs(MyInt)
Output = Output + vbCrLf + _
“The sign of “ + CStr(MyInt) + “ is: “ + _
CStr(Sgn(MyInt))
MsgBox Output, vbOKOnly, “Using Sgn and Abs”
End Sub
The code begins by defining an input value. The VBA documentation leads
you to believe that you can use a 
Double
only as input to the trigonometric
functions. This example shows that you can use any numeric type as long as
the value that it contains is correct. The code builds an output string for the
first message box by using the various trigonometric functions.
The second portion of the example begins by showing the output of the 
Sgn
function when you supply a value of 
0
. The output is 
0
to show that the
number is neither positive nor negative. The input value is set to a negative
99

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   90   91   92   93   94   95   96   97   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish