Results 1 to 14 of 14

Thread: Making Cheat Codes

  1. #1
    Guest

    Talking

    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.

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    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
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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

  4. #4
    Guest
    can i ask you guys one thing, Why do you use static to declare a variable instead of dim?

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Using Static to declare variables allow the variable to hold it's data between function calls.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    *bump*

    The first question I ever helped to answer. And nearly three years later, I'm still here
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i'll try and dig up the first question i answered

    ?
    Last edited by da_silvy; Sep 22nd, 2003 at 02:41 AM.

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

  9. #9
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Originally posted by plenderj
    *bump*

    The first question I ever helped to answer. And nearly three years later, I'm still here
    Aww, so proud *wipes tear*

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Where's yours so we can feel proud of you Tom?
    Last edited by manavo11; Sep 22nd, 2003 at 05:12 PM.


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Mine even though I didn't really help out too much. How can I get a custom title?
    Please rate my post.

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    You can't.

    They were discontinued in the Custom Title fire of 2000

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by da_silvy
    You can't.

    They were discontinued in the Custom Title fire of 2000
    I thought you got at 4096 posts...


    Has someone helped you? Then you can Rate their helpful post.

  14. #14
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you do...


    hello humour

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width