Solved

Replacing

Posted on 2003-11-18
13
258 Views
Last Modified: 2010-05-01
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
Comment
Question by:kalaka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 20 total points
ID: 9775789
Replace(Text1.Text, "A", "B")
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 9775826
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
 
LVL 1

Expert Comment

by:thundercage
ID: 9775840
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 1

Expert Comment

by:thundercage
ID: 9775848
Remember this is with capslock ON
0
 

Author Comment

by:kalaka
ID: 9775862
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 9775866
Text1.Text = Replace(Text1.Text, "A", "B")
0
 

Author Comment

by:kalaka
ID: 9775879
Does it have to be by Ascii? cant I just replace the string?
0
 

Author Comment

by:kalaka
ID: 9775941
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 9776349
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
 

Author Comment

by:kalaka
ID: 9782184
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 9782439
Text2.Text = Replace(Text1.Text, "A", "B")
Text2.Text = Replace(Text2.Text, "C", "D")
Text2.Text = Replace(Text2.Text, "E", "F")
0
 

Author Comment

by:kalaka
ID: 9782753
That doesnt work. THATS WHY IM ASKING IN THE FISRT PLACE!
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 9782897
before you start shouting, please look at the comment... there is a slight difference b/w mine and yours.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 152
Macro Excel - Multiple If conditions 2 94
Problem to With line 4 87
VBA: Insert New column with specific format type 12 57
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question