# I need a VB.NET '03 Class

Hey guys and gals I need a class developed for me PLZ, I will give 100% credit to whomever developes it for me.
On the Event of Button1 being pressed
The Class has to,
Call a function that
From Textbox1 take all the text (A-Z a-a) only and break it down into numbers like A = 1 a = 2 B = 3 b= 4 ECT and put the numbers into Textbox2. Then there has to be a function that when Button2 in Form1 is pressed it converts Textbox2 into Letters again.

Does anyone have any ideas? I am developing a program that will have this as a simplistic security feature.

Please help send the class to me in a PM The App (when finished) will be fully open source and will give credits to your work.

__________________

## Comments

• : Hey guys and gals I need a class developed for me PLZ, I will give 100% credit to whomever developes it for me.
: On the Event of Button1 being pressed
: The Class has to,
: Call a function that
: From Textbox1 take all the text (A-Z a-a) only and break it down into numbers like A = 1 a = 2 B = 3 b= 4 ECT and put the numbers into Textbox2. Then there has to be a function that when Button2 in Form1 is pressed it converts Textbox2 into Letters again.
:
: Does anyone have any ideas? I am developing a program that will have this as a simplistic security feature.
:
: Please help send the class to me in a PM The App (when finished) will be fully open source and will give credits to your work.

---------------------------------------------------------------------
Hi,

Look up the ASC and CHR functions.

A1
B3
C5
D7
E9
F11
G13
H15
I17
J19
K21
L23
M25
N27
O29
P31
Q33
R35
S37
T39
U41
V43
W45
X47
Y49
Z51

How do you propose to distinguish the 3 in 35 for letter R from a 3 for letter B? Are you putting spaces between the numbers or making them all two digits?

I.E. 3 becomes 03 (zero three)?

Have you thought of that when converting back to letters?

Regards,

Dr M.

• [b][red]This message was edited by DrMarten at 2006-6-14 6:43:22[/red][/b][hr]

Hi,

Not a bad idea, i've done it in two functions as you asked. ;-)

I like a challenge sometimes..... NEXT!! :-)

You could code emails with this. :-)
It's not that secure an alogrithim idea though. :-(

[b] PASTE ALL of the code below into a
completely EMPTY code window for
this program to work. [/b]

[code]

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button3 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(255, Byte), CType(128, Byte))
Me.Button1.Location = New System.Drawing.Point(568, 208)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Encode"
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(128, Byte))
Me.Button2.Location = New System.Drawing.Point(568, 264)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 1
Me.Button2.Text = "Decode"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 80)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(536, 152)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(16, 336)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(536, 152)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.White
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(536, 64)
Me.Label1.TabIndex = 4
Me.Label1.Text = "Type text into the box below after you left click on it. Click on the ENCODE butt" & _
"on."
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label2
'
Me.Label2.BackColor = System.Drawing.Color.White
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(16, 264)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(536, 64)
Me.Label2.TabIndex = 5
Me.Label2.Text = "Type or PASTE coded text into the box below after you left click on it. " & _
" Click on the DECODE button."
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Button3
'
Me.Button3.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte))
Me.Button3.Location = New System.Drawing.Point(568, 304)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 6
Me.Button3.Text = "Exit"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(704, 502)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Text coder."
Me.ResumeLayout(False)

End Sub

#End Region
'A side effect of this program is that it changes all
'non-text characters to a space character as in " " when decoding.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Set up a string for the RESULT.
Dim resultString As String
'The following line was my test string for the program.
'TextBox1.Text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz."

'Get the string to be ENCODED.
resultString = TextBox1.Text
'Call the ENCODE function placing the result into textbox2.
TextBox2.Text = Encode(resultString)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Set up a string to pass the encoded string.
Dim thisString As String
'Get the string to be DECODED.
thisString = TextBox2.Text
'Call the DECODE function placing the result back into textbox1.
TextBox1.Text = Decode(thisString)
End Sub

Function Decode(ByVal string2 As String)

'Set up some working variables.
Dim codedString As String
Dim decodedString As String = ""
Dim myChar As String = ""
Dim index, ch As Integer
'Make the codedString the contents of string2 passed to this function.
codedString = string2

'Step through the coded string 2 characters at a time
'as each one is in the range 01 to 99.
For index = 1 To codedString.Length Step 2
'Get the two characters as a string.
myChar = Mid(codedString, index, 2)
'Is it a number?
If IsNumeric(myChar) = True Then
'Check if the string is 01 or 02 or 03 or 04 or
' 05 or 06 or 07 or 08 or 09
'If so remove the "0"
If myChar.Substring(0, 1) = "0" Then
myChar = myChar.Substring(1, 1)
End If

'Make ch the INTEGER value of the string myChar
ch = CInt(myChar)

'If ch is odd it's a CAPITAL!!
If ch Mod 2 = 0 Then 'otherwise lower-case
'Convert back to ascii range 97 to 122
' i.e a to z.
ch = (ch / 2) + 96
Else
'Convert back to ascii range 65 to 90
' i.e A to Z.
ch = ((ch + 1) / 2) + 64
End If
decodedString = decodedString & Chr(ch)
Else
'As it is not a number the make it a space character.
decodedString = decodedString & " "
End If
Next

'Pass the decoded string back to the line that referenced this function.
Return decodedString

End Function

Function Encode(ByVal string1 As String)

'Set up some working variables.
Dim myString As String = ""
Dim newString As String = ""
Dim index, myVal As Integer
'Make myString the contents of the string passed to the function through string1.
myString = string1

'Loop though every character of the string.
For index = 1 To myString.Length
myVal = Asc(Mid(myString, index, 1))

'-----------------------This section handles the A..Z characters.----------------------------------

'If UPPER-CASE then create an ODD number 01 to 51.
'It does this by changing the ascii value from 1 to 26.
'Doubles the result in this 1st IF statement and deducts 1.

'So 1 stays as 1 but 2 become 3 and so on....
If myVal >= 65 And myVal <= 90 Then
myVal = ((myVal - 64) * 2) - 1
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
If myVal <= 9 Then
newString = newString & "0" & CStr(myVal)
Else
'If the number is 10 or more the "0" isn't added.
newString = newString & CStr(myVal)
End If

'-----------------------This section handles the a..z characters.----------------------------------

ElseIf myVal >= 97 And myVal <= 122 Then
myVal = (myVal - 96) * 2
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
If myVal <= 9 Then
newString = newString & "0" & CStr(myVal)
Else
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
newString = newString & CStr(myVal)
End If
'If a character is not in a..z or A..Z two stars are added to the coded string.
Else
newString = newString & "**"
End If
Next
'Pass the coded string back to the line that referenced this function.
Return newString

End Function

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub
End Class
[/code]

Regards,

Dr M.

• [b][red]This message was edited by DrMarten at 2006-6-13 22:2:12[/red][/b][hr]
Hi,

Here is the code again without the
[b]WINDOWS FORM DESIGNER GENERATED CODE[/b] section.

You'll need two textboxes and three buttons left as their default names if you redesign the FORM yourself for this to work.

[b]
button1 ENCODES
button2 DECODES
button3 EXIT

textbox1 [green] is the box the program codes from,
coding goes to textbox2.[/green]
textbox2 [green] is the box the program decodes from,
decoding goes back to textbox1.[/green]

DELETE the text in textbox1 once ENCODED
to prove this program works. :-)
[b]

[code]
'A side effect of this program is that it changes all
'non-text characters to a space character as in " " when decoding.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Set up a string for the RESULT.
Dim resultString As String
'The following line was my test string for the program.
'TextBox1.Text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz."

'Get the string to be ENCODED.
resultString = TextBox1.Text
'Call the ENCODE function placing the result into textbox2.
TextBox2.Text = Encode(resultString)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Set up a string to pass the encoded string.
Dim thisString As String
'Get the string to be DECODED.
thisString = TextBox2.Text
'Call the DECODE function placing the result back into textbox1.
TextBox1.Text = Decode(thisString)
End Sub

Function Decode(ByVal string2 As String)

'Set up some working variables.
Dim codedString As String
Dim decodedString As String = ""
Dim myChar As String = ""
Dim index, ch As Integer
'Make the codedString the contents of string2 passed to this function.
codedString = string2

