Results 1 to 2 of 2

Thread: Passing Array Names

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    California
    Posts
    115
    Ok, Ill try and explain this without sounding like a retard.

    I have a function that I call that has a select statement inside it which can range from 0 to 12, one of the values of the function will be a number between 0 to 12, in each case statement, there is:
    Code:
    Dim MyArray() as String
    Dim MyArray2() as String
    ---------------------------------------------------------
    Function LoadMyArrays(Type, IntText As String, Flag As Integer)
    Dim strItems() As String
    Dim i As Integer
    Dim MyString As String
    MyString = IntText
    strItems = Split(MyString, vbCrLf)
    Case 0
     ReDim MyArray(UBound(strItems)) As String
         
         For i = 0 To UBound(strItems)
            MyArray(i) = strItems(i)
            
        If Flag = 1 Then
        retval = Split(MyArray(i), ",")
            For j = 0 To UBound(retval)
                If j = 0 Then
                 Set list_item = Form9.ListView1.ListItems.Add(, , retval(j))
                Else
                list_item.SubItems(1) = retval(j)
                End If
                Next j
        End If
        Next
    
    Case 1
     ReDim MyArray2(UBound(strItems)) As String
         
         For i = 0 To UBound(strItems)
            MyArray2(i) = strItems(i)
            
        If Flag = 1 Then
        retval = Split(MyArray2(i), ",")
            For j = 0 To UBound(retval)
                If j = 0 Then
                 Set list_item = Form9.ListView1.ListItems.Add(, , retval(j))
                Else
                list_item.SubItems(1) = retval(j)
                End If
                Next j
        End If
        Next
    as you can see, each case statement is basiclly alike, cept its a different array thats being redim'd and loaded with values

    Now, to the question, would it be possible to get rid of the case statement and just pass in a arrayname, possible code

    Code:
    Dim MyArray() as String
    Dim MyArray2() as String
    ------------------------------------------------
    Call LoadMyArrays(MyArray, "some,text,here", 0)
    ------------------------------------------------
    Function LoadMyArrays(MyArrayName, IntText As String, Flag As Integer)
    Dim strItems() As String
    Dim i As Integer
    Dim MyString As String
    MyString = IntText
    strItems = Split(MyString, vbCrLf)
    
    ReDim MyArrayName(UBound(strItems)) As String
     'do all the rest of the stuff above
    I've tried several different ways with no avail.

    Any help would be great, if you're confused, ignore me

    Thanks.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Since your using the Split function I assume you have VB6.
    I've tried the following without any problems.
    Code:
    Private MyArray() As String
    
    Public Function LoadMyArray(Arr() As String, sText As String)
        Dim sItems() As String
        Dim i%, iCount%
        
        sItems = Split(sText, vbCrLf)
        iCount = UBound(sItems)
        ReDim Arr(iCount)
        For i = 0 To iCount
            Arr(i) = sItems(i)
        Next
    End Function
    
    Private Sub Command1_Click()
        Dim sText As String
        Dim i%, iCount%
        Open "c:\winnt\javainst.log" For Input As #1
        sText = Input(LOF(1), 1)
        Close #1
        LoadMyArray MyArray, sText
        iCount = UBound(MyArray)
        MsgBox iCount
        For i = 0 To iCount
            MsgBox MyArray(i)
        Next
    End Sub
    Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width