473,666 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

imbed variables in text inside of MessageBox(

Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write(" Answer: {0}",answer);

But instead do it inside of a MessageBox.Show (

Thanks
Jan 24 '06 #1
7 16828
generallee5686,

You can always format the string before you make the call to Show. So,
you could do this:

string prompt = string.Format(" Answer: {0}", answer);
MessageBox.Show (prompt);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"generallee5686 " <u18038@uwe> wrote in message news:5ada7c985c e28@uwe...
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write(" Answer: {0}",answer);

But instead do it inside of a MessageBox.Show (

Thanks

Jan 24 '06 #2
generallee5686,

MessageBox doesn't provide this out of the box, but it can be easily
workaround using String.Format method

Message.Box.Sho w(string.Format ("Answer: {0}",answer")) ;
--
HTH
Stoitcho Goutsev (100)

"generallee5686 " <u18038@uwe> wrote in message news:5ada7c985c e28@uwe...
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write(" Answer: {0}",answer);

But instead do it inside of a MessageBox.Show (

Thanks

Jan 24 '06 #3
generallee5686 <u18038@uwe> wrote:
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write(" Answer: {0}",answer);

But instead do it inside of a MessageBox.Show (


Use string.Format:

MessageBox.Show (string.Format ("Answer: {0}", answer),
...);

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 24 '06 #4
Wow that helped tons guys.
Thanks so much!
Jan 24 '06 #5
I like to build a function that takes params....

private void ShowMsg(string fmt, params object[] prms)
{
MessageBox.Show (string.Format( fmt, prms));
}

ShowMsg("Answer : {0}", answer);

-mdb

Jon Skeet [C# MVP] <sk***@pobox.co m> wrote in
news:MP******** *************** *@msnews.micros oft.com:
generallee5686 <u18038@uwe> wrote:
Just a quick question, im just taking a C# class.

Is there a way to have a variable inside a text string like:
Console.Write(" Answer: {0}",answer);

But instead do it inside of a MessageBox.Show (


Use string.Format:

MessageBox.Show (string.Format ("Answer: {0}", answer),
...);


Jan 24 '06 #6
Just another quick question about that.

So does like Console.Write have string.Format built into it or something?
Jan 25 '06 #7
generallee5686 <u18038@uwe> wrote:
Just another quick question about that.

So does like Console.Write have string.Format built into it or something?


Basically, yes. The overload
Console.Write (string, params object[])
calls through to TextWriter.Writ e(string, params object[])
which in turn calls string.Format.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 25 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1316
by: Fred Heida | last post by:
Hi, I try to implement dragging (and dropping) of text inside a rtf control (similar as word i guess) I have set AllowdDrop = true and setup the handlers for DragDrop, DragOver, DragEnter. is there anything else i need to do ? becuase if i now select some text in the control and start dragging this, the very first time i see the 'no entry' sign (none of my handlers getting
6
2432
by: TomB | last post by:
Hello all, On the page located at http://deimos.curious.be/~dusk/lyrics.php#gotn I have put the lyrics text inside <pre> elements so that the UA renders the linebreaks in the code. Because of this though some of the longer lines will be clipped by the div they're in (or cross its borders if I allow overflow) when viewed with a narrower viewport (or user-increased
1
1081
by: Paul | last post by:
Hi all, I'm making a custom control. I can set attributes to determine how the control is rendered, but I don't know how to access the text inside the tag. For example: <tagprefix:TestControl runat="server">My text</tagprefix:TestControl> How can I fetch the "My text" value in the custom control's code so I can use it in the Render method?
4
8526
by: Pete90 | last post by:
I am trying to change the text continously for the text inside a table but it stops after reaching the 2nd index in the array. Anyone can debug? Below are the coding: <script language="javascript"> var i=0; var text=; function dhtml(){ document.write("<table border='1' color='black'>");
11
3752
by: giannis | last post by:
How can i refer to a form's textbox.text inside a SQL clause ? I know how is that in Access* but at VB i receive error. * SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2=!.
2
2289
by: amitp | last post by:
hi i'm using MS Word2003 for my VB application which is a report. The word documents contains tables and the cells inside the table contain some fields. My application replaces the field values with Values from database. The problem i was getting is if the text length that is replaced is more than the cell length it was not displaying at all rather "Display Text Cannot Span More Than One Line" is displayed in that cell. I need to wrap the...
1
2681
by: countocram | last post by:
I have big problem, I'm using preg_replace() function for my highlighter function, after searching for particular keyword, once the hightler check box is checked it will highlight the content that matches the search keyword, the problem is, it also highlight the text inside the HTML tags that matches the keywords. here's the screenshot: http://www.fileden.com/files/2006/6/11/61581/screen.JPG I need a preg_replace() function that will not...
1
1498
by: StanislavPetrov | last post by:
Is it possible to delete the text inside .txt file?And if so,how?
4
1401
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi everydoby! I have an issue, I have an static image, and I need to write text inside it in runtime, but I don't know how! I can't use absolute position in atributtes style. Thanks.
0
8444
marktang
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...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7386
agi2029
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...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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();...
0
4198
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...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.