Author | Message | Time |
---|---|---|
Reaper | Hey I need help, how would I make a simple program to translate like one letter to another? Ex. A -> G, B -> W, etc.. etc.. Help is appreciated | November 10, 2004, 11:57 PM |
Yegg | do u mean like a > b > c and so on? | November 11, 2004, 1:57 AM |
Dyndrilliac | [quote author=Reaper~ link=topic=9502.msg88309#msg88309 date=1100131020] Hey I need help, how would I make a simple program to translate like one letter to another? Ex. A -> G, B -> W, etc.. etc.. Help is appreciated [/quote] Try splitting the string into an array using a null string as your delimiter and then iterate through the array with a For Loop, running a check to see which letter it is and what to replace it with. Here's an example - this is untested:[code]Dim Splt() As String Public Function Encode(S As String) As String Splt = Split(S, vbNullString) Dim i As Integer For i = 0 To UBound(Splt) Select Case LCase$(Splt(i)) Case "a" Splt(i) = Replace(Splt(i), "a", "g") End Select Encode = Encode & Splt(i) Next i End Function[/code] | November 11, 2004, 2:22 AM |
TheMinistered | You could make a table of values (an array) from 1-26, and each could have a corresponding value for the proper letter. i.e. 1st letter is A so in the first element of the table you could have G. Then you could do something like this: [code] Private CharTable(1 To 26) As String Private Sub Test() Dim lngCounter As Long, strDumpString As String Dim bytCharacter As Byte Dim strString As String strString = "abcde" CharTable(1) = "G" CharTable(2) = "s" CharTable(3) = "A" CharTable(4) = "x" CharTable(5) = "I" '... For lngCounter = 1 To Len(strString) bytCharacter = Asc(Mid$(strString, lngCounter, 1)) If (bytCharacter >= 65 And bytCharacter <= 90) Then strDumpString = strDumpString & CharTable(bytCharacter - 64) End If If (bytCharacter >= 97 And bytCharacter <= 122) Then strDumpString = strDumpString & CharTable(bytCharacter - 96) End If Next lngCounter End Sub [/code] | November 13, 2004, 5:05 PM |