Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm making a login screen that will be able to check to see if a file exists and throw an error message. The problem is that if I use (<> = True), even if the file does not exist it throws the error message. If I use just (= True) it does not throw error message at all. Below is the code I'm using. Thanks in advance.
VB
Private Sub btnCreateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateUser.Click
        Dim namefile As String
        namefile = txtCUserName.Text
        If namefile = "" Then
            MsgBox("Please Enter A Username")
            txtCPassword.Focus()
        Else : If txtCPassword.Text = "" Then
                MsgBox("Please Enter A Password")
            Else : If My.Computer.FileSystem.DirectoryExists("C:\AccountUsers\") Then
                Else
                    MkDir("C:\AccountUsers\")
                End If
            End If
        End If
        If My.Computer.FileSystem.FileExists("/txtCUserName.txt") <> True Then
            MsgBox("Account Already Exists, Use A Different Username Or Login", MsgBoxStyle.Information)
            txtCUserName.Text = ""
            txtCPassword.Text = ""
            txtCUserName.Focus()
        Else
            FileOpen(1, "C:\AccountUsers\" + namefile + ".txt", OpenMode.Output, OpenAccess.Write)
            PrintLine(1, txtCUserName.Text)
            PrintLine(1, txtCPassword.Text)
            FileClose(1)
            txtCUserName.Text = ""
            txtCPassword.Text = ""
            txtCUserName.Focus()
        End If
    End Sub
Posted

First, you should specify the entire qualified path when you're doing something like this., Second, try this:

VB
If My.Computer.FileSystem.FileExists("/txtCUserName.txt") Then
...
else
...
end if
 
Share this answer
 
Comments
Dalek Dave 22-Nov-10 11:14am    
Good Call, John.
Get ride of the forward slash ("/") in the FileExists parameter and lose the "<> True" part entirely.

What is this? You're writing the users name and password into a text file in clear text?? Security doesn't seem to be a worry if you're doing this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900