Hi goo day! I'am Darrel, a newbie with visual basic, i have a problem with my recent project.
the projecti have is to replace the text from one letter to another. I dont know how to code it.
I'am using text box for my (input), another textbox for the letter to be replace, another text box for the letter to be place. and display the whole text in a label..
can some give me some hint or sample codes. Thank you so much!!!
Hoping for an immediate reponse for it!!!
10 5675
Dear Friend, Try this.......
1. I have one text box named TxtA and command button CmdProcess
2. I want to replace the text "a" with "z" in TxtA on cmdProcess - click
3. Please look the code on cmdProcess_clic k
4. Instead of "a" you can use other textbox.text - Dim a As String
-
a = TxtA.Text
-
a = ""
-
Dim x As String
-
x = ""
-
For i = 1 To Len(TxtA)
-
If Mid(TxtA, i, 1) = "a" Then
-
x = x + "b"
-
Else
-
x = x + Mid(TxtA, i, 1)
-
End If
-
Next
-
MsgBox x
give a feed back
samy
Actually, while the details may depend on what version of VB you are using, in VB6 you can use the Replace() function to do it in one statement.
that's not the output that i have to achieve, the program is like this
the user must enter a word in a textbox1(of any length) and must enter/assign a letter in textbox2 which is the letter to be replace from textbox1 and the user must enter a letter in textbox3 which is the letter to be substituted. and display the whole text in a label.
its like this if the user enters the word "paragraph" and the user wanted to change all letter "a" with letter "b" and the result must be "pbrbgrbph" .
hope you can help me sir.... its very difficult for me.... thank you
That's what the code did, that samycbe posted. It's just that some of it was hard-coded rather than being taken from a textbox. After all, you can't expect us to do everything for you - you need to make a serious attempt at the work yourself.
Anyway, like I said, check out the Replace function. It's in the manual, and will do it all in one statement.
that's not the output that i have to achieve, the program is like this
the user must enter a word in a textbox1(of any length) and must enter/assign a letter in textbox2 which is the letter to be replace from textbox1 and the user must enter a letter in textbox3 which is the letter to be substituted. and display the whole text in a label.
its like this if the user enters the word "paragraph" and the user wanted to change all letter "a" with letter "b" and the result must be "pbrbgrbph" .
hope you can help me sir.... its very difficult for me.... thank you
try this code
replace("<thy string>","<repl ace char>","<replac ed by>")
lbl.caption=rep lace(txt1.text, txt2.text,txt3. text)
yes i know that, that's why ive tried using mid.
the code its like this - Private Sub Command1_Click()
-
Dim str1 As String
-
Dim str2 As String
-
Dim str3 As String
-
-
-
str1 = Text1.Text
-
str2 = Text2.Text
-
str3 = Text3.Text
-
-
If Mid(str1, 1, 1) = str2 Then
-
Mid(str1, 1, 1) = str3
-
Label4.Caption = Mid(str1, 1)
-
-
End If
-
End Sub
and its working...but the problem is wat if the text is to long, i dont know how to loop my condition..
Well, you could use a For loop with the length of the original string as the upper limit.
Also, when posting code, please use appropriate tags around it for readability. Details can be found here.
can help me how to construct a loop using "FOR".
guys, ive done it am finished with my project, thanks a lot for all the help, to contribute here the code.... - Private Sub Command1_Click()
-
Dim str1 As String
-
Dim str2 As String
-
Dim str3 As String
-
Dim Counter As Integer
-
-
-
str1 = Text1.Text
-
str2 = Text2.Text
-
str3 = Text3.Text
-
-
For i = 1 To Len(str3)
-
Counter = i + 1
-
If Mid$(str3, i, 1) = str2 Then
-
Mid$(str3, i, 1) = str1
-
Label4.Caption = Mid$(str3, 1)
-
End If
-
Next
-
-
End Sub
Hope you'll still help me guys sooner or later.. thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: hokieghal99 |
last post by:
import os, string
print " "
setpath = raw_input("Enter the path: ")
def find_replace(setpath):
for root, dirs, files in os.walk(setpath):
fname = files
for fname in files:
find = string.find(file(os.path.join(root,fname),
'rb').read(), 'THIS')
print find
|
by: Xah Lee |
last post by:
suppose you want to do find & replace of string of all files in a
directory.
here's the code:
©# -*- coding: utf-8 -*-
©# Python
©
©import os,sys
©
©mydir= '/Users/t/web'
|
by: Daniel |
last post by:
I use an Access database to basically take data exports, import them,
manipulate the data, and then turn them into exportable reports. I do
this using numerous macros, and queries to get the data in the format
that I need it in order to create the reports that we use. So far this
has proven to be successful for the reports that I am doing and the
data that I am pulling into it. I just have one challenge that may
require a lot of work and I...
|
by: Neo Geshel |
last post by:
This works:
<form>
<asp:TextBox id="name" />
<%= name.ClientID %>
</form>
But this DOES NOT work:
<form>
|
by: scorpion53061 |
last post by:
This excel find/replace code works great under Excel 2003 but bombs with an
error (pasted below the code) in Excel 2000. Can anyone suggest an
alternative to make both happy? I am using vb.net windows application. I
also tried creating an object and assigning the find/replace event to it but
I also received errors.
I am a little under the gun on this one....
WSheet.Application.Selection.Replace(What:="NONE", Replacement:="",...
| |
by: Xah Lee |
last post by:
Interactive Find and Replace String Patterns on Multiple Files
Xah Lee, 2006-06
Suppose you need to do find and replace of a string pattern, for all
files in a directory. However, you do not want to replace all of them.
You need to look at it in a case-by-case basis. What can you do?
Answer: emacs.
|
by: peter |
last post by:
Hello all,
I'm looking for an advice.
Example (one block in ascii file):
$------------------------
NAME='ALFA'
CODE='x'
$------------------------
|
by: TOXiC |
last post by:
Hi everyone,
First I say that I serched and tryed everything but I cannot figure
out how I can do it.
I want to open a a file (not necessary a txt) and find and replace a
string.
I can do it with:
import fileinput, string, sys
fileQuery = "Text.txt"
sourceText = '''SOURCE'''
|
by: JoeP |
last post by:
Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False
oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient
oSMTP.Send(oMailMessage) (in this line I am getting the above err)
|
by: mouac01 |
last post by:
Newbie here. How do I do a find and replace in a binary file? I need
to read in a binary file then replace a string "ABC" with another
string "XYZ" then write to a new file. Find string is the same length
as Replace string. Here's what I have so far. I spent many hours
googling for sample code but couldn't find much. Thanks...
public static void FindReplace(string OldFile, string NewFile)
{
string sFind = "ABC"; //I probably need...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |