Solved

Replacing

Posted on 2003-11-18
13
259 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

617 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