Private Sub ButtonDecrpyt_Click(sender As Object, e As EventArgs) Handles ButtonDecrpyt.Click
MessageBox.Show("encrypted text is : " & Encryptedtext)
MessageBox.Show("cipheralphabet is : " & CipherAlphabet)

' load Cipher alphabet array from cipher alphabet text
Dim arrCipher() As Char = CipherAlphabet.ToCharArray


'load encrypted text into array arrEncryptedText
Dim arrEncryptedText() As Char = Encryptedtext.ToCharArray

'read encryptedtext Array and convert to plain text
For i = 0 To arrEncryptedText.Length - 1
Dim letter As String = arrEncryptedText(i) ' get letter 'i' from encrypted text
Dim arraypos As Integer = Array.IndexOf(arrCipher, letter) ' find out what position in encrypted text array 'letter' is in
PlainText &= arrAlpha(arraypos)
Next
TextboxPlain.Text = PlainText


End Sub
Just to clarify the Message boxes were put in to confirm that both the textstrings 'CipherAlphabet' and 'encryptedText' contain what I expected and they do

arrAlpha was previously defined under Public Class Form1
Dim arrAlpha() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}

Been at this now for well over 4 hours trying to work out why I get an out of range exception for line. Debug tells me arraypos is set to -1
PlainText &= arrAlpha(arraypos)

I hard-coded "T" instead of letter in the above code line as a test and still get the error, even though I know "T" is the first letter in encrypted text (or index 0 of arrCipher) and should be index value 19 (T being 20th letter of the alphabet) of arrAlpha

So instead of
PlainText &= arrAlpha(19)
VB.NET interprets it as
PlainText &= arrAlpha(-1)


I can only think that somehow this line is causing the problem. -1 I believe is the value kicked out if an Item cannot be found in an array.

Dim arraypos As Integer = Array.IndexOf(arrCipher, letter)

What I want it to do is look up the VALUE letter in ArrCipher and return the INDEX
I then use this index value to push out the letter stored in array ArrCipher at the same INDEX

Hope that makes sense