You are incrementing the count i
in the loop. You don't need to do this in a For
loop.
Also you are going past the end of the string. You need to end the loop at the Length - 1
Private Function function1(text As String) As String
Dim dec As String = ""
For i As Integer = 0 To text.Length - 1
dec = dec & System.Text.ASCIIEncoding.ASCII.GetBytes(text)(i)
Next
Return dec
End Function
Note: switch option strict on - you will be glad you did in the long run!