Here is what I have in my password form.
Public Class PassCreate
Dim strPass As String
Private Sub btnPassCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassCreate.Click
strPass = txtPasscreate.Text
My.Computer.FileSystem.WriteAllText("C:\Pass.txt", strPass, True)
Me.Hide()
PGS.Show()
End Sub
End Class
What I want is
If
C:\Pass.txt <> exist then
create a password write it to a file C:\Pass.txt
hide form and show main
elseif C:\Pass.txt does exist then
enter password and if it matches C:\Pass.txt
hide this form and show main.

Is it there?
dpua
The following should set the focus to the textbox3 control.
You need to be a little careful about the event that you put it in as later events may trump it and set it to something else.
Public Class Form1
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
TextBox3.Focus()
End Sub
End Class
Geo V
Here is your problem:
swPass.WriteLine(Me.btnPassCreate.Text)
I'm guessing that btnPassCreate is a button, and that the text of the button is "Create." So, when you write the value to your file, all you ever get is "Create." You probably want:
swPass.WriteLine(Me.txtPassCreate.Text)
(The text property of the control where the user is actually entering their password.)
hindi
System.IO.File.Exists will tell you if the file exists.
Jochen Kalmbach
Public Class PassCreate
Private Sub btnPassCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassCreate.Click
'declare a streamwriter variable
Dim swPass As IO.StreamWriter
Try
'create a StreamWriter Object by opening file for append
swPass = IO.File.AppendText("C:\Pass.txt")
'write name on a seperate line in the file
swPass.WriteLine(Me.btnPassCreate.Text)
'close the file
swPass.Close()
'clear the name txtbx and send it the focus
Me.txtPasscreate.Text = ""
Me.txtPasscreate.Focus()
Catch ex As Exception
'handles any errors
MessageBox.Show(ex.Message, "PGS", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
Me.Hide()
PGS.Show()
End Sub
Noxious
Yes ,I was writing the value of the button text to the file and the button text is 'Create',
Obvious when someone points it out.
Firedancer
This showed me how to write text to a file, I do have one more question please, when the form loads how do I get the Text box to have the focus so that it is ready to have the password entered.
phil_h
I've learnt more here in 24hrs than I have using the help section in weeks!
The answer you gave has worked, I don't think it will cause a problem for me in this case as once the password is entered the form is finished with but it is something I will bear in mind for other programs.
Irina!
Why are you opening the file to append Best guess, btnPassCreate.Text is "", and the word 'create' was put in at some point and is not being removed.
avinashraj
If your using 2005/Express then the following will work
Public Class PassCreate
Private Sub btnPassCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassCreate.Click
Try
My.Computer.Filesystem.WriteAllText("C:\Pass.txt", Me.btnPassCreate.Text, False)
'clear the name txtbx and send it the focus
Me.txtPasscreate.Text = ""
Me.txtPasscreate.Focus()
Catch ex As Exception
'handles any errors
MessageBox.Show(ex.Message, "PGS", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
Me.Hide()
PGS.Show()
End