Dim a 1 to a 2 as Dim

  • Slides: 18
Download presentation

数组的定义 Dim 数组变量名(a 1 to a 2) as 元素的类型 Dim result(3) as string 表示定义了:

数组的定义 Dim 数组变量名(a 1 to a 2) as 元素的类型 Dim result(3) as string 表示定义了: result(0)、result(1)、result(2)、result(3)

复习:过程(局部)变量与窗体变量 过程变量 窗体变量 作用范围 过程内 整个窗体 定义位置 过程内部 过程外部,窗体上方 例子 Sub command 1_click() Dim

复习:过程(局部)变量与窗体变量 过程变量 窗体变量 作用范围 过程内 整个窗体 定义位置 过程内部 过程外部,窗体上方 例子 Sub command 1_click() Dim a As integer a=a+1 End Sub command 2_click() Dim a As integer a=a+2 End Sub Dim a As integer Sub command 1_click() a=a+1 End Sub command 2_click() a=a+2 End Sub 连续 2次单击 Command 1 A的值为 2 单击一次 Command 1 再单击一次 Command 2 A的值为 3

求所有的正数和 使用DO循环 结果输出在label 1中。 s=0 n=1 Do While n <= 500 If i(n) >

求所有的正数和 使用DO循环 结果输出在label 1中。 s=0 n=1 Do While n <= 500 If i(n) > 0 Then s = s + i(n) n=n+1 Loop Label 1. Caption = "所有正数和:" & s

统计正数的个数 使用DO循环 结果输出在label 1中。 s=0 n=1 Do While n <= 500 If i(n) >

统计正数的个数 使用DO循环 结果输出在label 1中。 s=0 n=1 Do While n <= 500 If i(n) > 0 Then s = s + 1 n=n+1 Loop Label 1. Caption = "正数的个数: "&s

参考代码 Dim s As Double, x As Double s=0 For n = 1 To

参考代码 Dim s As Double, x As Double s=0 For n = 1 To 640 s = s + i(n) Next x = x / 640 s=0 For n = 1 To 640 s = s + (i(n) - x) ^ 2 Next Label 1. Caption = "方差为:" & s / 640