Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB keycodes


  • Please log in to reply

#1
dpm1did1

dpm1did1

    New Member

  • Member
  • Pip
  • 3 posts
:woot: Not a complete noobie as i have a fair bit of PC experience, albeit mostly hardware, so i decided to add a software qualification to my engineering stuff....and i hit a bit of a VB snag :whistling:

Requirement: a simple encryption program

easy peasy - using keycodes, or so it should

'single chr to ASCII to chr (automatic)
Private Sub Txt1_keyup(keycode As Integer, shift As Integer)
Label1.Caption = keycode 'encode function
Label2.Caption = Chr(keycode) 'decode
End Sub

entered text converts to ascii fine, but converts back incorrectly- as shown in the tests below:

eg. input chr : input ascii : incorrect label1 ascii : incorrect chr returned
a 97 65 A
A 65 65 A
z 122* 90 Z
Z 90 90 Z
1 49 49 1

in short, A-Z,0-9 are fine, but a-z code/decode to A-Z !!!!!!!

any ideas? surely it cant be that difficult but i am a little stumped as the rest of my little encryption stuff goes fine!- is it just a bad day? :blink: :help: :)

VMT...D

Edited by dpm1did1, 24 May 2006 - 05:50 AM.

  • 0

Advertisements


#2
KenshinX

KenshinX

    Member

  • Member
  • PipPip
  • 35 posts
u just need the proper Chr(#) code
like if you wanted to do " then you would insert & Chr(34) &
i used it for my myspace generator i made. hopefully it'll help you
  • 0

#3
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Hi,
VB Keycodes and ASCII are two different things: When you press "A" on your keyboard, VB does not distinguish between "a" and "A", essentially you pressed the same key.
What you have to do is to replace the txt1_keyup with txt1_keypress. Keypress uses ASCII not VB Keycodes

Hope that helped :whistling:
  • 0

#4
KenshinX

KenshinX

    Member

  • Member
  • PipPip
  • 35 posts

Hi,
VB Keycodes and ASCII are two different things: When you press "A" on your keyboard, VB does not distinguish between "a" and "A", essentially you pressed the same key.
What you have to do is to replace the txt1_keyup with txt1_keypress. Keypress uses ASCII not VB Keycodes

Hope that helped :whistling:


o sorry i just realized i posted that in wrong forum there was a similar question in another so im sorry about that
  • 0

#5
dpm1did1

dpm1did1

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts
Many thanks for the replies..

"VB Keycodes and ASCII are two different things" - thx, guessed as much =but couldnt find a definite reference for it. So near yet so far!

"replace txt1_keyup with txt1_keypress. Keypress uses ASCII not VB Keycodes" - so easy to fix, pity my learned college instructor didnt just tell us that in the first place [ admittedly he is more C++ and flash oriented but i was left rather :whistling: ]

i shall look at revising my code and fingers x'ed it will all work out well!

if not then i shall fudge it like i did for C++, VBA, SQL etc etc etc
  • 0

#6
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
hope everything's gonna be fine :whistling:
Cheers
  • 0

#7
dpm1did1

dpm1did1

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts
here is the code i eventually used:

Private Sub Txt1_KeyPress(keyAscii As Integer)
Label1.Caption = keyAscii 'encode function
Label2.Caption = chr(keyAscii) 'decode


rather than---
Private Sub Txt1_keyup(keycode As Integer, shift As Integer)
Label1.Caption = keycode 'encode function
Label2.Caption = Chr(keycode) 'decode


such subtle differences!

many thanks to one and all :whistling:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP