First of all the code as posted will throw an exception for anything but the shortest of strings.
The following code includes the OP's original code, plus a simple checksum, and a guess at how the checksum might be used.
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim buffer() As Byte
Dim tstString As String = "Calculate a checksum for a given string"
Dim chkSumFix As Integer = CreateIntChecksumFixed(tstString) 'get a checksum
buffer = SendPacket(tstString, chkSumFix) 'create a byte buffer to send
tstString = decodePacket(buffer)
'do the same using the OP's original code
Dim chkSum As Integer = CreateIntChecksum(tstString) 'error
buffer = SendPacket(tstString, chkSum)
End Sub
'OP
Public Function CreateIntChecksum(ByVal s As String) As Integer
Dim r As Integer = 0
For i As Integer = 0 To (s.Length() - 1)
Dim bchar As Byte = Convert.ToByte(s(i))
r = bchar + ((r << 5) - r)
Next
Return r
End Function
'a very simple checksum
Public Function CreateIntChecksumFixed(ByVal s As String) As Integer
Dim r As Integer = 0
For i As Integer = 0 To (s.Length() - 1)
Dim bchar As Byte = Convert.ToByte(s(i))
r = (r And &HFFFF) + bchar
Next
Return r
End Function
Private Function SendPacket(ByVal aString As String, _
ByVal aChecksum As Integer) As Byte()
'construct a packet to be sent
'Packet format
'returns a byte buffer
'byte(0 -3) = length of original string - use BitConverter.ToInt32 to extract
'byte(4-n) = original string. n = (4 + string length) - 1
'byte(n + 1, n + 2, n + 3, n + 4) = checksum
Dim length As Integer
Dim retV As New List(Of Byte)
retV.AddRange(System.Text.Encoding.ASCII.GetBytes(aString)) 'add string to packet
length = retV.Count 'get length - use this length in case a different encoding is used
retV.AddRange(BitConverter.GetBytes(aChecksum)) 'add checksum
retV.InsertRange(0, BitConverter.GetBytes(length)) 'insert length at start of packet
Return retV.ToArray
End Function
Private Function decodePacket(ByVal buffer As Byte()) As String
Dim sLen As Integer = BitConverter.ToInt32(buffer, 0)
If sLen + 8 <> buffer.Length Then Throw New ArgumentOutOfRangeException
Dim s As String = System.Text.Encoding.ASCII.GetChars(buffer, 4, sLen)
Dim chksum As Integer = CreateIntChecksumFixed(s)
Dim embeddedChecksum As Integer = BitConverter.ToInt32(buffer, sLen + 4)
If chksum <> embeddedChecksum Then Throw New ArgumentException("Invalid checksum")
Return s
End Function