change each given letter....

whosyodaddy

Regular
Joined
Jun 23, 2003
Messages
83
im sorta far in a program i am making. it is like a decoder where you type a message in the richtextbox, hit the button, and the message will appear decoded in a secret code in the other richtextbox. what is the code for when the user types in something in richtextbox1, and it knows to turn all the letter "a" in richtextbox1 to "z" 's .in richtextbox2 in the exact same format
for instance:
Data in Richtextbox1: ABCD ABCD
A's turn into B's
B's turn into D's
C's turn into F's
D's turn into Z's
So hit the button,
Then the data in Richtextbox2 is: BDFZ BDFZ
please help me on this. i am excelling quite far and reading some books, none of which explain how to do this. thanks.
 
RichTextBox1.Text = RichTextBox1.Text.Replace("A","B")

and so on, but be careful that you need to do them in the correct order so that when you change the A's to B's and not change them back to D's...

Hope this helps,
 
thanks!!!

so would i do like:

On Button Click (the code for clicking button)
RichTextBox1.Text = RichTextBox1.Text.Replace("A","B")
Then here is the code for putting the text that got replaced into richtextbox2

ok thanks for the code again! but what is the code for putting the text that got replaced into richtextbox2?:confused:
 
Oh sory i didnot read you question well, so you want the replaced text to be put in another textbox,

Then instead of
RichTextBox1.Text = RichTextBox1.Text.Replace("A","B")

do
RichTextBox2.Text = RichTextBox1.Text.Replace("A","B")
 
hmmm, well when i do that, whatever text i put in richtextbox1, same goes to richtextbox2. it doesn't replace any letters for some reason:( whats wrong?
 
The code I gave you is supposed to work...

I agree with atesh just show us the code to see where the problem is...
 
ok here:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RichTextBox2.Text = RichTextBox1.Text.Replace("A", "B")
End Sub

doesn't work.
when i type in 'a' in richtextbox1, hit button, 'a' appears in richtextbox2.
 
dynamic_sysop said:
try this...
Visual Basic:
RichTextBox2.Text =Replace(Replace(Replace(Replace(RichTextBox1.Text,"A","B"),"B","D"),"C","F"),"D","Z")
but remember it's case sensetive.

when i do that, i type in "ABCD" click the button, and this what comes up "ZZFZ" in richtextbox2. what is wrong?
 
Your problem is in the order ou are executing your stratements.

You are changing the A's to B's

Then Changing B's to D's

So all original A's will be changed to D's

and so on...

Try this instead
'Declare a string to hold the converted data
Dim strConvertedText As String = RichTextBox1.Text

'Start from backwards since following the order you chose will change A's to Z's
strConvertedText = strConvertedText.Replace("D", "Z")
strConvertedText = strConvertedText.Replace("d", "z")
strConvertedText = strConvertedText.Replace("C", "F")
strConvertedText = strConvertedText.Replace("c", "f")
strConvertedText = strConvertedText.Replace("B", "D")
strConvertedText = strConvertedText.Replace("b", "d")
strConvertedText = strConvertedText.Replace("A", "B")
strConvertedText = strConvertedText.Replace("a", "b")

RichTextBox2.Text = strConvertedText
 
:D
AWESOME GUYS!!!!!!
thanks so much!!!
ya'll the best!!!
does anybody know the code for when a certain item in the listbox is selected and then a certain item in the combobox is selected, it changes certain text?
i think i know the beggining of the code:
If ListBox1.SelectedItem = "A"
ComboBox1.SelectedItem="E" Then

(what do i put here to change the strConvertedText = strConvertedText.Replace("A","B") in form1.vb under button1_click to strConvertedText = strConvertedText.Replace("A", "E") and then it saves it)

End If

Remember, all of that code is in Form2.vb. So the user goes to Form2.vb Set's the settings that changes the code in Form1.vb, saves it, so when he goes back to Form1.vb, the code is saved. and the "a" replaces with "e"? does anybody know how to do this? i can give you the program if you want..... thanks!

i spent alot of my time trying to figure out how... and i came up with this:

Dim Z As Form1
If ListBox1.SelectedItem = "A" & _
ComboBox1.SelectedItem = "E" Then
Z.RichTextBox1.Text = Z.RichTextBox1.Text.Replace("A", "E")
Z.RichTextBox2.Text = Z.RichTextBox1.Text
End If

although whenever i run it i get the error whenever i click on the "A" in the listbox. the error where it gives me the options "Break" & "Continue". what is wrong? thanks.
 
Last edited:
Back
Top