1 / 17

情報基礎 B Lecture 8

情報基礎 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

preston
Download Presentation

情報基礎 B Lecture 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 情報基礎BLecture 8 Takeshi TokuyamaTohoku University Graduate School of Information SciencesSystem Information SciencesDesign and Analysis of Information Systems

  2. PROGRAMMING VBADATA TYPE, IF-THEN-ELSE

  3. Data type (Numeric)

  4. Data type (Others)

  5. 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

  6. Variables (Integer and String) and Data IO (InputBox and MsgBox)

  7. “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

  8. “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

  9. If - Then - Else in VBA TRUE logical_test Action1 FALSE Action2 If logical_testThen Else End If Action1 Action2

  10. Grading Program • Grade score if it is Pass or Fail • Pass if score is more than 60, fail otherwise TRUE >=60 Pass FALSE Fail

  11. Grading Program

  12. Nesting “IF” in Excel Function TRUE A >=90 FALSE TRUE B >=80 FALSE TRUE C >=70 FALSE TRUE D >=60 FALSE F

  13. 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”))))

  14. 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

  15. Grading Program If-Then-Else

  16. Nesting If-Then-Else TRUE A >=90 FALSE TRUE B >=80 FALSE TRUE C >=70 FALSE TRUE D >=60 FALSE F

  17. Grading Program nesting If-Then-Else

More Related