Simple text conversion question (quiz related)

mattkorguk

Registered User.
Local time
Today, 22:16
Joined
Jun 26, 2007
Messages
301
Hi All,
I thought I'd just try and write a quick Db to convert the alphabet into reverse. It's for a quiz which is being held at work, "who can decode the messages" type thing.
I'm just trying to have a text box, which the user can type in, the click on the 'convert' button and this gives the 'coded' message.

I've started down this route, but it seems not to be as straight forward as I was hoping! :confused:
Code:
Dim mystring As String
Dim intcounter As Integer
For intcounter = 1 To Len(Me.TextEntry)
If Mid(Me.TextEntry, 1, intcounter) = Chr(65) Then
mystring = Replace(Me.TextEntry, Chr(65), Chr(90))
If Mid(Me.TextEntry, 1, intcounter) = Chr(66) Then
mystring = Replace(Me.TextEntry, Chr(66), Chr(89))
End If
End If
Me.Code = mystring
Me.Refresh
Next
 
Haven't tested it, but this might work:

Dim mystring As String
Dim intcounter As Integer
Dim char As String
For intcounter = 1 To Len(Me.textentry)
char = Mid$(Me.textentry, intcounter, 1)
Select Case char
Case "a" To "z"
char = Chr$(Asc("z") - (Asc(char) - Asc("a")))
Case "A" To "Z"
char = Chr$(Asc("Z") - (Asc(char) - Asc("A")))
End Select

mystring = mystring + char
Next
 
Never mind I didn't quite get it at first. You want to substitute all A's with Z's, all B's with Y's, etc. right?
 
You could try something like this

Code:
sub bleh()


dim strAlp as string
dims strLet as string 'individual letter of word
dim lngStr as long
dim strInput as string 'this is the word you want to convert
dim strOutput
dim strEncoded as string
dim x as long
dim i as long

strInput = "Blah"

x = len(strInput)


strAlp = "abcdefghijklmnoprstuvwxyz"
strEncoded = ""

for i = 1 to x

   strOutput = mid(strInput, i, 1)
   lngStr = instr(1,strAlp,stOutput)
   strEncoded = strEncoded & Mid(strAlp, 27 - lngStr, 1)

next i

debug.print strEncoded

end sub

Not infront of a computer with msoffice atm so may be a few mistakes but should put you on the right track.
 
Bob - That's correct.
Thank you very much for the other suggestions, I'll give them a try today.
 
Mearle - First time and it worked a treat, thank you very much indeed! :)
 
Mearle - I spoke too soon...uppercase letters receive special characters instead such as š™˜—–•”“’‘ŽŒ‹Š‰ˆ‡ etc.
 
I just changed the input text into lowercase and all is well.
Thanks again for all you help.

Code:
Me.TextEntry = (StrConv(Me.TextEntry, vbLowerCase))
Dim mystring As String
Dim intcounter As Integer
Dim char As String
For intcounter = 1 To Len(Me.TextEntry)
char = Mid$(Me.TextEntry, intcounter, 1)
Select Case char
Case "a" To "z"
char = Chr$(Asc("z") - (Asc(char) - Asc("a")))
End Select
mystring = mystring + char
Next
Me.Coded = mystring
End Sub

:)
 

Users who are viewing this thread

Back
Top Bottom