'Step through the coded string 2 characters at a time
'as each one is in the range 01 to 99.
For index = 1 To codedString.Length Step 2
'Get the two characters as a string.
myChar = Mid(codedString, index, 2)
'Is it a number?
If IsNumeric(myChar) = True Then
'Check if the string is 01 or 02 or 03 or 04 or
' 05 or 06 or 07 or 08 or 09
'If so remove the "0"
If myChar.Substring(0, 1) = "0" Then
myChar = myChar.Substring(1, 1)
End If

'Make ch the INTEGER value of the string myChar
ch = CInt(myChar)

'If ch is odd it's a CAPITAL!!
If ch Mod 2 = 0 Then 'otherwise lower-case
'Convert back to ascii range 97 to 122
' i.e a to z.
ch = (ch / 2) + 96
Else
'Convert back to ascii range 65 to 90
' i.e A to Z.
ch = ((ch + 1) / 2) + 64
End If
decodedString = decodedString & Chr(ch)
Else
'As it is not a number the make it a space character.
decodedString = decodedString & " "
End If
Next

'Pass the decoded string back to the line that referenced this function.
Return decodedString

End Function

Function Encode(ByVal string1 As String)

'Set up some working variables.
Dim myString As String = ""
Dim newString As String = ""
Dim index, myVal As Integer
'Make myString the contents of the string passed to the function through string1.
myString = string1

'Loop though every character of the string.
For index = 1 To myString.Length
myVal = Asc(Mid(myString, index, 1))

'-----------------------This section handles the A..Z characters.----------------------------------

'If UPPER-CASE then create an ODD number 01 to 51.
'It does this by changing the ascii value from 1 to 26.
'Doubles the result in this 1st IF statement and deducts 1.

'So 1 stays as 1 but 2 become 3 and so on....
If myVal >= 65 And myVal <= 90 Then
myVal = ((myVal - 64) * 2) - 1
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
If myVal <= 9 Then
newString = newString & "0" & CStr(myVal)
Else
'If the number is 10 or more the "0" isn't added.
newString = newString & CStr(myVal)
End If

'-----------------------This section handles the a..z characters.----------------------------------

ElseIf myVal >= 97 And myVal <= 122 Then
myVal = (myVal - 96) * 2
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
If myVal <= 9 Then
newString = newString & "0" & CStr(myVal)
Else
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
newString = newString & CStr(myVal)
End If
'If a character is not in a..z or A..Z two stars are added to the coded string.
Else
newString = newString & "**"
End If
Next
'Pass the coded string back to the line that referenced this function.
Return newString

End Function

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
[/code]

Regards,

Dr M.

• Hi,

OOps i forgot to add vertical scrollbars to my textboxes. :-)
I'll leave that up to you.

I tried the program on the program main text too.
See the result of decoding, below the line>>

Regards,

Dr M.
_______________________________________________________________________

