界面设计: 计算运费 第五章选择结构程序设计 基本运费 Textl 货物重量 Text2 运输距离 Text3 计算运费 Label4 Command1 193 16
第五章选择结构程序设计 16 界面设计: Text1 Text2 Text3 Label4 Command1
代码设计: Private Sub Command1 ClickO 第五章 Price Val(Text1.Text) 输入基本运费 Weight Val(Text2.Text) '输入货物重量 distance Val(Text3.Text) '输入运输距离 选择结构程序设计 '根据不同的运输距离distancei计算折扣 If distance 250 Then Discount =0 Elself distance >=250 And distance 500 Then Discount 0.02 Elself distance >=500 And distance 1000 Then Discount 0.05 17
第 五 章 选 择 结 构 程 序 设 计 17 代码设计: Private Sub Command1_Click() Price = Val(Text1.Text) ' 输入基本运费 Weight = Val(Text2.Text) ' 输入货物重量 distance = Val(Text3.Text) ' 输入运输距离 ' 根据不同的运输距离distance计算折扣 If distance < 250 Then Discount = 0 ElseIf distance >= 250 And distance < 500 Then Discount = 0.02 ElseIf distance >= 500 And distance < 1000 Then Discount = 0.05
ElseIf distance >=1000 And distance 2000 Then Discount 0.08 ElseIf distance >2000 And distance 3000 Then 五章 Discount =0.1 Else Discount =0.15 择结构程序设计 End If 计算总运费 Freight=Price*Weight*distance*(1 Discount) "输出总运费 Label4.Caption Format(Freight,"0.00") End Sub 18
第 五 章 选 择 结 构 程 序 设 计 18 ElseIf distance >= 1000 And distance < 2000 Then Discount = 0.08 ElseIf distance >= 2000 And distance < 3000 Then Discount = 0.1 Else Discount = 0.15 End If ' 计算总运费 Freight=Price*Weight*distance*(1 - Discount) ' 输出总运费 Label4.Caption = Format(Freight, "0.00") End Sub