Chinaunix首页 | 论坛 | 博客
  • 博客访问: 310148
  • 博文数量: 65
  • 博客积分: 2570
  • 博客等级: 少校
  • 技术积分: 730
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 14:04
个人简介

苦逼房奴一枚

文章分类

全部博文(65)

文章存档

2017年(19)

2016年(5)

2013年(6)

2012年(1)

2011年(3)

2009年(5)

2008年(26)

我的朋友

分类: WINDOWS

2008-08-29 13:12:50

可以转载,转载请著名作者和出处,谢谢,特别鄙视转载后扣上自己名字的哥们
 
 
Imports System.IO
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Atext As String
        Dim blnExist As Boolean
        blnExist = False
        Atext = TextBox1.Text
        Dim i As Integer
        For i = 0 To ListBox1.Items.Count() - 1
            If ListBox1.Items.Item(i) = Atext Then
                MsgBox("error")
                blnExist = True
            End If
        Next i
        If blnExist = False Then
            ListBox1.Items.Add(Atext)
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim saveFileDialog1 As New SaveFileDialog()
        saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        saveFileDialog1.FilterIndex = 1
        saveFileDialog1.RestoreDirectory = True
        If saveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK And (saveFileDialog1.FileName.Length) > 0 Then
            Dim sw As New StreamWriter(saveFileDialog1.FileName)
            For i As Int32 = 0 To ListBox1.Items.Count - 1 Step 1
                sw.WriteLine(ListBox1.Items(i))
            Next
            sw.Close()
            MsgBox("保存完毕")
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Dim strFileName() As String
        Dim OpenFileDialog1 As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog()
        With OpenFileDialog1
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .InitialDirectory = "C:\"
            .Title = "打开文件"
            .Multiselect = False
        End With
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            'strFileName = OpenFileDialog1.FileNames
            Dim sr As New StreamReader(OpenFileDialog1.FileName)
            Dim line As String
            Do
                line = sr.ReadLine()
                If line Is Nothing Then
                    Exit Do
                else
                    ListBox1.Items.Add(line)
                End If
            Loop Until line Is Nothing
            sr.Close()
            MsgBox("读取完毕")
        End If
    End Sub
End Class
阅读(1649) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~