Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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,

Dream as if you'll live forever, live as if you'll die today
Posted

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:

Posted

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")

Dream as if you'll live forever, live as if you'll die today
Posted

The code I gave you is supposed to work...

 

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

Dream as if you'll live forever, live as if you'll die today
Posted

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.

Posted
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?

Posted

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

Dream as if you'll live forever, live as if you'll die today
Posted
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.

"Reality is fake, Dreams are for real"
Posted (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 by whosyodaddy
  • Leaders
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...