Solved

Replacing

Posted on 2003-11-18
13
253 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
Comment Utility
Replace(Text1.Text, "A", "B")
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
Remember this is with capslock ON
0
 

Author Comment

by:kalaka
Comment Utility
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
Comment Utility
Text1.Text = Replace(Text1.Text, "A", "B")
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

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

Author Comment

by:kalaka
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That doesnt work. THATS WHY IM ASKING IN THE FISRT PLACE!
0
 
LVL 18

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 36
using Access 8 52
Add a task in Outlook from access 11 32
How to compare ms sql hashbytes results within vb6 5 34
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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