How to make a text box change text automatically?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 4609 Views - Last Post: 20 March 2013 - 06:09 AM Rate Topic: -----

#16 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 04 March 2013 - 05:02 AM

View PostIronRazer, on 03 March 2013 - 04:32 PM, said:

Here try this. If its not longer that 5 characters it will tell you and if a password longer than 5 characters is entered it changes textbox text to Locked.
    Private Sub btnPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassword.Click
        If txtPassword.Text = "Locked" Then
            MsgBox("You must unlock the safe before trying to change the Password", MsgBoxStyle.Information)

        Else

            Password = InputBox("Set a Password")

            If password.Length <= 5 Then
                MsgBox("Must be longer than 5 characters")
            Else
                If password <> "" Then txtPassword.Text = "Locked"
            End If

        End If
    End Sub




Your code worked!!!! Thanks a lot! The only problem I am having now is even if the user doesnt enter 5 characters and clicks ok the status still changes to locked.. iv amended the code you posted because it wouldnt let me use the else twice for some reason.

    Private Sub btnPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassword.Click
        If txtPassword.Text = "Locked" Then
            MsgBox("You must unlock the safe before trying to change the Password", MsgBoxStyle.Information)

        Else

            Password = InputBox("Set a Password")

            If password.Length <= 5 Then
                MsgBox("Must be longer than 5 characters")
            
                If password <=5> "" Then txtPassword.Text = "Locked"
            End If

    End Sub



As you can see from the above code the else has been removed because it will not let me have it. So then i tried <=5>, it works but then closes the program and brings up an error msg.

I know if that else was there it maybe would work but it does not let me put it there, brings a squiggly line under it.

thanks
Was This Post Helpful? 0
  • +
  • -

#17 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 221
  • View blog
  • Posts: 737
  • Joined: 01-February 13

Re: How to make a text box change text automatically?

Posted 04 March 2013 - 06:13 AM

There must have been an extra (End If) statement in your code if it made a blue line under it. You must copy this exactly line by line. Select and cut the whole button event in your code and remove it. Then copy this code by putting your mouse over the code box and in the upper right corner click copy to clipboard. Then paste it in your program where your button event was. :bigsmile:/>
    Private Sub btnPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassword.Click
        If txtPassword.Text = "Locked" Then
            MsgBox("You must unlock the safe before trying to change the Password", MsgBoxStyle.Information)

        Else

            password = InputBox("Set a Password")

            If password.Length <= 5 Then
                MsgBox("Must be longer than 5 characters")
            Else
                If password <> "" Then txtPassword.Text = "Locked"
            End If

        End If
    End Sub


This post has been edited by IronRazer: 04 March 2013 - 06:15 AM

Was This Post Helpful? 1
  • +
  • -

#18 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 04 March 2013 - 12:45 PM

View PostIronRazer, on 03 March 2013 - 04:32 PM, said:

Here try this. If its not longer that 5 characters it will tell you and if a password longer than 5 characters is entered it changes textbox text to Locked.
    Private Sub btnPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassword.Click
        If txtPassword.Text = "Locked" Then
            MsgBox("You must unlock the safe before trying to change the Password", MsgBoxStyle.Information)

        Else

            Password = InputBox("Set a Password")

            If password.Length <= 5 Then
                MsgBox("Must be longer than 5 characters")
            Else
                If password <> "" Then txtPassword.Text = "Locked"
            End If

        End If
    End Sub



Just tested this code!! Mate..You are a life saver! I really really appreciate your help! Cannot thank you enough!!

It looks like you can spread reputation, ill try adding some for you.

thanks a lot!! Will rep all helpers!

Erm how do you add reputation lol. sorry
Was This Post Helpful? 0
  • +
  • -

#19 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8964
  • View blog
  • Posts: 33,624
  • Joined: 12-June 08

Re: How to make a text box change text automatically?

Posted 04 March 2013 - 12:50 PM

Quote

Erm how do you add reputation lol. sorry

The green plus at the bottom right of any given post.
Was This Post Helpful? 2
  • +
  • -

#20 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 04 March 2013 - 01:40 PM

Thanks for all the help guys i really appreciate it! I have repped all that in this thread.

thanks a lot!
Was This Post Helpful? 0
  • +
  • -

#21 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 08:07 AM

Hey I have a new problem i have literally finished my program just a few touch ups needed. Can you give me a hand please.

 Private Sub BtnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTest.Click

        If Not txtPassword.Text = Password Then MsgBox("Invalid", MsgBoxStyle.Exclamation)
        If txtPassword.Text = Password Then txtStatus.Text = "Unlocked"

        txtpassword.Text = ""

        If txtStatus.Text = "Unlocked" Then btnTest.Text = "Lock safe"


    End Sub



Above is my current code.

Now i want to add to this section if a user selects the test button and the status say unlocked then the safe says locked again. I Tried various ones but i keep contradicting myself when im entering a code. so far this is the code i have tried.

if txtStatus.text= "Unlocked" then btnTest.txt="Locked"


This will not work because Unlocked with never appear then lol.
Was This Post Helpful? 0
  • +
  • -

#22 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 08:23 AM

Looking around i think i need an else in there to loop it.
Was This Post Helpful? 0
  • +
  • -

#23 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 08:35 AM

Yes that would work.

You could even use the buttons .text to determine what condition it is in when it's clicked.

For example, by default the button text is "Locked" and the password .Text is ""

If btnTest.Text = "Lock Safe" then
   btnTest.Text = "Locked"
else
   if txtPassword.Text = Password then
     btnTest.Text = "Lock Safe"
     txtPassword.Text = ""
   else
     MsgBox("Invalid")
   end if
