I would like so that when the user presses the cobination of: 0-5-1-3 any time during the form it makes a label visible.
Printable View
I would like so that when the user presses the cobination of: 0-5-1-3 any time during the form it makes a label visible.
This should do the trick, just make sure you set the KeyPreview property of your form to True and that you have a Label named Label1 and that it's Visible property is set to false.
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
Static sLast4 As String
If Len(sLast4) = 4 Then
sLast4 = Right(sLast4, 3)
End If
sLast4 = sLast4 & Chr(KeyAscii)
If sLast4 = "0513" Then Label1.Visible = True
End Sub
Well, just remember what the user has entered, and if the cheat code is in the text they've entered, then show the label.
Once the cheat code has been entered, you'd want to clear the buffer so that the label can be shown again at a later stage.
Dim entered as string
Private Sub Form_KeyPress(KeyAscii As Integer)
entered = entered & Chr(KeyAscii)
If (InStr(1, entered, "0513", vbTextCompare) <> 0) Then
entered = ""
Label1.visible = true
End If
End Sub
can i ask you guys one thing, Why do you use static to declare a variable instead of dim?
Using Static to declare variables allow the variable to hold it's data between function calls.
*bump*
The first question I ever helped to answer. And nearly three years later, I'm still here :D
i'll try and dig up the first question i answered :p
:D?
Aww, so proud *wipes tear* :DQuote:
Originally posted by plenderj
*bump*
The first question I ever helped to answer. And nearly three years later, I'm still here :D
Where's yours so we can feel proud of you Tom? :p
Mine even though I didn't really help out too much. How can I get a custom title?
You can't.
They were discontinued in the Custom Title fire of 2000
I thought you got at 4096 posts...Quote:
Originally posted by da_silvy
You can't.
They were discontinued in the Custom Title fire of 2000
you do...
hello humour :(