
基本流程结构.doc
3页一、 IF语句例:判断某年是否闰年闰年的条件是:1、能被4整除,但不能被100整除的年份都是闰年2、能被100整除,又能被400整除的年份是闰年Dim x As IntegerPrivate Sub Command1_Click()x = Val(Text1.Text)If (x Mod 100) Then ‘如果x不能被100整除 If (x Mod 4 = 0) Then ‘如果x能被4整除,但不能被100整除 Text2.Text = "yes" Else ‘如果x不能被4和100整除 Text2.Text = "no" End IfElseIf (x Mod 400 = 0) Then ‘如果x能被100整除,又能被400整除 Text2.Text = "yes"Else Text2.Text = "no"End IfEnd Sub二、 SELECT CASE语句例:从键盘上输入一个学生的学号与考试成绩,然后输出该学生的学号与考试成绩,并根据成绩按下面的规定输出对该学生的评语。
成绩:80~100 60~79 50~59 40~49 0~39评语:Very Good Good Fair Poor FailPrivate Sub Command1_Click()Dim m As Longm = Val(Text2.Text)Select Case m Case 85 To 100 ‘80<=m<=100 Label1.Caption = "Very Good!" Label1.Font.Italic = True Label1.Font.Size = 12 Case 60 To 79 ‘60<=m<=79 Label1.Caption = "Good" Label1.Font.Italic = True Label1.Font.Size = 12 Case 50 To 59 ‘50<=m<=59Label1.Caption = "Fair"Label1.Font.Italic = TrueLabel1.Font.Size = 12 Case 40 To 49 ‘40<=m<=49Label1.Caption = "Poor"Label1.Font.Italic = TrueLabel1.Font.Size = 12 Case 0 To 39 ‘0<=m<=39Label1.Caption = "Fail"Label1.Font.Italic = TrueLabel1.Font.Size = 12End SelectEnd SubPrivate Sub Command2_Click()Command1.SetFocusEndEnd Sub例:个人所得税计算程序收入以800元为起征点,高超过800元以上的部分为经x级数全月应纳税所得额x税率/%1不超过500元52500~20001032000~50001545000~2000020从键盘输入某人一个月的总收入,计算其应交所得税Private Sub Command1_Click()Dim x As Single, y As Singlex = Val(Text1.Text) - 800If x <= 0 Then Text2.Text = "本月不需要交税"Else Select Case x Case Is <= 500 y = x * 0.05 Case Is <= 2000 y = x * 0.1 Case Is <= 5000 y = x * 0.15 Case Is <= 20000 y = x * 0.2 End Select Text2.Text = Str$(y)(或y)End IfEnd SubPrivate Sub Command2_Click()EndEnd Sub。
