Solved

Replacing

Posted on 2003-11-18
13
255 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBScript - Find file starting with XXXX use that in runnig rest of code 9 75
passing parameter in sql procedure 9 61
MsgBox 4 59
Export Data to Different .csv Files 26 103
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now