A side effect of this program is that it changes all non text characters to a space character as in when decoding Private Sub Button Click ByVal sender As System Object ByVal e As System EventArgs Handles Button Click Set up a string for the RESULT Dim resultString As String The following line was my test string for the program TextBox Text ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz Get the string to be ENCODED resultString TextBox Text Call the ENCODE function placing the result into textbox TextBox Text Encode resultString End Sub Private Sub Button Click ByVal sender As System Object ByVal e As System EventArgs Handles Button Click Set up a string to pass the encoded string Dim thisString As String Get the string to be DECODED thisString TextBox Text Call the DECODE function placing the result back into textbox TextBox Text Decode thisString End Sub Function Decode ByVal string As String Set up some working variables Dim codedString As String Dim decodedString As String Dim myChar As String Dim index ch As Integer Make the codedString the contents of string passed to this function codedString string Step through the coded string characters at a time as each one is in the range to For index To codedString Length Step Get the two characters as a string myChar Mid codedString index Is it a number If IsNumeric myChar True Then Check if the string is or or or or or or or or If so remove the If myChar Substring Then myChar myChar Substring End If Make ch the INTEGER value of the string myChar ch CInt myChar If ch is odd it s a CAPITAL If ch Mod Then otherwise lower case Convert back to ascii range to i e a to z ch ch Else Convert back to ascii range to i e A to Z ch ch End If decodedString decodedString Chr ch Else As it is not a number the make it a space character decodedString decodedString End If Next Pass the decoded string back to the line that referenced this function Return decodedString End Function Function Encode ByVal string As String Set up some working variables Dim myString As String Dim newString As String Dim index myVal As Integer Make myString the contents of the string passed to the function through string myString string Loop though every character of the string For index To myString Length myVal Asc Mid myString index This section handles the A Z characters If UPPER CASE then create an ODD number to It does this by changing the ascii value from to Doubles the result in this st IF statement and deducts So stays as but become and so on If myVal And myVal Then myVal myVal If number is a or less it adds a into the number here So becomes and so on If myVal Then newString newString CStr myVal Else If the number is or more the isn t added newString newString CStr myVal End If This section handles the a z characters ElseIf myVal And myVal Then myVal myVal If number is a or less it adds a into the number here So becomes and so on If myVal Then newString newString CStr myVal Else If number is a or less it adds a into the number here So becomes and so on newString newString CStr myVal End If If a character is not in a z or A Z two stars are added to the coded string Else newString newString End If Next Pass the coded string back to the line that referenced this function Return newString End Function Private Sub Button Click ByVal sender As System Object ByVal e As System EventArgs Handles Button Click End End Sub
• Dude Thank you, works Like A Charm. You Should Write me a Message Stating who you want the Credits to Be To.
• How did you come up with that? I sat at my computer for months ECT. attempting to do this but I dont know Basic that well.

Oh yea, is there anything I could add that would make um lets say .'s = the & symbol. and even numbers like 0-9 become Alphabetical during the encryption phase? 391602282238**250228**123036**401610**16102432
• [b][red]This message was edited by DrMarten at 2006-6-14 6:29:12[/red][/b][hr]

: How did you come up with that? I sat at my computer for months ECT. attempting to do this but I dont know Basic that well.
:
: Oh yea, is there anything I could add that would make um lets say .'s = the & symbol. and even numbers like 0-9 become Alphabetical during the encryption phase? 391602282238**250228**123036**401610**16102432

======================================================================

Hi,

3916022822**503042**403030**123036**50304236**0630081008**26103838021410**1810****391602282238**250228**123036**401610**16102432************232923**

Re: One More thing. How about coding everything to numbers including the numbers?[b][blue]
Please be the 1st person [/blue][green]to add a message to my[/green][red] guestbook if you wish?[/red][/b]

[b]Message No.2. >>[/b]
0350**401610**460250****493042**16024410**20423840**1418441028**2610**02283040161036**18081002**123036**02**32363014360226**18**4410**160208**1828**26182808**123036**02141038****17**46182424**40102424**503042**26303610**0204304240**40161838**1828**02**3210363830280224**26103838021410**

Glad i solved it for you this far ( saying this modestly ). ;-)

I've been programming on and off for about 20 years.
I know some assembly language,Pascal and BASIC.

Most variations of BASIC including VB.Net have their similiar
features. Like FOR NEXT loops etc and some graphics commands. :-)

I'm now 40. I'm back in my home town about 3 years now after living
in the North West of England for about 8 years.

Just got back into programming since i started doing VB.Net at the university of Teesside last September.
Their website is www.tees.ac.uk

I wished i'd done a course some 15 to 20 years ago.
I'm thinking of going on to do a degree and maybe go
into teaching or I.T. support.
I find VB.Net fairly easy for simple programs like this.

If you asked me to do a game, that would take a while. :-|

I'm "kind of" teaching myself VB.Net with books and the use
of the built in help files ( which are not all that easy to
understand, some of the time ).I know some graphics routines too.

I have a half developed working program that is a graphics demo, if you're interested? It does more than what VB.Net's built-in
graphics commands can do.

I hope you liked the comments i put in the program too?

I will have a think about recoding it for ' " ! ? and = symbols, maybe for all the printable characters.
I might just use their ascii values (maybe reverse them) and rework the program so a letter A is 001 instead of 01.
To convert to ascii and back is the easiest bit. :-)
See ascii table at www.asciitable.com

It took me a few minutes to come up with>>

number=(number*2)-1

