|
-
Apr 26th, 2010, 08:45 AM
#1
Thread Starter
Hyperactive Member
[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
-
Apr 26th, 2010, 08:48 AM
#2
Hyperactive Member
Re: Detect asci!
Private Sub Text1_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub
-
Apr 26th, 2010, 08:51 AM
#3
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2010, 08:58 AM
#4
Hyperactive Member
-
Apr 26th, 2010, 09:07 AM
#5
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2010, 09:10 AM
#6
Hyperactive Member
Re: Detect asci!
Oh OK. You're welcome.
-
Apr 26th, 2010, 09:13 AM
#7
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2010, 09:28 AM
#8
Hyperactive Member
Re: Detect asci!
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 113 Then
MsgBox "You Pressed Q!"
End If
End Sub
-
Apr 26th, 2010, 09:31 AM
#9
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2010, 09:38 AM
#10
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,...
-
Apr 26th, 2010, 09:43 AM
#11
Hyperactive Member
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.
-
Apr 26th, 2010, 09:53 AM
#12
Thread Starter
Hyperactive Member
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
-
Apr 26th, 2010, 09:58 AM
#13
Hyperactive Member
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
-
Apr 26th, 2010, 10:02 AM
#14
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,...
-
Apr 26th, 2010, 10:27 AM
#15
Hyperactive Member
Re: Detect asci!
Yes that would be a better idea if you have many replacements to make.
-
Apr 26th, 2010, 06:03 PM
#16
Re: Detect asci!
vb Code:
Private Cryptobet(25) As Byte
Private Sub InitCrypt()
Dim X As Long, Y As Long, bTMP As Byte
Rnd -1 'reset rnd generator
Randomize 5330 'SEED
'assign the alphabet to the array
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
'shuffle it
For X = 1 To UBound(Cryptobet) 'loop though the array
Y = Int(X * Rnd) 'get a random whole number
If X <> Y Then
bTMP = Cryptobet(X) 'store one value in tmp var
Cryptobet(X) = Cryptobet(Y) 'swap direct
Cryptobet(Y) = bTMP 'swap with temp
End If
Next X
End Sub
Private Function EnCrypt(ByVal strIn As String) As String
Dim bString() As Byte
Dim bNewString() As Byte 'a couple of dynamic byte arrayss
bString = StrConv(LCase$(strIn), vbFromUnicode) 'convert BSTR to ascii/byte array
ReDim bNewString(UBound(bString)) 'make a ascii/byte array to store the result
For X = 0 To UBound(bString)
bNewString(X) = Cryptobet(bString(X) - 97) 'basic LUT
Next X
EnCrypt = StrConv(bNewString, vbUnicode) 'convert the ascii array to BSTR(a normal 'as String' type)
End Function
'usage:
Private Sub Command1_Click()
InitCrypt
Debug.Print EnCrypt("helloworld")
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.
-
Apr 27th, 2010, 01:33 AM
#17
Thread Starter
Hyperactive Member
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
-
Apr 27th, 2010, 01:53 AM
#18
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.
-
Apr 27th, 2010, 03:40 AM
#19
Thread Starter
Hyperactive Member
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
-
Apr 27th, 2010, 07:56 AM
#20
Hyperactive Member
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
-
Apr 27th, 2010, 06:44 PM
#21
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:
'index = ascii value
Cryptobet(0) = 97
Cryptobet(1) = 98
Cryptobet(2) = 99
Cryptobet(3) = 100
Cryptobet(4) = 101
Cryptobet(5) = 102
Cryptobet(6) = 103
Cryptobet(7) = 104
Cryptobet(8) = 105
Cryptobet(9) = 106
Cryptobet(10) = 107
Cryptobet(11) = 108
Cryptobet(12) = 109
Cryptobet(13) = 110
Cryptobet(14) = 111
Cryptobet(15) = 112
Cryptobet(16) = 113
Cryptobet(17) = 114
Cryptobet(18) = 115
Cryptobet(19) = 116
Cryptobet(20) = 117
Cryptobet(21) = 118
Cryptobet(22) = 119
Cryptobet(23) = 120
Cryptobet(24) = 121
Cryptobet(25) = 122
'generated with:
For X = 0 To 25
Debug.Print "Cryptobet(" & X & ") = " & X + 97
Next X
You could also shuffle these yourself, avoiding the need to do it with a programming language.
Good luck.
-
Apr 28th, 2010, 01:33 AM
#22
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|