I'm trying to Write a Console application that will read in an unknown number of integers (up to 100) from data.txt, a comma-delimited text file in the current directory. The program should show the numbers as they are given in the file, and it should also show the numbers in ascending (sorted) order. (Sort by value). The output should look like the figure below.

A sample data file is given, but the testing numbers will be different. This file should be in the default directory (bin).

Add a console.readline() at the end of your code to keep the console window open. Also, be sure to add a console.writeline() at the top to print your name.

However I have no idea what to do to get the text file to load in. So far I have this

Imports System.IO
Module Module1

Sub Main()

    Console.WriteLine("Bubble Sort by Ian Pinholster")

    Dim array(100) As Int16

    Dim n, c, d, swap As Int16

    Console.WriteLine("Enter Number of Elements")

    n = Convert.ToInt16(Console.ReadLine())

    Console.WriteLine("Enter " + n.ToString() + " integers")

    For c = 0 To n - 1
        array(c) = Convert.ToInt16(Console.ReadLine())

    For c = 0 To n - 2

        For d = 0 To n - c - 2

            If (array(d) > array(d + 1)) Then

                swap = array(d)

                array(d) = array(d + 1)

                array(d + 1) = swap
            End If


    Console.WriteLine("Sorted list in ascending order: ")

    For c = 0 To n - 1


End Sub

End Module

Any help on where to go would be awesome

The easiest way is

Dim MyData() As String = System.IO.File.ReadAllLines(MyDataFile)

There are those who would tell you to use a StreamReader but for reasonably sized text files this way is much easier. You don't need to declare any helper objects and you don't have to worry about end-of-file testing. You'll still have to step through each line in MyData and parse the text into separate numbers.

This article has been dead for over six months. Start a new discussion instead.