Question

How can I pass the specific value of Array1 to Array2 using VB6? Is it possible to use 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
Was it helpful?

Solution

the problem is with the following lines in your code:

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

what variable type is geting ? is geting an array ?

as adata(i) is a single string (i think), i also think geting is a single string

using UBound() on a single string should give an compile error though ("expected array"), but i have no idea to what your compiler settings are and wether you run the project by pressing ctrl-F5 or just F5

somehow UBound(getting) does probably return 0, which is smaller than the value of i, and therefore your loop wont be executed

advice:

  • please declare all your variables properly
  • each variable declaration should have a type. "dim intA, intB as integer" will make an integer of intB, but intA will be of type variant
  • place breakpoints in your code before you run it, so you know if that part of the code is reached upon execution
  • when you arrive at a breakpoint "watch" the contents of the variables and check if they are what you expect them to be
  • use ctrl-F5 to run the project from within the IDE, do not just use F5

[EDIT]

to copy an array to another array you can loop through the array and copy each element to the new array (make sure you redim the new array to the right size) .. or you can simple copy it:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top