• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Replacing

How do I replace a string by another? In other words:
If I type "A" in Text1 and want it to be replaced by "B"
0
kalaka
Asked:
kalaka
  • 5
  • 5
  • 2
  • +1
1 Solution
 
bobbit31Commented:
Replace(Text1.Text, "A", "B")
0
 
sirbountyCommented:
text1.text="B"?
Unless I'm missing something. . .
If text2.text="B"
and you want text1.text to equal "B",
you can also use
text1.text=text2.text
0
 
thundercageCommented:
I think what you want to know is how to intercept a key and replace it when it is typed. To do this you need to put your code in the KeyPress event of the Text1 textbox

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 65 Then KeyAscii = 66
End Sub
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
thundercageCommented:
Remember this is with capslock ON
0
 
kalakaAuthor Commented:
I know I already accepted an answer but  if I use ()'s it requires a "=" sign. Without the ()'s it still doesnt work. ok, here's my code:
Private Sub Text1_change()
Replace Text1.Text, "A", "B"
End Sub

It doesnt work :(
0
 
bobbit31Commented:
Text1.Text = Replace(Text1.Text, "A", "B")
0
 
kalakaAuthor Commented:
Does it have to be by Ascii? cant I just replace the string?
0
 
kalakaAuthor Commented:
What if I want to "double" replace? In other words, replace more than 1 characters. Here's the code:

Private Sub Text1_change()
Text2.Text = Replace(Text1.Text, "A", "B")
Text2.Text = Replace(Text1.Text, "C", "D")
End Sub
0
 
bobbit31Commented:
replace works on strings...

so if you had "AB" you could do text2.text = Replace(Text1.Text, "AB", "BC")

But if A and B are separate then you'd have to do it like you've posted above.
0
 
kalakaAuthor Commented:
But above doesnt work :( It only replaces C by D, The A still is A. Isnt there a way of making it replace many characters by anothers?
0
 
bobbit31Commented:
Text2.Text = Replace(Text1.Text, "A", "B")
Text2.Text = Replace(Text2.Text, "C", "D")
Text2.Text = Replace(Text2.Text, "E", "F")
0
 
kalakaAuthor Commented:
That doesnt work. THATS WHY IM ASKING IN THE FISRT PLACE!
0
 
bobbit31Commented:
before you start shouting, please look at the comment... there is a slight difference b/w mine and yours.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now