Solved

Insert Into A String From Textbox

Posted on 2009-04-05
7
333 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 200 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 300 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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 300 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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