Public Class Form2
Public Function FileFolderExists(ByVal strFullPath As String) As Boolean
'Check if file/folder exists_I do not take credits for this
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
On Error GoTo 0
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrg.Click
'Register Requirements
If TextBox1.TextLength < 3 Or TextBox2.TextLength < 3 Or TextBox3.TextLength < 3 Or TextBox4.TextLength < 3 Or TextBox5.TextLength < 3 Then
MsgBox("Mais Letras num dos campos... Mínimo 3") 'Minimum 3 letters
ElseIf TextBox5.Text <> TextBox4.Text Then
MsgBox("Passes não coincidem") 'Portuguese warning meaning "Pass words are not equal"
End If
'Creating the "Main" folder
If FileFolderExists("C:/Manel/") Then
MsgBox("Yh, existe") 'Saying it exists
End If
'If it doesn't
If FileFolderExists("C:/Manel/") = False Then
System.IO.Directory.CreateDirectory("C:/Manel/")
MsgBox("Pasta Criada") 'folder created
End If
If FileFolderExists("C:/Manel/" + TextBox3.Text + ".txt") Then
MsgBox("User Já existe") 'User already exists warning
Form1.btnregist.PerformClick()
Me.Close()
ElseIf FileFolderExists("C:/Manel/" + TextBox3.Text + ".txt") = False Then
MsgBox("Passo 1 Completo") 'step 1 accomplished
System.IO.File.Create("C:/Manel/" + TextBox3.Text + ".txt") 'creating user file
End If
'Writting User info
Dim FILE_NAME As String = ("C:/Manel/" + TextBox3.Text + ".txt")
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.Write("Nome:" + TextBox1.Text + "|||" + "Email:" + TextBox2.Text + "|||" + "User" + TextBox3.Text + "|||" + "Pass:" + TextBox4.Text)
objWriter.Close()
MsgBox("User Criado") 'User created
'Oh btw, in objwriter.write I don't know how to make a line drop so I used ||| How do I make one?
Else
MsgBox("Erro") 'Error warning
End If
End Sub
End Class
The process cannot access the file 'C:\Manel\ahah.txt' because it is being used by another process.
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)