分支语句

 If  expression1 Then
expressions
ElseIf expression2 Then
expressions
Else
expression
End If

注:VBA中等于号和赋值符号都是"=",但并不会冲突,只有在选择语句中“=”才表示是否相等

示例(交互型)

1、写好程序

2、设置动作 (View-->Toolbars-->Form Controls-->Toggle Design Mode-->Push Button)

3、绑定对应的宏 (Controls-->Events-->Mouse button pressed-->Macro-->想绑定的Macro)

代码

 Option Explicit           ‘设置变量必须先定义才能使用’
Option VBASupport 1 ‘必须写,使得VBA能够在LibreOffice中起作用’
Sub Main
Dim A As Double
Dim B As Double
Dim C As Double
Dim detal As Double
A = ActiveSheet.Cells(,)
B = ActiveSheet.Cells(,)
C = ActiveSheet.Cells(,)
detal = B ^ - * A * C Dim x1 As Double
Dim x2 As Double
ActiveSheet.Cells(,) = ""
ActiveSheet.Cells(,) = ""
If detal > Then
MsgBox("two solution!")
x1 = (-B + sqr(detal)) / ( * A)
x2 = (-B - sqr(detal)) / ( * A)
ActiveSheet.Cells(,) = x1
ActiveSheet.Cells(,) = x2
Elseif detal = Then
MsgBox("one solution!")
x1 = -B / ( * A)
x2 = x1
ActiveSheet.Cells(,) = x1
ActiveSheet.Cells(,) = x2
Else
MsgBox("no solution!")
ActiveSheet.Cells(,) = "no solution"
ActiveSheet.Cells(,) = "no solution"
End if
End Sub Sub clear
ActiveSheet.Cells(,) = ""
ActiveSheet.Cells(,) = ""
ActiveSheet.Cells(,) = ""
ActiveSheet.Cells(,) = ""
ActiveSheet.Cells(,) = ""
End sub

效果图

参考链接:https://youtu.be/TrjUbaqspNg

最新文章

  1. Silverlight5 Tools安装失败及解决方案
  2. 【mongo】drop不释放磁盘空间
  3. mysql的登录密码带特殊符号登录不进去的问题
  4. careercup-数学与概率 7.5
  5. 商务通代码API
  6. Auto-Layout 的各种坑Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
  7. ajax是怎么发请求的和浏览器发的请求一样吗?cookie
  8. POJ 2773 Happy 2006 数学题
  9. python学习第五讲,python基础语法之函数语法,与Import导入模块.
  10. vue 3.0的搭建
  11. docker 命令2
  12. Ubuntu下Tomcat绑定80端口(zz)
  13. javascript的use strict(使用严格模式)
  14. Huawei DHCP 全局配置与接口配置
  15. 深入set和dict
  16. linux下mysql自动备份脚本
  17. PL/SQL集合(一):记录类型(TYPE 类型名称 IS RECORD)
  18. type使用细则
  19. windows phone 手机解锁失败问题
  20. 打通前后端全栈开发node+vue进阶【课程学习系统项目实战详细讲解】(3):用户添加/修改/删除 vue表格组件 vue分页组件

热门文章

  1. spring+mybatis 多数据源整合--temp
  2. node安装升级npm
  3. bzoj4750
  4. B. Simple Molecules
  5. LightOJ 1140 How Many Zeroes? (数位DP)
  6. E20180418-hm
  7. CF1045G AI robots(动态开点线段树)
  8. JZOJ4307. 【NOIP2015模拟11.3晚】喝喝喝
  9. Python while 1 和 while True 速度比较
  10. python之unittest