end if


So on running the program, the button shows locked. If you click it and the password doesn't match, you are warned. If it does match, it changes the button to Lock Safe (it's now unlocked)

If you click the button again, it changed to locked and were back to checking for a password.
Was This Post Helpful? 1
  • +
  • -

#24 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 09:14 AM

View PostCharlieMay, on 07 March 2013 - 08:35 AM, said:

Yes that would work.

You could even use the buttons .text to determine what condition it is in when it's clicked.

For example, by default the button text is "Locked" and the password .Text is ""

If btnTest.Text = "Lock Safe" then
   btnTest.Text = "Locked"
else
   if txtPassword.Text = Password then
     btnTest.Text = "Lock Safe"
     txtPassword.Text = ""
   else
     MsgBox("Invalid")
   end if
end if


So on running the program, the button shows locked. If you click it and the password doesn't match, you are warned. If it does match, it changes the button to Lock Safe (it's now unlocked)

If you click the button again, it changed to locked and were back to checking for a password.

Hmm i tried it but it does not work. Maybe i couldnt explain it properly Sorry. Ill try again.

When the user clicks the btnkey which is currently supposed to say "Test". if the text that has been entered in the text box txtpassword matches the variable it changes the btnkey text to "Lock Safe" also changes the txtStatus to saying "Unlocked"

Now if the user clicks the btnkey when it says "Lock safe"(this is the second time after it has changed from "test" to "Lock Safe") that button is supposed to change the txtstatus to saying "locked"....

Confusing as hell! I first thought I should put a loop which says do while, but looking on the internet some people have managed to get it working by having else only.

thanks.
Was This Post Helpful? 0
  • +
  • -

#25 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 09:23 AM

I think if you ran an example of that code to the point where it made sense to you what was happening, you could easily change it to accommodate the rules of the requirements. That example used the button's text.

If you know what each segment is doing you could set your txtStatus accordingly and reword a couple of checks against the button.
If btnTest.Text = "Lock Safe" then
   btnTest.Text = "Locked"
else
   if txtPassword.Text = Password then
     btnTest.Text = "Lock Safe"
     txtPassword.Text = ""
   else
     MsgBox("Invalid")
   end if
end if

So, i was starting with Locked, you were starting with Test
What would you change in there to use Test instead of Locked?
I wasn't using a txtStatus.
Where in there would you put a txtStatus.Text = "Something"?
We know that upon success you want txtStatus.Text = "Unlocked" so where are we successful?
Do we need to do anything to txtStatus.Text if we receive the msgbox?
we know where that is happening.

Hope this doesn't come off in any way other than trying to be helpful in helping you understand the code and where you can manipulate your results.
Was This Post Helpful? 1
  • +
  • -

#26 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 09:50 AM

View PostCharlieMay, on 07 March 2013 - 09:23 AM, said:

I think if you ran an example of that code to the point where it made sense to you what was happening, you could easily change it to accommodate the rules of the requirements. That example used the button's text.

If you know what each segment is doing you could set your txtStatus accordingly and reword a couple of checks against the button.
If btnTest.Text = "Lock Safe" then
   btnTest.Text = "Locked"
else
   if txtPassword.Text = Password then
     btnTest.Text = "Lock Safe"
     txtPassword.Text = ""
   else
     MsgBox("Invalid")
   end if
end if

So, i was starting with Locked, you were starting with Test
What would you change in there to use Test instead of Locked?
I wasn't using a txtStatus.
Where in there would you put a txtStatus.Text = "Something"?
We know that upon success you want txtStatus.Text = "Unlocked" so where are we successful?
Do we need to do anything to txtStatus.Text if we receive the msgbox?
we know where that is happening.

Hope this doesn't come off in any way other than trying to be helpful in helping you understand the code and where you can manipulate your results.


No seriously you been a great help! I know what you are trying to say, i finally got it to work how i wanted to thanks a lot! I changed them around and managed to make it work.


Now i am trying to make it that when i click the Lock safe button again it changes it back to "test" but its not letting me add another else after invalid for some reason keeps bring an error line up and iv also added another end if but it still not working.

Iv learnt quite a bit since starting this. Final thing then iv finished "he says"

This post has been edited by sammy11: 07 March 2013 - 09:51 AM

Was This Post Helpful? 0
  • +
  • -

#27 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 09:55 AM

Post your code you have now
Was This Post Helpful? 1
  • +
  • -

#28 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 10:10 AM

 If btntest.Text = "Lock Safe" Then
            txtStatus.Text = "Locked"
            txtpassword.Text = ""
        Else
            If txtpassword.Text = combination Then
                btntest.Text = "Lock Safe"
                txtStatus.Text = "Unlocked"
                txtpassword.Text = ""
            Else
                MsgBox("Invalid")
            End If
        End If



looking much cleaner now thanks! need to add another else which will change the btntest.text to "test" if i click it after "lock safe"
Was This Post Helpful? 0
  • +
  • -

#29 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 10:14 AM

Ok, so when you click the button when it says Lock Safe you want it to then switch to Test

Look at where you're setting the status to locked. You could probably set a btntest.Text in there somewhere to what you want it to say.
Was This Post Helpful? 1
  • +
  • -

#30 sammy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-March 13

Re: How to make a text box change text automatically?

Posted 07 March 2013 - 10:19 AM

View PostCharlieMay, on 07 March 2013 - 10:14 AM, said:

Ok, so when you click the button when it says Lock Safe you want it to then switch to Test

Look at where you're setting the status to locked. You could probably set a btntest.Text in there somewhere to what you want it to say.


HAHA! added that extra line where you said and it worked!! Thank you very much really really appreciate it!!
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3