Reputation:
I have ran in to a problem while writing a program for school that converts a string like abc
to bcd
, a
becomes b
and b
becomes c
and you can see the rest.
For i = 0 To length - 1
If (Asc(justatext.Substring(i, 1)) >= 65 And Asc(justatext.Substring(i, 1)) <= 90) Then
Asc(justatext.Substring(i, 1) = (Asc(justatext.Substring(i, 1) + 1)))
answer &= justatext.Substring(i, 1)
End If
Next
This is in a function and I return the value answer
, but I always get an invalid cast exception
. Is there a way you can do this with ansi
codes?.
Upvotes: 3
Views: 531
Reputation: 2783
your problem can be found in the brackets, you have quite a lot of them, and I think you confused yourself with them.
I've tripped down your code and removed the brackets that aren't needed:
For i = 0 To justatext.Length - 1
If Asc(justatext.Substring(i, 1)) >= 65 And Asc(justatext.Substring(i, 1)) <= 90 Then
answer &= Chr(Asc(justatext.Substring(i, 1)) + 1)
End If
Next
Watch out: this code will only work for capital letters..
Upvotes: 2