VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

Visual Basic Source Code


You're Browsing As A Guest! Register Now...
Become a VB Expert!

Join 357,970 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,554 people online right now.Registration is fast and FREE... Join Now!




Letter substitution code

substitutes a letter with another letter based on a passkey.

Submitted By: iwantthependrive
Actions:
Rating:
Views: 983

Language: Visual Basic

Last Modified: August 30, 2009
Instructions: make 2 command buttons and a text box.

Snippet


  1. 'THIS ENCODES THE LETTER
  2. Private Sub Command1_Click()
  3. Dim pa As Long, a As String, b As Long, i As Long, c As String, num As Long
  4. If Text1.Text = "" Then
  5. MsgBox "There is Nothing To Encrypt"
  6. Else
  7. pa = InputBox("Enter passkey (only between 1 and 128")
  8. a = Text1.Text
  9. Text1.Text = ""
  10. b = Len(a)
  11. For i = 1 To b
  12. c = Mid(a, i, 1)
  13. num = Asc(c)
  14. num = num + pa
  15. If num > 256 Then
  16. MsgBox "Lower Passkey!"
  17. End If
  18. Text1.Text = Text1.Text + Chr(num)
  19. Next i
  20. MsgBox "Your Passkey is " & pa, vbInformation
  21. End If
  22. End Sub
  23.  
  24. 'THIS DECODES THE LETTER
  25. Private Sub Command2_Click()
  26. Dim pa As Long, a As String, b As Long, i As Long, c As String, num As Long, cl as string
  27. If Text1.Text = "" Then
  28. MsgBox "There is Nothing To Decrypt"
  29. Else
  30. pa = InputBox("Enter Your Passkey")
  31. a = Text1.Text
  32. Text1.Text = ""
  33. b = Len(a)
  34. For i = 1 To b
  35. c = Mid(a, i, 1)
  36. num = Asc(c)
  37. num = num - pa
  38. If pa > 128 Then
  39. MsgBox "Passkey should be between 1 and 128!"
  40. End If
  41. cl = Chr(num)
  42. Text1.Text = Text1.Text + cl
  43. Next i
  44. End If
  45. End Sub
  46.  
  47.  

Copy & Paste


Comments

firebolt 2009-04-28 08:30:08

If you say make 2 command buttons, wouldnt you want the second to be command2.

iwantthependrive 2009-05-02 10:19:04

i am sorry. i have corrected it.

hbhargava 2009-08-28 13:49:13

in vb 2008 it tells me that cl is not declared, and same with qwe

iwantthependrive 2009-08-30 10:03:33

i have modified it. it should work now.

borninlyoko 2009-12-05 14:12:22

I'm getting an error, line 3 character 8. It says it expected end of statement


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month