1

VISUAL BASIC: You know how you can make your own settings in your program setting/properties, well I made a register system for a software. You register by entering a password and username then pressing 'Register' to save the username and password to My.Settings.Username and My.Settings.Password using My.Settings.Save().

The code: My.Settings.Username = TextBox1.Text My.Settings.Password = TextBox2.Text My.Settings.Save() This all works perfectly but how can I prevent the user from changing it again.

This is my code so far:

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    Dim res As MsgBoxResult
    If Not My.Settings.Username = String.Empty And
       My.Settings.Password = String.Empty Then
        MsgBox("You have registered a WCUE account, please use 'CHANGE PASSWORD' in 'Settings' to do so.", MsgBoxStyle.Exclamation, "Not possible.")
    ElseIf TextBox1.Text = String.Empty Or
        TextBox2.Text = String.Empty Then
        MsgBox("Don't press the register button if the text boxes are empty!", MsgBoxStyle.Critical, "Fill all required fields please.")
    Else
        If TextBox1.Text = My.Settings.Username And
            TextBox2.Text = My.Settings.Password Then
            MsgBox("If you are trying to log in then press the 'Log-in' text below the register button!", MsgBoxStyle.Exclamation, "You have already registered!")
        Else
            res = MsgBox("Register a WCUE account?", MsgBoxStyle.YesNo, "Create")
            If res = MsgBoxResult.Yes Then
                My.Settings.Username = TextBox1.Text
                My.Settings.Password = TextBox2.Text
                My.Settings.Save()
                MsgBox("You can now login to WCUE and set the time limit on this user!", MsgBoxStyle.Information, "YEAH - Register successful!")
            ElseIf res = MsgBoxResult.No Then
                MsgBox("You should register as quick as possible before someone unauthorized sets a password!!", MsgBoxStyle.Exclamation, "Suit yourself.")
            End If
        End If
        Exit Sub
    End If
End Sub

The FIRST if statement is what I am having trouble with, I tried to check if My.Settings.Username and My.Setting.Password contains a value (string) which should be the username and password, if it does not then you can register but if it does contain a value then it tells you that someone has already registered. Nothing happens? I hope this is clear enough, please help!

atRM
  • 11
  • 3
  • Don't just read your code. Debug it. Place a breakpoint at the top of that code (F9) and then, when execution breaks at that line, step through the code line by line (F10). At each step, you can use the Autos, Locals, Watch and Immediate windows to evaluate variables, properties and other expressions to compare the actual state of the app to what you expect. As soon as reality differs from expectation, then you have something to investigate. You should likely be able to fix the issue yourself then but, if not, at least you can give us a proper description of the issue. – jmcilhinney Dec 28 '14 at 05:23

1 Answers1

0

I ~think~ this is what you're trying to do...

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    If My.Settings.Username <> String.Empty AndAlso My.Settings.Password <> String.Empty Then
        MsgBox("You have registered a WCUE account, please use 'CHANGE PASSWORD' in 'Settings' to do so.", MsgBoxStyle.Exclamation, "Not possible.")
    Else
        If TextBox1.Text = String.Empty OrElse TextBox2.Text = String.Empty Then
            MsgBox("Don't press the register button if the text boxes are empty!", MsgBoxStyle.Critical, "Fill all required fields please.")
        Else
            Dim res As MsgBoxResult
            res = MsgBox("Register a WCUE account?", MsgBoxStyle.YesNo, "Create")
            If res = MsgBoxResult.Yes Then
                My.Settings.Username = TextBox1.Text
                My.Settings.Password = TextBox2.Text
                My.Settings.Save()
                MsgBox("You can now login to WCUE and set the time limit on this user!", MsgBoxStyle.Information, "YEAH - Register successful!")
            ElseIf res = MsgBoxResult.No Then
                MsgBox("You should register as quick as possible before someone unauthorized sets a password!!", MsgBoxStyle.Exclamation, "Suit yourself.")
            End If
        End If
    End If
End Sub
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40