Solved

Replacing

Posted on 2003-11-18
13
254 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 42
How to make an ADE file by code? 11 80
MsgBox 4 48
VB 6 error 5 in windows 10 but not in XP 7 46
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

11 Experts available now in Live!

Get 1:1 Help Now