如何使我的按钮保存结果?

时间:2017-03-11 06:58:15

标签: vb.net

我一直在玩学习VB.NET的绳索。我已经开始制作我自己的小型生成器,它只是根据用户在组合框中选择的内容在左侧列表框中生成txt,如图所示。我想配置已保存结果以打开文件对话框,并允许用户在他或她选择的任何目录中的txt文件中说明列表框中已有的内容。请查看下面的VB程序图片以便更好地理解

My VB program

Imports System.IO
Public Class Form1

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ProgressBar1.Value = ProgressBar1.Value + 60 'change this to incrase green bar'
End Sub



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


    ' declare the required variables
    Dim i As Integer = 0
    Dim item As String
    Dim fileReader As StreamReader

    ' set the value min and max values of progress bar


    ' clear the contents of the ListBox1
    ListBox1.Items.Clear()

    ' check whether an item is selected in the combox1
    If ComboBox1.SelectedIndex <> -1 Then
        ' is selected get the item
        item = ComboBox1.SelectedItem.ToString()
    Else
        ' otherwise set item to empty
        item = ""
    End If

    ' depending on the item initialize the fileReader with
    ' with respective file name


    If item.Equals("Random") Then
        fileReader = New StreamReader("world mix.txt")
    ElseIf item.Equals("China") Then
        fileReader = New StreamReader("china.txt")
    ElseIf item.Equals("Korea") Then
        fileReader = New StreamReader("korea.txt")
    ElseIf item.Equals("United Arab Emirates") Then
        fileReader = New StreamReader("ae.txt")
    ElseIf item.Equals("Russia") Then
        fileReader = New StreamReader("ru.txt")
    ElseIf item.Equals("USA") Then
        fileReader = New StreamReader("usa lead.txt")
    ElseIf item.Equals("New Zeland") Then
        fileReader = New StreamReader("nz.txt")
    Else
        fileReader = New StreamReader("names.txt")
    End If

    ' loop till end of the file
    Do While fileReader.Peek() <> -1

        ' check whether the progress is less than 200
        ' if so just increment the progress bar value
        If ProgressBar1.Value <= 100 Then
            ' set the line that is read into the listBox
            ListBox1.Items.Add(fileReader.ReadLine().ToString())

            ' increment the iterator


        End If
    Loop

    ' close the file
    fileReader.Close()



End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    ' when stop button is clicked, just display a pop up message
    MessageBox.Show("The progress bar has stopped!")
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ''This is the save results button button''
End Sub
End Class

0 个答案:

没有答案