introduction to mis1 copyright © 1998-2002 by jerry post introduction to mis appendix 12 visual...

6
Introduction to MIS Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Upload: jeffry-sutton

Post on 04-Jan-2016

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to MIS1 Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Introduction to MIS 1

Copyright © 1998-2002 by Jerry Post

Introduction to MIS

Appendix 12

Visual Basic

Page 2: Introduction to MIS1 Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Introduction to MIS 2

Appendix: Visual Basic Programming Logic

Computations Variables Internal functions

Conditions Loops Input Output

Math functionsAbs Absolute valueAtn Arc TangentCos CosineExp ExponentialFix Returns integer portionInt Converts to integerLog LogarithmRnd Random numberSgn Signum (-1, 0, 1)Sin SineSqr Square rootTan Tangent

String functionsStrComp Compare two stringsLCase, UCase Convert to lowercase or uppercaseLen Find length of a stringFormat Format a stringInStr, Left, LTrimMid, Right, RTrim, Trim Manipulate strings.

Page 3: Introduction to MIS1 Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Introduction to MIS 3

VB: ConditionsIf (condition) Then

statements if true

Else

statements if false

End If

If (Sales > 1000) Then

Bonus = 100

Else

Bonus = 0

End If

Select Case Customer

Case Customer = ‘Corporate’

Discount = 0.05

Case Customer = ‘Government’

Discount = 0.10

Case Else

Discount = 0.01

End Select

Page 4: Introduction to MIS1 Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Introduction to MIS 4

VB: Loops

total = 0For month = 1 To 12

total = total + SalesForMonth(month)Next month

month = 1sales = 0Do Until (sales > 100000)

sales = sales + SalesForMonth(month)month = month + 1

Loop

Page 5: Introduction to MIS1 Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Introduction to MIS 5

VB: Input and OutputCould use: InputBox, MsgBox, and Printer object.

Generally just use data in the application.

In this example, the form collects the data and displays the result.

Page 6: Introduction to MIS1 Copyright © 1998-2002 by Jerry Post Introduction to MIS Appendix 12 Visual Basic

Introduction to MIS 6

VBA: Excel ExampleSub Macro1()' Keyboard Shortcut: Ctrl+Shift+U For Each c In Selection c.Value = PCase(c.Value) Next cEnd Sub

Function PCase(txt)' Convert a text value to proper case Dim i As Integer txt = LCase(txt) Mid(txt, 1, 1) = UCase(Mid(txt, 1, 1)) i = 2 Do While (i > 0) And (i < Len(txt)) i = InStr(i, txt, " ") If (i > 0) And (i < Len(txt)) Then Mid(txt, i + 1, 1) = UCase(Mid(txt, i + 1, 1)) i = i + 1 End If Loop PCase = txtEnd Function

ALTA 143SNOWBASIN 154BRIGHTON 113PARK CITY 115DEER PARK 120SOLITUDE 137

Alta 143Snowbasin 154Brighton 113Park City 115Deer Park 120Solitude 137