Results 1 to 2 of 2

Thread: Reading from File to Array , plz help

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    10

    Question

    i need some help with reading from a file , with 10 integers to an array with a area of [10]

    i need to read the integers into the array , then sort them from big to small value's and then save to a text file ....

    this is my code , could someone help me with the array code for reading to and from file ...

    Option Explicit
    Dim mArray(10) As Integer
    Dim mFileSysObj As New fileSystemObject



    Dim x As Integer
    Dim mfile As File
    Dim mtxtstream As textstream

    Private Sub Command1_Click()

    Dim s As Integer
    s = mtxtstream.readline
    For x = LBound(mArray) To UBound(mArray)







    End Sub

    Public Sub Load_File()
    Set mfile = mFileSysObj.getfile("d:\data.dat")
    Set mtextstream = mfile.openastextstream(forreading)
    End Sub

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Dim mArray(9) As Integer  'arrays are 0 based so 9 = 10
    Dim x As Integer
    Dim mfile
    Dim mFileSysObj As Object
    Dim mtxtstream As Object
    
    Sub SortMArray(iArray As Variant)
     'sort an array by number
     
         Dim Loop1 As Long
         Dim Loop2 As Long
         Dim lTemp As Long
         
         For Loop1 = UBound(iArray) To LBound(iArray) Step -1
           For Loop2 = LBound(iArray) + 1 To Loop1
    
             If iArray(Loop2 - 1) > iArray(Loop2) Then
               lTemp = iArray(Loop2 - 1)
               iArray(Loop2 - 1) = iArray(Loop2)
               iArray(Loop2) = lTemp
             End If
           Next Loop2
         Next Loop1
       End Sub
    
    
    Private Sub Command1_Click()
    'set the objects
        Set mfile = CreateObject("Scripting.FileSystemObject")
        Set mtxtstream = mfile.openTextFile("c:\data.dat")
            
        Do Until mtxtstream.atendofstream
            
            mArray(x) = mtxtstream.readline
            mArray(x) = Trim(mArray(x))
            x = x + 1
      Loop
      Call SortMArray(mArray)
        For x = LBound(mArray) To UBound(mArray)
           List1.AddItem mArray(x)
        Next
    'set the objects to nothing
        Set mfile = Nothing
        Set mtxtstream = Nothing
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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