vblecture

vblecture - Dr. T.P. Clement CE 3010 class notes Dr. T.P....

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Dr. T.P. Clement CE 3010 class notes In the end we will conserve only what we love. We love only what we understand. We will understand only what we are taught. . Baba Dioum From a 1968 speech given at the general assembly of the International Union for Conservation of Nature in Delhi. Mr. Dioum was born in Dahra, Senegal in 1937. He studied ecology at the Ecole Nationale des Eaux et Forets in Nancy, France where he received a degree in Forestry Engineering. 1 Dr. T.P. Clement CE 3010 class notes Contents Why numerical methods? Problem examples Why programming? Why numerical methods and programming? Why VBA? 2 Dr. T.P. Clement CE 3010 class notes Why Numerical Methods? Many problems in engineering and science cannot be solved in closed (analytical) form Still need a solution So approximate Non linear problems often require numerical solution 3 Dr. T.P. Clement CE 3010 class notes Creating your first VBA code–Your own mini calculator! Create two VBA buttons from the developer tab 4 Dr. T.P. Clement CE 3010 class notes Program Workspace 5 Dr. T.P. Clement CE 3010 class notes Assignment Statements c = a + b means get values of a and b from storage locations, add them, store result in location reserved for c Only one variable permitted left of = a + b = c not allowed But c = c + 2 OK: means take old value of c, add 2 to it, store result in c location 6
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Dr. T.P. Clement CE 3010 class notes Simple Calculator Option Explicit Sub Codeadd_Click() REM add values of a and b to produce result c REM a and b defined within the program REM answer is displayed on the screen along with Dim a As Single, b As Single, c As Single a = Cells(1, 2) b = Cells(3, 2) c = a + b Cells(5, 2) = c End Sub 7 Standard first statement Dr. T.P. Clement CE 3010 class notes Changing the main program name Click properties Right click on button Name of the routine (codeadd) Button name ( ADD) Dr. T.P. Clement CE 3010 class notes Structure of the program Sub Codeadd_Click() REM Code author Dr. Clement REM add values of a and b to produce result c REM a and b defined within the program REM answer is displayed on the screen along with Dim a As Single, b As Single, c As Single a = Cells(1, 2) b = Cells(3, 2) c = a + b Cells(5, 2) = c End Sub Name of the routine ( Codeadd ) Documentation or comments Variable declaration Variable Initializa tion Mathematical operation Printing output Option Explicit Dr. T.P. Clement CE 3010 class notes Comment Lines VBA and other languages permit adding descriptive notes (non executable statements) within program Specify either by REM (reminder) or an apostrophe (‘) to include reference text within VBA Editor will automatically display the comments in green Good idea to label parts of program such as: REM Computes inverse of a matrix (or) Computes inverse of a matrix 10 Dr. T.P. Clement CE 3010 class notes Documentation Important, but often neglected Minimum contents: Your name Purpose of program Method Input/output including units, if used Limitations of program, e.g. only finds real roots
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

vblecture - Dr. T.P. Clement CE 3010 class notes Dr. T.P....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online