代码如下:
Public vDoc As ObjectPublic Sub RadioFill(ByRef arr() As Object, ByRef byName$)
Dim i%, j% Set vDoc = wbb.Document
For i = 0 To UBound(arr) - 1
If arr(i).Value = True Then
j = i + 1
End If
Next i
For i = 0 To UBound(arr) - 1
If vDoc.getElementsByName(byName)(i).Value = j Then
vDoc.getElementsByName(byName)(i).Checked = True
End If
Next i
End Sub
Private Sub btn_submit_Click()
RadioFill op_use(13), "use"
RadioFill op_area(5), "area"
end Sub其中op_use(13)是我画的13个OptionButton和网页中<input type="radio" value="1" name="use" checked/> aaa<input type="radio" value="2" name="use" /> bbb...对应 op_area(5)也一样
执行时提示在 RadioFill op_use(13), "use" 和 RadioFill op_area(5), "area" 出错信息:编译错误,类型不匹配,缺少数组或用户定义类型请高手帮忙解答!
Public vDoc As ObjectPublic Sub RadioFill(ByRef arr() As Object, ByRef byName$)
Dim i%, j% Set vDoc = wbb.Document
For i = 0 To UBound(arr) - 1
If arr(i).Value = True Then
j = i + 1
End If
Next i
For i = 0 To UBound(arr) - 1
If vDoc.getElementsByName(byName)(i).Value = j Then
vDoc.getElementsByName(byName)(i).Checked = True
End If
Next i
End Sub
Private Sub btn_submit_Click()
RadioFill op_use(13), "use"
RadioFill op_area(5), "area"
end Sub其中op_use(13)是我画的13个OptionButton和网页中<input type="radio" value="1" name="use" checked/> aaa<input type="radio" value="2" name="use" /> bbb...对应 op_area(5)也一样
执行时提示在 RadioFill op_use(13), "use" 和 RadioFill op_area(5), "area" 出错信息:编译错误,类型不匹配,缺少数组或用户定义类型请高手帮忙解答!
解决方案 »
- 装sql2000个人版时出现的问题
- 采集系统
- 求助:搞了几天还没搞定,关于ActiveReport报表横打的问题
- 请教如何动态地改变文本框的大小
- 谁又背景音乐的代码???
- 关于TCP/IP数据通信的问题
- 数据库连接问题,请帮忙!
- 用VB如何获得拔号网络连接后所获得的动态IP地址?
- 如何给ListView控件设置背景图片?
- 知道在没有人用机器时把机器锁定起来,系统锁或,键盘锁,你是怎么搞定的,能告诉我吗,如有源代码最好 这个问题我问了很多准次,但就是没有一个说得详细一点,说要用hook人,但总得给我一个方法吧,大哥,大姐们,帮帮我吧,我不然去跳楼的
- 调用CommonDialog.ShowSave 出错提示 ActiveX 不能创建对象?
- VB编程资源大全光盘哪位兄弟有?共享下
首先在界面上画了13个OptionButton option1(13)方法:
Sub RadioFill(ByRef arr() As Object)
MsgBox(UBound(arr))
End SubPrivate Sub btn_submit_Click()
RadioFill option1(13)End Sub
RadioFill option1(13) 这样传入的只是option1这一object数组中,序号是13的一个元素...与你过程中的参数类型不一至....
窗体上放了option1(0),option1(1)
然后用ubound(option1)就出错误了,这里必须用控件的ubound属性,option1.ubound。好吧,忍你了。
下来
Sub RadioFill(arr() As OptionButton, byName As String)
Dim i
For i = 0 To arr.ubound
Next i
End Sub
调用Call RadioFill(Option1, "user")立即出错了,“类型不匹配,缺少数组或用户自定义类型”唉,控件数组不是数组嘛不能直接当做数组处理嘛。不是有个Object数据类型,可以引用对象吗,下面程序通过了,不知道能不能达到lz的要求Private Sub Command2_Click()
Dim x() As Object
Debug.Print Option1(0).Container.Name
Debug.Print TypeName(Option1(0))
Debug.Print Option1.ubound
ReDim x(Option1.lbound To Option1.ubound)
For i = 0 To UBound(x)
Set x(i) = Option1(i)
Next i
Call RadioFill(x, "user")
End Sub
Sub RadioFill(arr() As Object, byName As String)
Dim i
For i = 0 To UBound(arr)
Debug.Print TypeName(arr(i))
Debug.Print arr(i).Caption
Next i
End Sub
Option ExplicitSub RadioFill(Opt As Object, Optional Idx As Long = 0)
'参数opt不用声明为数组
Dim i As Long
If Idx > 0 Then
For i = 0 To Idx - 1
Debug.Print Opt(i).Index
Next
Else
Debug.Print Opt.Name
End If
End SubPrivate Sub Command1_Click()
RadioFill Option2(0)
RadioFill Option2, Option2.Count
End Sub
Public vDoc As ObjectPublic Sub RadioFill(ByRef arr As Variant, ByRef byName$)
Dim i%, j% Set vDoc = wbb.Document
For i = 0 To arr.UBound
If arr(i).Value = True Then
j = i + 1
End If
Next i
For i = 0 To arr.UBound
If vDoc.getElementsByName(byName)(i).Value = j Then
vDoc.getElementsByName(byName)(i).Checked = True
End If
Next i
End Sub
Private Sub btn_submit_Click()
RadioFill op_use, "use"
RadioFill op_area, "area"
end SubThank you very much!
Public vDoc As ObjectPublic Sub RadioFill(ByRef arr As Variant, ByRef byName$)
Dim i% Set vDoc = wbb.Document
For i = 0 To arr.UBound
If arr(i).Value = True Then
vDoc.getElementsByName(byName)(i).Checked = True
End If
Next i
End SubPrivate Sub btn_submit_Click()
RadioFill op_use, "use"
RadioFill op_area, "area"
end Sub