如何在数组的每个循环中使用a? [英] How can I use a for each loop on an array?
本文介绍了如何在数组的每个循环中使用a?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串数组:
Dim sArray(4) as String
我正在遍历数组中的每个字符串:
I am going through each String in the array:
for each element in sarray
do_something(element)
next element
do_something
以字符串作为参数
我在将元素作为字符串传递时遇到错误:
I am getting an error passing the element as a String:
ByRef参数不匹配
ByRef Argument Mismatch
我应该将元素转换为String还是什么?
Should I be converting the element to a String or something?
推荐答案
元素需要为变体,因此不能将其声明为字符串.只要您将其传递给ByVal,您的函数就应该接受一个变体(如果它是一个字符串).
Element needs to be a variant, so you can't declare it as a string. Your function should accept a variant if it is a string though as long as you pass it ByVal.
Public Sub example()
Dim sArray(4) As string
Dim element As variant
For Each element In sArray
do_something (element)
Next element
End Sub
Sub do_something(ByVal e As String)
End Sub
另一种选择是在传递变体之前将其转换为字符串.
The other option is to convert the variant to a string before passing it.
do_something CStr(element)
这篇关于如何在数组的每个循环中使用a?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文