Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert Into A String From Textbox

Posted on 2009-04-05
7
Medium Priority
?
336 Views
Last Modified: 2012-05-06
Hello,

Here is my little problem.  I am tying to figure out a way so that when someone puts a certing symbol in a textbox upon pressing a button that symbol turns into a string and is inserted into the string they already entered.

Ex.
If I write "Hello (%) How are you"  I would like the (%) to be converted into "Hello GetName(Player) How are you" when it is outputted into a text file.

(%) = GetName(Player)

This is the part of my code where it reads the textbox:

sw.WriteLine(vbTab & vbTab & vbTab & "Say(QuestGiver, " & Chr(34) & txtQuestAccSay.Text & Chr(34) & Chr(41))

sw is my StreamWriter

Sorry is this is a newb question im still learning.
Thank you
0
Comment
Question by:Daniel112
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Assisted Solution

by:CraigLazar
CraigLazar earned 800 total points
ID: 24074500
Hi,
If i understand your question, u can use the replace statement to do this fot u.
dim tmpStr as string
ex. tmpstr = replace(textbox1,"(%)","GetName(Player)")
What this function does is it takes the source string as paramter 1, then the value u want to replace as 2nd paramter, then the 3rd paramter is what u want to replace it with.
sw.WriteLine(vbTab & vbTab & vbTab & "Say(QuestGiver, " & Chr(34) & replace(txtQuestAccSay.Text,"(%)","GetName(Player)") & Chr(34) & Chr(41))
 
 hope this helps
 
 
 
0
 

Author Comment

by:Daniel112
ID: 24074969
If I do this I get an error saying expression produces no value.
But this is exactly what I am trying to do.
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1200 total points
ID: 24075020
Use this....
sw.WriteLine(vbTab & vbTab & vbTab & "Say(QuestGiver, " & Chr(34) & txtQuestAccSay.Text.Replace("(%)","GetName(Player)") & Chr(34) & Chr(41))

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Daniel112
ID: 24075057
Thank you both the reason why I got the expression error was because I was importing system.io.file when I should have not.

When I use either code that you guys gave me though it will output twice in the text file just like this:
 "Hello (%)"
 "Hello GetName(Player)"
How Would I get it to stop doubling again thank you.
0
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 1200 total points
ID: 24075069
You are calling the sw.WriteLine method twice. Remove the superfluous line of code.

Wayne
0
 

Author Comment

by:Daniel112
ID: 24075101
Thank you so much. Sorry didn't see that I have so much code I should have looked.  Thank you again.
0
 

Author Closing Comment

by:Daniel112
ID: 31566902
Very Fast. Thank You Both!
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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