Advertisement
TermSpar

Directory

Jan 4th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.11 KB | None | 0 0
  1. Imports System.IO
  2. Public Class frmDirectory
  3.     Public directory As String
  4.     Public theDirect As String
  5.  
  6.     Private Sub frmDirectory_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  7.         My.Settings.Directory = directory
  8.         theDirect = txtDirectory.Text
  9.         Login.Show()
  10.     End Sub
  11.  
  12.     Private Sub frmDirectory_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  13.         directory = My.Settings.Directory
  14.         If My.Settings.Directory = "" Or My.Settings.Directory = "0" Then
  15.             If My.Computer.FileSystem.FileExists("D:\test.txt") Then
  16.                 txtDirectory.Text = "D:\test.txt"
  17.             End If
  18.         Else
  19.             If My.Computer.FileSystem.FileExists(My.Settings.Directory) Then
  20.                 txtDirectory.Text = directory
  21.             Else
  22.                 txtDirectory.Text = ""
  23.             End If
  24.             theDirect = txtDirectory.Text
  25.         End If
  26.     End Sub
  27.  
  28.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  29.         Dim myIPaddress As String
  30.         Dim tmpHostName As String = System.Net.Dns.GetHostName()
  31.         myIPaddress = System.Net.Dns.GetHostByName(tmpHostName).AddressList(0).ToString()
  32.         If My.Computer.FileSystem.FileExists(txtDirectory.Text) Then
  33.             If txtDirectory.Text.Contains(".txt") Then
  34.                 directory = txtDirectory.Text
  35.                 My.Settings.Directory = txtDirectory.Text
  36.                 MsgBox("Directory set to: " & directory, MsgBoxStyle.Information, "Success")
  37.                 Login.Show()
  38.                 Me.Close()
  39.             Else
  40.                 MsgBox("The directory must be a .txt file", MsgBoxStyle.Critical, "Error")
  41.                 txtDirectory.Text = My.Settings.Directory
  42.             End If
  43.         Else
  44.             MsgBox("The file directory you have entered was not found", MsgBoxStyle.Critical, "Error")
  45.             txtDirectory.Text = My.Settings.Directory
  46.         End If
  47.         If My.Computer.FileSystem.ReadAllText(My.Settings.Directory).Contains(myIPaddress) Then
  48.         Else
  49.             frmCreate.Show()
  50.             Me.Close()
  51.             Login.Close()
  52.         End If
  53.     End Sub
  54.  
  55.     Private Sub txtDirectory_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtDirectory.KeyDown
  56.         If e.KeyCode = Keys.Enter Then
  57.             Button1.PerformClick()
  58.         End If
  59.     End Sub
  60.  
  61.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
  62.         Dim SFD As New SaveFileDialog
  63.         Dim sv As String
  64.         SFD.Filter = "(*.txt)|*.txt"
  65.         SFD.ShowDialog()
  66.         sv = SFD.FileName
  67.         Dim sw As New StreamWriter(sv)
  68.         sw.Write("")
  69.         sw.Close()
  70.         txtDirectory.Text = SFD.FileName
  71.     End Sub
  72.  
  73.     Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  74.         Dim ofd As New OpenFileDialog
  75.         ofd.Filter = "(*.txt)|*.txt"
  76.         ofd.ShowDialog()
  77.         txtDirectory.Text = ofd.FileName
  78.     End Sub
  79. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement