Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how would I Console.WriteLine Integers from a .dat file in VB, from greatest to smallest or vise versa I know how to get the file info on screen, I just need to know how to change the order.

What I have tried:

VB
Imports System.IO
Module Module1


    Sub Main()
        Dim readFromFile As StreamReader
        Dim FileName1 As String

        FileName1 = "C:\Documents and Settings\Administrator\Desktop\Anthony\Week 11 Homework\File Read and Display\Data\numbers.dat"


        readFromFile = File.OpenText(FileName1)
        If File.Exists(FileName1) Then
                Do Until readFromFile.EndOfStream
                Console.WriteLine(readFromFile.ReadLine())
                Loop
        Else
            Console.WriteLine("File Could not be found. Exiting program!")
        End If
        Console.WriteLine("Press When you are Finished press any key to exit.")
        Console.ReadKey()
        readFromFile.Close()
    End Sub
End Module
Posted
Updated 7-Mar-16 12:47pm

1 solution

Here is an example of what your code should look like:
VB
' declare an empty array
...
    readFromFile = File.OpenText(FileName1)
    If File.Exists(FileName1) Then
        Do Until readFromFile.EndOfStream
            ' add the next value to the array
        Loop
        ' Sort the array
        ' for each value in array
             ' print value
        ' end of loop 'for each'
    Else
 
Share this answer
 
v3
Comments
Sascha Lefèvre 7-Mar-16 19:03pm    
+5
Patrice T 7-Mar-16 19:15pm    
Thank you
Matt T Heffron 7-Mar-16 19:16pm    
+5
Patrice T 7-Mar-16 19:18pm    
Thank you too.
Member 12312671 8-Mar-16 17:09pm    
OK, I know the syntax to make an array. By add the next value I think you mean to add each read from fileName1 to array as a value, if I understand correctly. Now the only thing I'm unsure of is the "sort" what would the syntax for that look like, I've never made anything out of order sort (This is my first time working with arrays).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900