Visual Basic - 在.txt文件中保存和加载一位或多位数字

时间:2015-06-15 09:35:21

标签: visual-studio

对于我的任务,我正在使用视觉基础制作一个球类游戏,玩家可以获得击球点数。我在保存和加载.txt文件中的数字/最高分时遇到问题。到目前为止,我已设法将播放器的名称和高分保存到.txt文件,但它只保存/加载0-9的数字,不允许2位数字。提前致谢。以下是我的代码:

保存到文本文件

   Dim FileNum As Integer

  'if the player's score (lblpoints) is greater than the high score (lblhighscore)

   If lblpoints.Text > lblhighscore.Text Then
        lblnewhigh.Visible = True
        lblhighscore.Text = lblpoints.Text
        lblbestname.Text = lblplyrname.Text

        'to save highscore to txt file

        FileNum = FreeFile()
        FileOpen(FileNum, "score.txt", OpenMode.Output)
        PrintLine(FileNum, lblbestname.Text)
        PrintLine(FileNum, lblhighscore.Text)
        FileClose(FileNum)

    End If

从文本文件加载

Dim FileNum As Integer

    'to fetch the highscore from txt file
    FileNum = FreeFile()
    FileOpen(FileNum, "score.txt", OpenMode.Input)
    lblbestname.Text = LineInput(FileNum)
    lblhighscore.Text = LineInput(FileNum)
    FileClose(FileNum)

0 个答案:

没有答案