Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Visual Basic: Replace Explained!
ViRuaL
post May 12 2005, 08:41 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 19
Joined: 12-May 05
Member No.: 5,018



This tutorial will go over how to effectively use the Replace function in Visual Basic.

1. So you have a string. Whether it be a label caption, an entry in a text box by the user of your program, or an item in a combo box. Let's say this is a bad string, something you do not want to appear. For instance, a user types "X is gay" in a text box, and you want to change that to something else. You can simply have it be deleted, or replaced with another value.

2. To make this work when a user types something in a textbox, you will need to use this sub:
CODE
Private Sub Text1_Change()

End Sub

Then we'll use the replace function. This looks like:
CODE
Replace(Expression, WhatToReplace, ReplaceWithWhat)


3. Now we want to find the text "X is gay" in the textbox. Remember our Text1_Change() Sub? We'll now insert the following code inside that sub.
CODE
Private Sub Text1_Change()
Dim txt
txt = Text1.Text
If InStr(1, Text1.Text, "X is gay") > 0 Then
Text1.Text = Replace(txt, "X is gay", "User is gay")
End If
End Sub


4. Done! What this code does is look for the value "X is gay" in Text1.Text, and if that is greater than 0 (meaning true) it replaces text in Text1.Text with "User is gay"

That's all there is to it. If you have any questions, feel free to e-mail me at ViRuaL@gmail.com. If you thought this was completely useless, feel free to flame it into oblivion.
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post May 12 2005, 09:02 PM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



Good job wink.gif Come back and post some more of such cool tips & tricks smile.gif

All the best,
m^e
Go to the top of the page
 
+Quote Post
ViRuaL
post May 12 2005, 09:05 PM
Post #3


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 19
Joined: 12-May 05
Member No.: 5,018



Why thank you. smile.gif
I will be posting a lot of cool things I've learned... Looking forward to my free hosting tongue.gif. Anyway, off to write my Start Button Editor post... Completely original code that I think is very cool.
Go to the top of the page
 
+Quote Post
iGuest
post Sep 27 2007, 07:38 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



I've been trying to figure this out for a while and this seems almost there... but when I add another "Remove" line only the top one works... any ideas?
Go to the top of the page
 
+Quote Post
iGuest
post Mar 30 2008, 09:54 PM
Post #5


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



VB replacing strings...
Visual Basic: Replace Explained!

How to relplace an oldword with an new word???

-question by Sukanya
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. [visual Basic] How To Confirm A Array Is Null(6)
  2. Visual Basic Help(7)
  3. Visual Basic: Unload Your Application Correctly!(1)
  4. Visual Basic: Change Your Start Button Text! (XP)(16)
  5. Visual Basic: Random Strings!(10)
  6. Visual Basic 6 + Crystal Reports 9(6)
  7. Visual Basic Names(11)
  8. New Features In Visual Studio 2005 Windows Forms(1)
  9. Visual Basic.NET Help Needed.(7)
  10. Is There A Free IDE For VB.NET Programming?(4)
  11. Visual Basic Express Tutorials(5)
  12. [help] Visual Studio .net 2005 Questions(8)
  13. Installed Internet Explorer 7?, Visual Basic Now Broken?(3)
  14. Visual Basic Projects: Scoreboard(0)
  15. Delete A Registry Subkey And Key(8)
  1. Necklace Problem In Visual Basic(3)


 



- Lo-Fi Version Time is now: 11th October 2008 - 03:42 AM