我的程序如何在vb中按数字顺序从文件中读取打印整数 [英] How do print integers my program read from a file in numerical order in vb

查看:55
本文介绍了我的程序如何在vb中按数字顺序从文件中读取打印整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从VB中的.dat文件中控制Console.WriteLine整数,从最大到最小或反之亦然我知道如何在屏幕上获取文件信息,我只需要知道如何更改顺序。



我的尝试:



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:

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

推荐答案

以下是代码应如下所示的示例:

Here is an example of what your code should look like:
' 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


这篇关于我的程序如何在vb中按数字顺序从文件中读取打印整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