Solved

Insert Into A String From Textbox

Posted on 2009-04-05
7
329 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Filesystemobject or .NET version 3 32
Tool Box 2 34
Name space syntax error 12 39
Host asp.net pages 5 25
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

914 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

18 Experts available now in Live!

Get 1:1 Help Now