Results 1 to 22 of 22

Thread: [RESOLVED] Detect asci!

  1. #1

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Resolved [RESOLVED] Detect asci!

    Hi I saw somewhere in this forum a post about detecting and outputting the asci for a keypress.... how is that?


    explination:
    If i press "ENTER" then the asci code for ENTER should be returned... as a msgbox for me to read...
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  2. #2
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    MsgBox KeyAscii
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    Ohh wait i forgott some part of the code =)
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  4. #4
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    What do you mean?

  5. #5

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    works perfectly tanks =)
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  6. #6
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    Oh OK. You're welcome.

  7. #7

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    how can i use this in a if statement? so like:
    Code:
    if asci = 113 then
    text.text = text.text & a
    end if

    q = ascii 113...
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  8. #8
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 113 Then
            MsgBox "You Pressed Q!"
        End If
    End Sub

  9. #9

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    what if i use check this from the commandbutton?



    I type in q in a textbox and then press enter

    Code:
    Command1_click
    if asci = 113 then
    'add a to the textbox
    end if
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  10. #10
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Detect asci!

    Is this what you are looking for ?
    Code:
    Private Sub Command1_Click()
      MsgBox "Command button pressed"
    End Sub
    
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii = 13 Then     '~~~ User pressed Enter Key
        Command1.Value = True
      End If
    End Sub
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  11. #11
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    What are you trying to accomplish? If you explain, I might be able to help better. Do you just want to check if "q" exists at all in the textbox? you can use Instr for that.

  12. #12

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    Aight let me say something like enigma!

    If you type Q it will change ure Q to A...

    The user enters a password into the textbox...
    when the user press enter the asci for each char in the word will be checked and replaced with another of choice (from Db later on)

    Hope this explains...
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  13. #13
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    OK so you want to validate it when the user presses enter. Here is one way to do it:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
            Text1.Text = Replace$(Text1.Text, "Q", "A")
        End If
    End Sub

  14. #14
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Detect asci!

    Alternative idea:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii = 13 Then       '~~~ If EnterKey is pressed
      
        Dim i As Long
        Dim Temp As Integer
        Dim strText As String
        
        strText = Text1.Text      '~~~ Storing a copy of the Text in a variable
        
        For i = 1 To Len(strText) '~~~ Looping through each characters
          Temp = Asc(Mid$(strText, i, 1)) '~~~ ASCII value of the character is obtained
          Select Case Temp
            Case 113:
              Temp = 100
            Case 112:
              Temp = 65
            '...etc
            End Select
            Mid$(strText, i, 1) = Chr$(Temp)  '~~~ Replace the character with the new one
        Next i
        Text1.Text = strText          '~~~ Write back to the TextBox
      End If
    End Sub
    ...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  15. #15
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    Yes that would be a better idea if you have many replacements to make.

  16. #16
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Detect asci!

    vb Code:
    1. Private Cryptobet(25) As Byte
    2.  
    3. Private Sub InitCrypt()
    4. Dim X As Long, Y As Long, bTMP As Byte
    5. Rnd -1 'reset rnd generator
    6. Randomize 5330 'SEED
    7.  
    8. 'assign the alphabet to the array
    9. For X = Asc("a") To Asc("z") 'asc("a") = 97, so subtract that to normalize the values to 0-25
    10.   Cryptobet(X - 97) = X
    11. Next X
    12.  
    13. 'shuffle it
    14. For X = 1 To UBound(Cryptobet) 'loop though the array
    15.   Y = Int(X * Rnd) 'get a random whole number
    16.   If X <> Y Then
    17.     bTMP = Cryptobet(X) 'store one value in tmp var
    18.     Cryptobet(X) = Cryptobet(Y) 'swap direct
    19.     Cryptobet(Y) = bTMP 'swap with temp
    20.   End If
    21. Next X
    22. End Sub
    23.  
    24. Private Function EnCrypt(ByVal strIn As String) As String
    25. Dim bString() As Byte
    26. Dim bNewString() As Byte 'a couple of dynamic byte arrayss
    27.  
    28. bString = StrConv(LCase$(strIn), vbFromUnicode) 'convert BSTR to ascii/byte array
    29. ReDim bNewString(UBound(bString)) 'make a ascii/byte array to store the result
    30.  
    31. For X = 0 To UBound(bString)
    32.   bNewString(X) = Cryptobet(bString(X) - 97) 'basic LUT
    33. Next X
    34. EnCrypt = StrConv(bNewString, vbUnicode) 'convert the ascii array to BSTR(a normal 'as String' type)
    35. End Function
    36.  
    37. 'usage:
    38.  
    39. Private Sub Command1_Click()
    40. InitCrypt
    41. Debug.Print EnCrypt("helloworld")
    42. End Sub

    This doesn't handle anything outside of a-z, and doesn't check for such things(they'll cause an error).

    Could easily be expanded to the entire ascii character set.
    Last edited by FireXtol; Apr 27th, 2010 at 06:38 PM.

  17. #17

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    aight not really what i needed but you all seem to get the point =), I need to check as i press the button... command1 when i press that then check...
    Maybe should use a function or so?
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  18. #18
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Detect asci!

    You could call EnCrypt with Lcase$(Chr$(Keyascii)), and then set Keyascii to the Asc() of the returned value. And/Or just use the array as a LUT.

    Like:
    keyascii = Asc(EnCrypt(Lcase$(Chr$(keyascii))))

    Or:

    keyascii = Cryptobet(Asc(Lcase$(Chr$(keyascii)))-97)

    Tested, and either way works. Just don't try to use a character outside a-z without updating the Cryptobet.

  19. #19

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    well i cant take ure cryptobet as im about to make my own "crypting program" (Not to be a real program only messing around and learning)
    So i only wonder if it would be possible if i made a function maybe called Enigma...
    I call enigma like Enigma text1.text and as my program goes it returns the enigma to an variable or directrly into text2.text... ?

    Would this be possible and if so a little push to get the function working so i call the "detect asci"

    Hope this makes abit sense atleast... Hard to explain

    //Thomas
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

  20. #20
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Detect asci!

    You could do something like this:
    This sub takes a textbox as a parameter and changes the text in it.
    Code:
    Public Sub Enigma(objText As TextBox)
        objText.Text = objText.Text & " modified!"
    End Sub
    
    Private Sub Command1_Click()
        Enigma Text1
    End Sub
    OR:

    This function takes any string, changes it, then returns the value.
    Code:
    Public Function Enigma(ByVal sText As String) As String
        sText = sText & " modified!"
        Enigma = sText
    End Function
    
    Private Sub Command1_Click()
        Text1.Text = Enigma(Text1.Text)
    End Sub

  21. #21
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Detect asci!

    You can always change:

    Code:
    For X = Asc("a") To Asc("z") 'asc("a") = 97, so subtract that to normalize the values to 0-25
      Cryptobet(X - 97) = X
    Next X
    With an unrolled equivalent. Setting each Cyprobet() index manually, just make sure you don't forget any characters.

    Here's the same code, unrolled:

    vb Code:
    1. 'index = ascii value
    2. Cryptobet(0) = 97
    3. Cryptobet(1) = 98
    4. Cryptobet(2) = 99
    5. Cryptobet(3) = 100
    6. Cryptobet(4) = 101
    7. Cryptobet(5) = 102
    8. Cryptobet(6) = 103
    9. Cryptobet(7) = 104
    10. Cryptobet(8) = 105
    11. Cryptobet(9) = 106
    12. Cryptobet(10) = 107
    13. Cryptobet(11) = 108
    14. Cryptobet(12) = 109
    15. Cryptobet(13) = 110
    16. Cryptobet(14) = 111
    17. Cryptobet(15) = 112
    18. Cryptobet(16) = 113
    19. Cryptobet(17) = 114
    20. Cryptobet(18) = 115
    21. Cryptobet(19) = 116
    22. Cryptobet(20) = 117
    23. Cryptobet(21) = 118
    24. Cryptobet(22) = 119
    25. Cryptobet(23) = 120
    26. Cryptobet(24) = 121
    27. Cryptobet(25) = 122
    28.  
    29. 'generated with:
    30. For X = 0 To 25
    31.  Debug.Print "Cryptobet(" & X & ") = " & X + 97
    32. Next X

    You could also shuffle these yourself, avoiding the need to do it with a programming language.

    Good luck.

  22. #22

    Thread Starter
    Hyperactive Member goofan's Avatar
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    296

    Re: Detect asci!

    thanks a bunch =)
    Ill give it a try! If i get stuck i come back here =)
    My hobbies:
    Vb 6.0, Studio 2010, Webbdesign (PHP, Mysql, CSS, Javascript, HTML)

    Programming hobbies:
    Vb 6.0: Work, Vb 2010: Login system to acces internet game, Webbdesign: Creating an advanced Text-based browser-game Called Banner

    Other word:
    Programming a game and an API to the game, while working and learning and
    P.S. I am still a basic programmer so i listend to every advice i get

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