Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2010  |  syntax: VB.NET  |  size: 1.49 KB  |  hits: 106  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4.  
  5. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  6.         Dim blOK As Boolean = True
  7.         If txtName.Text.Trim() = String.Empty Then
  8.             epName.SetError(txtName, "You cannot leave this blank.")
  9.             blOK = False
  10.         End If
  11.         If txtURL.Text.Trim() = String.Empty Then
  12.             epURL.SetError(txtURL, "You cannot laeve this blank.")
  13.             blOK = False
  14.         End If
  15.  
  16.         If blOK Then
  17.             sfdData.Filter = "Text Files *.txt|All files *.*"
  18.             sfdData.OverwritePrompt = False
  19.             sfdData.RestoreDirectory = True
  20.             Dim drSave As DialogResult = sfdData.ShowDialog()
  21.             If drSave = DialogResult.OK Then
  22.                 Dim output As String = String.Format("{0}|{1}", txtName.Text, txtURL.Text)
  23.                 Dim filename As String = sfdData.FileName
  24.                 If File.Exists(filename) Then
  25.                     Dim stream_writer As StreamWriter
  26.                     stream_writer = File.AppendText(filename)
  27.                     stream_writer.WriteLine(output)
  28.                     stream_writer.Close()
  29.                 Else
  30.                     Dim stream_writer As StreamWriter
  31.                     stream_writer = File.CreateText(filename)
  32.                     stream_writer.WriteLine(output)
  33.                     stream_writer.Close()
  34.                 End If
  35.             End If
  36.         End If
  37.     End Sub
  38. End Class