To make a number sequence like 1,2,3,4,5,6,7,8,9,10 etc into>>
1,3,5,7,9,11,13,15,17,19 etc for the CAPITAL letters.

Regards,

Dr M.
a.k.a. John.

• : How did you come up with that? I sat at my computer for months ECT. attempting to do this but I dont know Basic that well.
:
: Oh yea, is there anything I could add that would make um lets say .'s = the & symbol. and even numbers like 0-9 become Alphabetical during the encryption phase? 391602282238**250228**123036**401610**16102432

======================================================================
Hello again,

Did you mean a separate OOP ([b][blue]Object[/blue][red]Orientated[/red][green]Programming[/green][/b])
type of CLASS as in the VIZURA class in this answer of mine?>>

http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=39&MsgID=338985&Setting=A9999F0001

Regards,

Dr M.

• [b][red]This message was edited by DrMarten at 2006-6-14 18:47:52[/red][/b][hr]

[code]
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button3 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(255, Byte), CType(128, Byte))
Me.Button1.Location = New System.Drawing.Point(568, 208)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Encode"
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(128, Byte))
Me.Button2.Location = New System.Drawing.Point(568, 264)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 1
Me.Button2.Text = "Decode"
'
'TextBox1
'
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox1.Location = New System.Drawing.Point(16, 80)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox1.Size = New System.Drawing.Size(536, 152)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox2.Location = New System.Drawing.Point(16, 336)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox2.Size = New System.Drawing.Size(536, 152)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
'
'Label1
'
Me.Label1.BackColor = System.Drawing.Color.White
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(536, 64)
Me.Label1.TabIndex = 4
Me.Label1.Text = "Type text into the box below after you left click on it. Click on the ENCODE butt" & _
"on."
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label2
'
Me.Label2.BackColor = System.Drawing.Color.White
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(16, 264)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(536, 64)
Me.Label2.TabIndex = 5
Me.Label2.Text = "Type or PASTE coded text into the box below after you left click on it. " & _
" Click on the DECODE button."
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Button3
'
Me.Button3.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte))
Me.Button3.Location = New System.Drawing.Point(568, 304)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 6
Me.Button3.Text = "Exit"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(704, 502)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "H"
Me.ResumeLayout(False)

End Sub

#End Region
'A side effect of this program is that it changes all
'non-text characters to a space character as in " " when decoding.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Set up a string for the RESULT.
Dim resultString As String

'The following line was my test string for the program.
'TextBox1.Text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

'--------------------TAKE OUT THIS SECTION WHEN YOUR DONE TESTING THE PROGRAM. --------------------------
Dim index As Integer
For index = 0 To 255
TextBox1.AppendText(Chr(index))
Next
'--------------------END-OF-SECTION-TO-REMOVE-------------------------------------------------------------

'Get the string to be ENCODED.
resultString = TextBox1.Text
'Call the ENCODE function placing the result into textbox2.
TextBox2.Text = Encode(resultString)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Set up a string to pass the encoded string.
Dim thisString As String
'Get the string to be DECODED.
thisString = TextBox2.Text
'Call the DECODE function placing the result back into textbox1.
TextBox1.Text = Decode(thisString)
End Sub

Function Decode(ByVal string2 As String)

'Set up some working variables.
Dim codedString As String
Dim decodedString As String = ""
Dim myChar As String = ""
Dim index, ch As Integer
'Make the codedString the contents of string2 passed to this function.
codedString = string2

'Step through the coded string 2 characters at a time
'as each one is in the range 01 to 99.
For index = 1 To codedString.Length Step 3
'Get the two characters as a string.
myChar = Mid(codedString, index, 3)
'Is it a number?
If IsNumeric(myChar) = True Then
'Check if the string is 01 or 02 or 03 or 04 or
' 05 or 06 or 07 or 08 or 09
'If so remove the "0"
If myChar.Substring(0, 1) = "0" Then
myChar = myChar.Substring(1, 2)
ElseIf myChar.Substring(0, 2) = "00" Then
myChar = myChar.Substring(2, 1)
End If

'Make ch the INTEGER value of the string myChar
ch = CInt(myChar)

