locked
Does anyone have suggestions on how to go further with this program? RRS feed

  • Question

  • I created this password program to challenge myself and it turned out great. I just wanted to get some suggestions as to what I can do with this. I also wanted to know if I used the Goto correctly. I know a lot of people say Goto shouldn't be used, but I couldn't think of any other way.

    Note: I have removed the file needed to store the password. To make the program work, you need to make a notepad file and write its filepath/name in the program. I marked these areas.

    GraphicsWindow.BrushColor = "Green"
    RegisterButton = Controls.AddButton("Sign Up", 40, 60)
    LogInButton = Controls.AddButton("Log In", 230, 60)
    Controls.SetSize(RegisterButton, 80, 30)
    Controls.SetSize(LogInButton, 80, 30)
    
    GraphicsWindow.BrushColor = "Sienna"
    Dir1 = Shapes.AddText("Make an account today!")
    Dir2 = Shapes.AddText("Already have an account?")
    Shapes.Move(Dir1, 20, 40)
    Shapes.Move(Dir2, 200, 40)
    'Used in Sub Register Only
    x = 0
    y = -1
    z = 0
    'Used in Sub Save Only
    w = 0
    o = -1
    v = 0
    
    Controls.ButtonClicked = ButtonAssignment
    
    Sub ButtonAssignment
      LastClicked = Controls.LastClickedButton
      
      If (LastClicked = RegisterButton) Then
        Sound.PlayClick()
        Shapes.Remove(Dir3)
        Shapes.Remove(Dir4)
        Shapes.Remove(RegisterUserBox)
        Shapes.Remove(RegisterPasswordBox)
        Controls.Remove(Register2Button)
        Shapes.Remove(CongratsText)
        Shapes.Remove(Dir5)
        Shapes.Remove(Dir6)
        Shapes.Remove(UsernameBox)
        Shapes.Remove(PasswordBox)
        Controls.Remove(Login2Button)
        Shapes.Remove(WelcomeText)
        Shapes.Remove(IncorrectText)
        Register()  
        
      ElseIf (LastClicked = LogInButton) Then
        Sound.PlayClick()
        Shapes.Remove(Dir3)
        Shapes.Remove(Dir4)
        Shapes.Remove(RegisterUserBox)
        Shapes.Remove(RegisterPasswordBox)
        Controls.Remove(Register2Button)
        Shapes.Remove(CongratsText)
        Shapes.Remove(Dir5)
        Shapes.Remove(Dir6)
        Shapes.Remove(UsernameBox)
        Shapes.Remove(PasswordBox)
        Controls.Remove(Login2Button)
        Shapes.Remove(WelcomeText)
        Shapes.Remove(IncorrectText)
        Recall()
        Login()
        
      ElseIf (LastClicked = Register2Button) Then
        Sound.PlayClick()
        x = x + 1
        y = y + 2
        z = z + 2
        Account[x]["Username"] = Controls.GetTextBoxText(RegisterUserBox)
        Account[x]["PassWord"] = Controls.GetTextBoxText(RegisterPasswordBox)
        
        For i = 1 To 100
          BlankCheck = File.ReadLine("INSERT HERE", i)
          i = i
          If (BlankCheck = "") Then
            Goto Blank
          EndIf
        EndFor
        Blank:
        If (BlankCheck = "") Then
          File.WriteLine("INSERT HERE", i, Account[x]["Username"])
          File.WriteLine("INSERT HERE", i+1, Account[x]["Password"])
          GraphicsWindow.BrushColor = "Black"
          CongratsText = Shapes.AddText("Congratulations! You have registered!")
          Shapes.Move(CongratsText, 160, 300)
        EndIf
        
      ElseIf (LastClicked = Login2Button) Then
        Sound.PlayClick()
        UsernameInput = Controls.GetTextBoxText(UsernameBox)
        PasswordInput = Controls.GetTextBoxText(PasswordBox)
        
        For i = 1 To 100
          UsernameCheck = Array.ContainsValue(Account[i], UsernameInput)
          PasswordCheck = Array.ContainsValue(Account[i], PasswordInput)
          If (UsernameCheck = "True" And PasswordCheck = "True") Then
            Goto Check
          EndIf
        EndFor 
        Check:
        If (UsernameCheck = "True" And PasswordCheck = "True") Then
          Shapes.Remove(IncorrectText)
          WelcomeText = Shapes.AddText("Welcome to your account! You can't do anything yet. :D")
          Shapes.Move(WelcomeText, 160, 300)
        Else
          GraphicsWindow.BrushColor = "Sienna"
          Shapes.Remove(IncorrectText)
          IncorrectText = Shapes.AddText("Incorrect username or password. Try again.")
          Shapes.Move(IncorrectText, 160, 300)
        EndIf    
      EndIf
    EndSub
    
    Sub Register
      GraphicsWindow.BrushColor = "Sienna"
      Dir3 = Shapes.AddText("Enter a username.")
      Shapes.Move(Dir3, 200, 180)
      Dir4 = Shapes.AddText("Enter a password.")
      Shapes.Move(Dir4, 200, 230)
      GraphicsWindow.BrushColor = "Green"
      RegisterUserBox = Controls.AddTextBox(200, 200)
      RegisterPasswordBox = Controls.AddTextBox(200, 250)
      Register2Button = Controls.AddButton("Register", 250, 275)
    EndSub
    
    Sub Recall
      For i = 1 To 100
        w = w + 1
        o = o + 2
        v = v + 2
        Account[w]["Username"] = File.ReadLine("INSERT HERE", o)
        Account[w]["Password"] = File.ReadLine("INSERT HERE", v)
      EndFor
    EndSub
    
    Sub Login   
      GraphicsWindow.BrushColor = "Sienna"
      Dir5 = Shapes.AddText("Enter your username.")
      Shapes.Move(Dir5, 200, 180)
      Dir6 = Shapes.AddText("Enter your password.")
      Shapes.Move(Dir6, 200, 230)
      GraphicsWindow.BrushColor = "Green"
      UsernameBox = Controls.AddTextBox(200, 200)
      PasswordBox = Controls.AddTextBox(200, 250)
      Login2Button = Controls.AddButton("Login", 250, 275)
    EndSub  


    • Edited by 2020Bob Saturday, October 24, 2015 4:22 AM
    Friday, October 23, 2015 9:28 PM

Answers

  • In stead of  "goto Check" you can use in that position  " i=100". Then the for-loop ends and automatically you are on line  Check: 

    Jan [ WhTurner ] The Netherlands

    Saturday, October 24, 2015 2:34 PM
    Answerer
  • Then you have to do more:   assign the found value of i to another variable, end then set i to 100. In tthe write to file use the name of the other variable.

    Jan [ WhTurner ] The Netherlands

    Saturday, October 24, 2015 3:25 PM
    Answerer

All replies

  • In stead of  "goto Check" you can use in that position  " i=100". Then the for-loop ends and automatically you are on line  Check: 

    Jan [ WhTurner ] The Netherlands

    Saturday, October 24, 2015 2:34 PM
    Answerer
  • Oh, but then if i is 100, then the password is written on line 100 every time. Then only one password can be stored.
    Saturday, October 24, 2015 2:47 PM
  • Then you have to do more:   assign the found value of i to another variable, end then set i to 100. In tthe write to file use the name of the other variable.

    Jan [ WhTurner ] The Netherlands

    Saturday, October 24, 2015 3:25 PM
    Answerer
  • Jan/WhTurner,

    Thank you for all you do!

    Could you email me? It's edprice at Microsoft.

    Thanks!


    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Thursday, November 5, 2015 3:47 AM