Visual Basic Programming Using Excel
description
Transcript of Visual Basic Programming Using Excel
Visual Basic Programming Using Excel
September 12, 2006
What Programming Will Do
• Make a good engineer better
• Make a bad engineer worse by magnifying his/her ineptitude
Common Lies of Programmers
• The program ran fine yesterday and I did not change a thing but now it will not work.
• I used the same program as was given in class, but it does not want to work for me.
• I looked through all of the code 10 times and I am sure that there are no mistakes. Why won’t it run?
Why in the World Would You Need to be able to Program?
2
1
N
i
y i
50 202
1 1k i
y k i
y = 0For k = 1 To 50 Step 1 y1 = 0 For i = 1 To 20 Step 1 y1 = y1 + k + i^2 Next i y = y + y1Next k
Intrinsic Functions in Visual Basic
Absolute Value of x Abs(x)
Arctangent of x Atn(x)
Cosine of x Cos(x)
ex Exp(x)
Natural Log of x Log(x)
Random Number Generator, 0 – 1 Rnd()
Sign of x Sgn(x)
Sine of x Sin(x)
Square Root of x Sqr(x)
Tangent of x Tan(x)
Open up Excel and write a function subroutine which calculates the area of a circle given its diameter.
Before writing the program, listen to the instructor about macro security.
Fully Developed Flow of a Quasi-Incompressible Fluid
x
y
W
H
u u P
x y L
u = 0 at walls
Governing Equations
1
2 2
2
sinh sinh( , ) 1
sinh
2 2, 1 1 , sin ,
nn nn
nn n n
n
n n n
y H yau x y
H
n W n x Pa
W W n W W L
Analytical Solution #1
Intrinsic Functions in Visual Basic
Absolute Value of x Abs(x)
Arctangent of x Atn(x)
Cosine of x Cos(x)
ex Exp(x)
Natural Log of x Log(x)
Random Number Generator, 0 – 1 Rnd()
Sign of x Sgn(x)
Sine of x Sin(x)
Square Root of x Sqr(x)
Tangent of x Tan(x)
Analytical Solution #2
1 1
2 2
2
,
2 21 1 , , sin
n mm n
n m m n
m
m m m
a bu x y
H m m yb
H m H H H