'If ch is odd it's a CAPITAL!!
If ch Mod 2 = 0 Then 'otherwise lower-case
'Convert back to ascii range 97 to 122
' i.e a to z.
ch = (ch / 2) + 96
Else
'Convert back to ascii range 65 to 90
' i.e A to Z.
ch = ((ch + 1) / 2) + 64
End If
decodedString = decodedString & Chr(ch)
Else
'As it is not a number then decode the non-alphabetic character.
If myChar.Substring(0, 1) <> "O" Then
decodedString = decodedString & Chr(CInt(myChar.Substring(0, 3)))
ElseIf myChar.Substring(0, 2) = "OO" Then
decodedString = decodedString & Chr(CInt(myChar.Substring(2, 1)))
ElseIf myChar.Substring(0, 1) = "O" Then
decodedString = decodedString & Chr(CInt(myChar.Substring(1, 2)))
End If

End If

Next

'Pass the decoded string back to the line that referenced this function.
Return decodedString

End Function

Function Encode(ByVal string1 As String)

'Set up some working variables.
Dim myString As String = ""
Dim newString As String = ""
Dim currChar As String = ""
Dim index, myVal As Integer
'Make myString the contents of the string passed to the function through string1.
myString = string1

'Loop though every character of the string.
For index = 1 To myString.Length
myVal = Asc(Mid(myString, index, 1))

'-----------------------This section handles the A..Z characters.----------------------------------

'If UPPER-CASE then create an ODD number 01 to 51.
'It does this by changing the ascii value from 1 to 26.
'Doubles the result in this 1st IF statement and deducts 1.

'So 1 stays as 1 but 2 become 3 and so on....
If myVal >= 65 And myVal <= 90 Then
myVal = ((myVal - 64) * 2) - 1
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
If myVal <= 9 Then
newString = newString & "00" & CStr(myVal)
ElseIf myVal > 9 And myVal <= 99 Then
newString = newString & "0" & CStr(myVal)
Else
'If the number is 100 or more the "0's" aren't added.
newString = newString & CStr(myVal)
End If

'-----------------------This section handles the a..z characters.----------------------------------

ElseIf myVal >= 97 And myVal <= 122 Then
myVal = (myVal - 96) * 2
'If number is a 9 or less it adds a 0 into the number here.
'So 7 becomes 07 and so on....
If myVal <= 9 Then
newString = newString & "00" & CStr(myVal)
ElseIf myVal > 9 And myVal <= 99 Then
newString = newString & "0" & CStr(myVal)
Else
newString = newString & CStr(myVal)
End If
'If a character is not in a..z or A..Z letter O's are added as appropriate.
ElseIf myVal <= 9 Then
newString = newString & "OO" & CStr(myVal)
ElseIf myVal > 9 And myVal <= 99 Then
newString = newString & "O" & CStr(myVal)
Else
newString = newString & CStr(index)
End If
Next
'Pass the coded string back to the line that referenced this function.
Return newString

End Function

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub

End Class
[/code]

I have used a letter O as it looks almost like a zero >> "0" :-)

Regards,

Dr M.

• [b][red]This message was edited by DrMarten at 2006-6-14 18:58:49[/red][/b][hr]
[code]
'--------------------TAKE OUT THIS SECTION WHEN YOUR DONE TESTING THE PROGRAM. :-) -----------------------
Dim index As Integer
For index = 0 To 255
TextBox1.AppendText(Chr(index))
Next
'--------------------END-OF-SECTION-TO-REMOVE-------------------------------------------------------------
[/code]

It is in the middle of the button1 code. ;-)

Regards,

Dr M.

• It will crash with a string longer than 1020 maybe 1024? characters.
:-(

I might rewrite this program slightly to deal with long strings in "chunks". Hmmmn. :-|

: [code]
: '--------------------TAKE OUT THIS SECTION WHEN YOUR DONE TESTING THE PROGRAM. :-) -----------------------
: Dim index As Integer
: For index = 0 To 255
: TextBox1.AppendText(Chr(index))
: Next
: '--------------------END-OF-SECTION-TO-REMOVE-------------------------------------------------------------
: [/code]
:
: It is in the middle of the button1 code. ;-)
:
:
: Regards,
:
: Dr M.
:
:
:
:

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!