locked
Need help make code react to textbox input RRS feed

  • Question

  • Im trying to use a sub to grab the text input of a username and password field and using an if statement outside of the sub to register this if the certain conditions are true (i do NOT want the if statements in the sub).

     

    textboxusername = Controls.AddTextBox(330,260) 

    textboxpassword = Controls.AddTextBox(330,320)

    GraphicsWindow.DrawText(330,240,"Username:")

    GraphicsWindow.DrawText(330,300,"Password:")

    buttonlogin = Controls.AddButton("Log in",380,370)

    Controls.ButtonClicked = OnButtonClicked

     

    'load login

     

     Sub OnButtonClicked

      If (Controls.LastClickedButton = buttonlogin) Then

        textboxusernametext = Controls.GetTextBoxText(textboxusername)

        textboxpasswordtext = Controls.GetTextBoxText(textboxpassword)

      EndIf

    EndSub

     

    If ((textboxusernametext = "Administrator") Or (textboxusernametext = "administrator")) And (textboxpasswordtext = 123) Then

      GraphicsWindow.ShowMessage("hey","general")

    EndIf 

     

    Unfortunately, when the username is administrator, and the password 123, the message "hey" does not show up. Help me!

     

    IMPORT: BVZ863

    Sunday, March 13, 2011 10:51 PM

Answers

  • Your problem is the same as last time too. Your If needs to be inside of the Sub OnButtonClicked, or you can use this instead of the if statement:

    While loginvar=0 'do nothing, so you can just wait until loginvar=1
        'do nothing
    EndIf
    GraphicsWindow.Clear()
    'draw next frame

    If statements don't just wait until the statement is true, the compiler just runs through the rest, if it is true or not. The only times it waits is if it reaches the end of the code, or if you use a function like Sound.PlayAndWait() or if you are using an event, like your OnButtonClick, where your code would within the subroutine would wait until you clicked the button.


    ~~AirWaves!!~~
    • Marked as answer by SolidiusWolf Monday, March 14, 2011 6:13 PM
    Monday, March 14, 2011 4:40 PM

All replies

  • Your problem is that you have your if statement at the end, but because the text in the textbox is equal to "" at that time, it won't work. So you need to move the if statement at the end to inside the sub:

    textboxusername = Controls.AddTextBox(330,260)
    textboxpassword = Controls.AddTextBox(330,320)
    GraphicsWindow.DrawText(330,240,"Username:")
    GraphicsWindow.DrawText(330,300,"Password:")
    buttonlogin = Controls.AddButton("Log in",380,370)
    Controls.ButtonClicked = OnButtonClicked
    'load login
    Sub OnButtonClicked
        If (Controls.LastClickedButton = buttonlogin) Then
            textboxusernametext = Controls.GetTextBoxText(textboxusername)
            textboxpasswordtext = Controls.GetTextBoxText(textboxpassword)
            If ((textboxusernametext = "Administrator") Or (textboxusernametext = "administrator")) And (textboxpasswordtext = 123) Then
                GraphicsWindow.ShowMessage("hey","general")
            EndIf
        EndIf
    EndSub

    ~~AirWaves!!~~
    Monday, March 14, 2011 7:49 AM
  • Airwaves, the problem is however that after that message is shown i want the screen to clear and draw the next frame so:

    Sub OnButtonClicked
        If (Controls.LastClickedButton = buttonlogin) Then
            textboxusernametext = Controls.GetTextBoxText(textboxusername)
            textboxpasswordtext = Controls.GetTextBoxText(textboxpassword)
            If ((textboxusernametext = "Administrator") Or (textboxusernametext = "administrator")) And (textboxpasswordtext = 123) Then
                GraphicsWindow.Clear()       

           EndIf
        EndIf
    EndSub

    Then i would like it to skip to another section of code which draws the next frame, but since this would be invalid:

    Sub OnButtonClicked
        If (Controls.LastClickedButton = buttonlogin) Then
            textboxusernametext = Controls.GetTextBoxText(textboxusername)
            textboxpasswordtext = Controls.GetTextBoxText(textboxpassword)
            If ((textboxusernametext = "Administrator") Or (textboxusernametext = "administrator")) And (textboxpasswordtext = 123) Then
                GraphicsWindow.Clear()   

    goto start 'cant use goto in sub

          EndIf
        EndIf
    EndSub

    start:

    'code to draw next screen

    How would i wipe the screen and draw a new frame OUTSIDE of the sub command without the code being activated before the correct username/password is entered?

    I tried this instead:

     loginvar = 0
    textboxusername = Controls.AddTextBox(330,260)
    textboxpassword = Controls.AddTextBox(330,320)
    GraphicsWindow.DrawText(330,240,"Username:")
    GraphicsWindow.DrawText(330,300,"Password:")
    buttonlogin = Controls.AddButton("Log in",380,370)
    Controls.ButtonClicked = OnButtonClicked
    'load login
    Sub OnButtonClicked
        If (Controls.LastClickedButton = buttonlogin) Then
            textboxusernametext = Controls.GetTextBoxText(textboxusername)
            textboxpasswordtext = Controls.GetTextBoxText(textboxpassword)
            If ((textboxusernametext = "Administrator") Or (textboxusernametext = "administrator")) And (textboxpasswordtext = 123) Then
                loginvar = 1
            EndIf
        EndIf
    EndSub

    if (loginvar = 1) then
      GraphicsWindow.Clear()
      'draw next frame
    endif

    This however doesnt work even when loginvar is made to be 1. I hope that makes sense, let me know otherwise.


     


     

    Monday, March 14, 2011 10:36 AM
  • Your problem is the same as last time too. Your If needs to be inside of the Sub OnButtonClicked, or you can use this instead of the if statement:

    While loginvar=0 'do nothing, so you can just wait until loginvar=1
        'do nothing
    EndIf
    GraphicsWindow.Clear()
    'draw next frame

    If statements don't just wait until the statement is true, the compiler just runs through the rest, if it is true or not. The only times it waits is if it reaches the end of the code, or if you use a function like Sound.PlayAndWait() or if you are using an event, like your OnButtonClick, where your code would within the subroutine would wait until you clicked the button.


    ~~AirWaves!!~~
    • Marked as answer by SolidiusWolf Monday, March 14, 2011 6:13 PM
    Monday, March 14, 2011 4:40 PM
  • Thats perfect airwaves! I was trying to redraw the screen outside of the subroutine so that i may use other subroutines in the new frame. This is the perfect solution.

    Monday, March 14, 2011 5:46 PM