170 likes | 278 Views
情報基礎 B Lecture 8. Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information Systems. PROGRAMMING VBA DATA TYPE, IF-THEN-ELSE. Data type (Numeric). Data type (Others). Variables. A box to store a value
E N D
情報基礎BLecture 8 Takeshi TokuyamaTohoku University Graduate School of Information SciencesSystem Information SciencesDesign and Analysis of Information Systems
Variables • A box to store a value • Variable declaration • e.g. prepare a box “x” to store integer value • Dim x As Integer • Declare a Integer type variable “x” • Dim name As String • Declare a String type variable “name” x name
Variables (Integer and String) and Data IO (InputBox and MsgBox)
“IF” in Excel Function • Branch with “TRUE” or “FALSE” • IF(logical_test, value_if_true, value_if_false) String with “” or just numbers Logical formula or Cell number
“IF” in Excel Function • Grading program in previous lecture • Pass if score is more than 60, fail otherwise • D16 = IF(A1>=60, “Pass”, “Fail”) TRUE >=60 Pass FALSE Fail
If - Then - Else in VBA TRUE logical_test Action1 FALSE Action2 If logical_testThen Else End If Action1 Action2
Grading Program • Grade score if it is Pass or Fail • Pass if score is more than 60, fail otherwise TRUE >=60 Pass FALSE Fail
Nesting “IF” in Excel Function TRUE A >=90 FALSE TRUE B >=80 FALSE TRUE C >=70 FALSE TRUE D >=60 FALSE F
Nesting “IF” in Excel Function • Grade • A 100 > Score >= 90 • B 90 > Score >= 80 • C 80 > Score >= 70 • D 70 > Score >= 60 • F 60 > Score • =IF(B2>=90, ”A”, • IF(B2>=80, ”B”, • IF(B2>=70, ”C”, • IF(B2>=60, ”D”, “F”))))
If - Then - Else in VBA TRUE logical_test1 Action1 FALSE TRUE logical_test2 Action2 FALSE If logical_test1Then ElseIf logical_test2Then Else End If Action3 Action1 Action2 Action3
Nesting If-Then-Else TRUE A >=90 FALSE TRUE B >=80 FALSE TRUE C >=70 FALSE TRUE D >=60 FALSE F