Arrays 如何使用VB6将数组的值传递给另一个数组

Arrays 如何使用VB6将数组的值传递给另一个数组,arrays,vb6,Arrays,Vb6,如何使用VB6将Array1的特定值传递给Array2?是否可以使用If..Else语句 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 wh

如何使用
VB6
Array1
的特定值传递给
Array2
?是否可以使用
If..Else语句

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
选项显式
尺寸s1、s2、s3、s4、s5、s6、s7、s8、s9、s10
整数形式的Dim iPos1、iPos2、iPos3、iPos4、iPos5、iPos6、iPos7、iPos8、iPos9、iPos10
's1..s10是我需要的数据,这是fix,这就是为什么我把它放在变量中
s1=“过期会话数”
s2=“已解析的消息”
s3=“接收到的字节”
s4=“收到的消息”
s5=“已发送字节”
s6=“已发送消息”
s7=“超时事件”
s8=“总解析答案”
s9=“解析的消息总数”
s10=“解析的请求总数
在这一部分中,我让FSO读写一个文件。我不会把我的一些变量放进去,因为这并不重要,也不是问题的一部分
直到ft1.AtEndOfStream
出错时继续下一步
a=ft1.ReadLine
b=a
r=r+1
Text 1.Text=r
z=左(b,1)
'在本部分中,我将解析数据以创建数组
如果不是数字(z),则
adata=拆分(a,“,”)
对于i=0到UBound(adata)
Text3=数据(i)
Text5=i
这部分是我的情况,也是我的问题,因为我不知道该怎么办。
如果Text3“时间戳”和txt_标记=空,则
iPos1=仪表(文本3,s1)
iPos2=仪表(文本3,s2)
iPos3=仪表(文本3,s3)
iPos4=仪表(文本3,s4)
iPos5=仪表(文本3,s5)
iPos6=仪表(文本3,s6)
iPos7=仪表(文本3,s7)
iPos8=仪表(文本3,s8)
iPos9=仪表(文本3,s9)
iPos10=仪表(文本3,s10)
如果iPos1>0或iPos2>0或iPos3>0或iPos4>0或iPos5>0或iPos6>0或iPos7>0或iPos8>0或iPos9>0或iPos10>0,则
格廷=阿达塔(i)
num=i
对于num=i到Ubound(geting)
newArray=geting(num)'此部分我没有从数组中获取任何数据
下一个
ft2.WriteLine文本3
如果结束
如果结束
下一个

问题在于代码中的以下行:

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()会产生编译错误(“预期数组”),但我不知道编译器设置是什么,也不知道是按ctrl-F5还是只按F5来运行项目

不知何故,UBound(get)可能返回0,它小于i的值,因此不会执行循环

建议:

  • 请正确声明所有变量
  • 每个变量声明都应该有一个类型。“dim intA,intB as integer”将成为intB的整数,但intA将是variant类型
  • 在运行代码之前,在代码中放置断点,这样就可以知道执行时是否到达了代码的该部分
  • 当您到达断点时,请“观察”变量的内容,并检查它们是否是您期望的内容
  • 使用ctrl-F5从IDE中运行项目,而不仅仅是使用F5
[编辑]

要将一个数组复制到另一个数组,您可以在该数组中循环并将每个元素复制到新数组中(确保将新数组重新复制到正确的大小)…或者您可以简单地复制它:

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

你一直在问关于大致相同问题的问题…你尝试过什么…你能解释一下你对数组的了解吗?…请编辑你的问题,然后编辑你的问题,解释一下你想用什么方式使用If..Else…因为这完全与数组无关…你知道If..Else和你有什么部分吗g?和的问题:请不要将您自己的问题与您的其他帐户进行投票好的,我将编辑我的问题。请看上面编辑的问题。谢谢。我应该怎么做才能将数组传递到另一个数组?我只需要获取数组及其索引就可以完成这个程序。请帮助我编辑我的答案,并添加一个将数组intA复制到数组INTB的示例。我不认为你必须将数组复制到另一个数组中但是er数组..为什么要这样做?…最好写下程序需要做什么,并在其中添加一些流程图,包括要使用的变量..写在纸上,完成后再写vb6代码