Solved

Insert Into A String From Textbox

Posted on 2009-04-05
7
328 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
  • 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

20 Experts available now in Live!

Get 1:1 Help Now