如何使用Array1
将Array2
的具体值传递给VB6
?是否可以使用If..Else statement
?
Option Explicit
Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10
Dim iPos1, iPos2, iPos3, iPos4, iPos5, iPos6, iPos7, iPos8, iPos9, iPos10 As Integer
's1..s10 are the data that I need and this is fix that's why I put it in a variable
s1 = "Number of Expired Sessions"
s2 = "Parsed Messages"
s3 = "Received Bytes"
s4 = "Received Messages"
s5 = "Sent Bytes"
s6 = "Sent Messages"
s7 = "Timeout Events"
s8 = "Total Parsed Answers"
s9 = "Total Parsed Messages"
s10 = "Total Parsed Requests
'in this part I us FSO to read and write into a file. I will not put some of my variables because that is not important and not part of a question
Do Until ft1.AtEndOfStream
On Error Resume Next
a = ft1.ReadLine
b = a
r = r + 1
Text1.Text = r
z = Left(b, 1)
'In this part I will parse the data to create an array
If Not IsNumeric(z) Then
adata = Split(a, ",")
For i = 0 To UBound(adata)
Text3 = adata(i)
Text5 = i
'this part is my condition and my question also because I don't know what to do.
If Text3 <> "Time Stamp" And txt_tag = Empty Then
iPos1 = InStr(Text3, s1)
iPos2 = InStr(Text3, s2)
iPos3 = InStr(Text3, s3)
iPos4 = InStr(Text3, s4)
iPos5 = InStr(Text3, s5)
iPos6 = InStr(Text3, s6)
iPos7 = InStr(Text3, s7)
iPos8 = InStr(Text3, s8)
iPos9 = InStr(Text3, s9)
iPos10 = InStr(Text3, s10)
If iPos1 > 0 Or iPos2 > 0 Or iPos3 > 0 Or iPos4 > 0 Or iPos5 > 0 Or iPos6 > 0 Or iPos7 > 0 Or iPos8 > 0 Or iPos9 > 0 Or iPos10 > 0 Then
geting = adata(i)
num = i
For num = i To Ubound(geting)
newArray = geting(num) 'this part I don't get any data coming from array
Next
ft2.WriteLine Text3
End If
End If
Next
答案 0 :(得分:2)
问题在于代码中的以下几行:
geting = adata(i)
num = i
For num = i To UBound(geting)
newArray = geting(num) 'this part I don't get any data coming from array
Next
什么样的变量类型? 正在制作阵列?
因为adata(i)是单个字符串(我认为),我也认为geting是单个字符串
在单个字符串上使用UBound()应该会产生编译错误(&#34;期望数组&#34;),但我不知道你的编译器设置是什么,而且你按下ctrl-运行项目F5或只是F5
某种程度上UBound(获取)可能返回0,它小于i的值,因此你的循环不会被执行
<强>建议:强>
<强> [编辑] 强>
将数组复制到另一个数组,您可以遍历数组并将每个元素复制到新数组(确保将新数组重新调整为正确的大小)..或者您可以简单地复制它:
Option Explicit
Private Sub Form_Click()
Dim intIndex As Integer
Dim intA(10) As Integer
Dim intB() As Integer
For intIndex = 0 To UBound(intA)
intA(intIndex) = (intIndex + 1) ^ 2
Next intIndex
intB = intA
For intIndex = 0 To UBound(intB)
Print CStr(intB(intIndex))
Next intIndex
End Sub