利用调试窗口输出结果:
1,利用Debug.Write
m=64
- Dim i, j, k, m As Integer
- For i = 1 To 4
- For j = 1 To 4
- For k = 1 To 4
- Debug.Print("The value of i,j,k is " & i.ToString & " " & j.ToString & " " & k.ToString)
- m += 1
- Next
- Next
- Next
- Debug.Print("输出结束")
- Debug.Write("一共运行了" + m.ToString + "次")
2,利用Debug.Assert(关于变量的一个表达式) 它的结果为boolean型.如果运行结果与你的断言不一致,就会出现"断言失败"
如下:
- Dim i, j, k, m As Integer
- For i = 1 To 4
- For j = 1 To 4
- For k = 1 To 4
- Debug.Print("The value of i,j,k is " & i.ToString & " " & j.ToString & " " & k.ToString)
- m += 1
- Next
- Next
- Next
- Debug.Print("输出结束")
- Debug.Assert(m < 0)
3,利用
try----catch结构捕获异常
- Try
- i = m / 0
- Catch ex As Exception
- MessageBox.Show("错误:" + ex.ToString)
- End Try
4,利用 Err对象
Err.number=53 '文件未找到, 请检查路径名和磁盘驱动器
Err.number=7 '内存不足
Err.number=66 '磁盘满
msgbox(Err.Description)