whosyodaddy Posted September 23, 2003 Posted September 23, 2003 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. Quote
Mehyar Posted September 23, 2003 Posted September 23, 2003 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, Quote Dream as if you'll live forever, live as if you'll die today
whosyodaddy Posted September 23, 2003 Author Posted September 23, 2003 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: Quote
Mehyar Posted September 23, 2003 Posted September 23, 2003 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") Quote Dream as if you'll live forever, live as if you'll die today
whosyodaddy Posted September 23, 2003 Author Posted September 23, 2003 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? Quote
atesh Posted September 24, 2003 Posted September 24, 2003 show us the code you have please Quote To err is human, to really foul things up requires a computer.
Mehyar Posted September 24, 2003 Posted September 24, 2003 The code I gave you is supposed to work... I agree with atesh just show us the code to see where the problem is... Quote Dream as if you'll live forever, live as if you'll die today
whosyodaddy Posted September 25, 2003 Author Posted September 25, 2003 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. Quote
*Experts* mutant Posted September 25, 2003 *Experts* Posted September 25, 2003 This happens because it is case sensitive, so if you want to replace A with B and a with b you need two different calls. Quote
Leaders dynamic_sysop Posted September 25, 2003 Leaders Posted September 25, 2003 try this... RichTextBox2.Text =Replace(Replace(Replace(Replace(RichTextBox1.Text,"A","B"),"B","D"),"C","F"),"D","Z") but remember it's case sensetive. Quote
whosyodaddy Posted September 25, 2003 Author Posted September 25, 2003 try this... 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? Quote
Mehyar Posted September 25, 2003 Posted September 25, 2003 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 Quote Dream as if you'll live forever, live as if you'll die today
Leaders dynamic_sysop Posted September 25, 2003 Leaders Posted September 25, 2003 yes backwards is good ;) RichTextBox2.AppendText(Replace(Replace(Replace(Replace(RichTextBox1.Text, "D", "Z"), "C", "F"), "B", "D"), "A", "B")) Quote
Diablicolic Posted September 25, 2003 Posted September 25, 2003 yes backwards is good ;) RichTextBox2.AppendText(Replace(Replace(Replace(Replace(RichTextBox1.Text, "D", "Z"), "C", "F"), "B", "D"), "A", "B")) That code is so insane! But looks cool. Quote "Reality is fake, Dreams are for real"
whosyodaddy Posted September 25, 2003 Author Posted September 25, 2003 (edited) :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. Edited September 26, 2003 by whosyodaddy Quote
whosyodaddy Posted October 3, 2003 Author Posted October 3, 2003 erm.... can anybody help me? :confused: Quote
Leaders dynamic_sysop Posted October 3, 2003 Leaders Posted October 3, 2003 If ListBox1.SelectedItem = "A" & _ ComboBox1.SelectedItem = "E" Then ^^^ are you sure that when you click on the listbox, that the combobox has an item also selected? otherwise it will throw an error. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.