下面这段代码完成,在窗体上用语句添加2个 GroupBox控件,且在每个GroupBox控件中添加4个 RadioButton 控件。
创新互联建站专注于企业网络营销推广、网站重做改版、裕安网站定制设计、自适应品牌网站建设、成都h5网站建设、商城网站建设、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为裕安等各大城市提供网站开发制作服务。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
'添加2个GroupBox
Dim MyGroupBox(2) As GroupBox
For i = 1 To 2
'将一个GroupBox控件加入到Form上
MyGroupBox(i) = New GroupBox
Me.Controls.Add(MyGroupBox(i))
'设置该GroupBox控件的属性
MyGroupBox(i).Height = 240
MyGroupBox(i).Width = 600
MyGroupBox(i).Top = (i - 1) * (240 + 20) + 20
MyGroupBox(i).Left = 20
'修改新加入控件的Text值
MyGroupBox(i).Text = "GroupBox" CStr(i)
Next
'每个GroupBox中添加4个单选按钮
Dim MyRadioButton1(4) As RadioButton
Dim MyRadioButton2(4) As RadioButton
For i = 1 To 4
MyRadioButton1(i) = New RadioButton
Me.Controls.Add(MyRadioButton1(i))
MyRadioButton1(i).Parent = MyGroupBox(1)
'设置该GroupBox控件的属性
MyRadioButton1(i).Height = 20
MyRadioButton1(i).Width = 120
MyRadioButton1(i).Top = (i - 1) * (20 + 20) + 40
MyRadioButton1(i).Left = 20
'修改新加入控件的Text值
MyRadioButton1(i).Text = "RadioButton1_" CStr(i)
Next
For i = 1 To 4
MyRadioButton2(i) = New RadioButton
Me.Controls.Add(MyRadioButton2(i))
MyRadioButton2(i).Parent = MyGroupBox(2)
'设置该GroupBox控件的属性
MyRadioButton2(i).Height = 20
MyRadioButton2(i).Width = 120
MyRadioButton2(i).Top = (i - 1) * (20 + 20) + 40
MyRadioButton2(i).Left = 20
'修改新加入控件的Text值
MyRadioButton2(i).Text = "RadioButton2_" CStr(i)
Next
End Sub
分类: 电脑/网络 程序设计 其他编程语言
问题描述:
我知道能定义一维的,可是可以是二维的吗?
解析:
可以,在标准模块中定义:
要创建动态数组,请按照以下步骤执行:
(如果希望数组为公用数组,则)用 Public 语句声明数组,或者,(如果希望数组为模块级,则)在模块级用 Dim 语句声明数组,或者(如果希望数组为局部数组,则)在过程中用 Static 或 Dim 语句声明数组。给数组附以一个空维数表,这样就将数组声明为动态数组。
ReDim 语句用来定义或重定义原来已经用带空圆括号(没有维数下标)的 Private、Public 或 Dim 语句声明过的动态数组的大小。
例:
标准模块
Option Explicit
Public BL() As String
窗体部分
Option Explicit
Dim i As Integer
Dim j As Integer
Private Sub Command1_Click()
ReDim BL(5, 10) As String
For i = 0 To 2
For j = 0 To 5
BL(i, j) = i ^ 2 + j ^ 2
Next
Next
For i = 0 To 2
For j = 0 To 5
Print BL(i, j)
Next
Next
End Sub
for i =0 to ...
for j =0 to ...
keyarray(i,j)=
next
next
双重循环,赋值和读取一样