Display label results on a message box

does anyone know how this can be done?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 18231 Views - Last Post: 24 March 2008 - 08:50 PM Rate Topic: -----

#1 Mishka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-March 08

Display label results on a message box

Post icon  Posted 17 March 2008 - 05:24 PM

Hello,

I am trying to display 3 different label results + a grand total of those 3 results on a message box. Does anyone know how I can achieve this? I have been searching the web all day to try and find some help with using a message box to display the results of 3 different labels. Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Display label results on a message box

#2 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: Display label results on a message box

Posted 17 March 2008 - 05:32 PM

dim first as string = label1.text
dim second as string = label2.text
dim third as string = label3.text
msgbox(First + Second + Third)


This post has been edited by ferrari12508: 17 March 2008 - 05:33 PM

Was This Post Helpful? 0
  • +
  • -

#3 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Display label results on a message box

Posted 17 March 2008 - 10:45 PM

Here is some example code to help you, it has been commented to help you gain an understanding of this subject.

' This array will hold the integers we need to perform
' mathematical calculations with.
Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
                            Convert.ToInt32(Label2.Text), _
                            Convert.ToInt32(Label3.Text)}

' This function will create a message box, which will show all the values
' of the labels, and then show the resulting sum of all three integers.
MessageBox.Show("Label1 = " + Label1.Text + ", Label2 = " + Label2.Text _
                + ", Label3 = " + Label3.Text + ", Result = " + Convert.ToString( _
                numbers(0) + numbers(1) + numbers(2)))



You should always use MessageBox.Show over MsgBox in VB.NET, as MsgBox is a part of the old Legacy VB functions, which in part resolves it obsolete.

Hope that helps. :)
Was This Post Helpful? 1

#4 ferrari12508  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3
  • View blog
  • Posts: 1,115
  • Joined: 02-November 07

Re: Display label results on a message box

Posted 18 March 2008 - 03:27 PM

excuse me RodgerB, if that is your real name...

<rant>

msgbox and messagebox.show have different functions if you look closely, so certain people might like that msgbox is a little faster than messagebox.show when they don't need the extras that messagebox.show offers.

</rant>
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Display label results on a message box

Posted 18 March 2008 - 03:42 PM

View Postferrari12508, on 18 Mar, 2008 - 03:27 PM, said:

msgbox and messagebox.show have different functions if you look closely, so certain people might like that msgbox is a little faster than messagebox.show when they don't need the extras that messagebox.show offers.


Actually Rodger is correct, MsgBox is a legacy library left over from VB6, and those libraries wont be around forever so people need to get in the habit of using native .Net libraries before the legacy ones are gone :)
Was This Post Helpful? 0
  • +
  • -

#6 Mishka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-March 08

Re: Display label results on a message box

Posted 20 March 2008 - 06:41 AM

Ok, I have tried to use the example you have given... but it seems I am still getting blue lines under variables and I am not sure if I am using the right format for the string... here is my code below. Any suggestions?

  ' If we reach this point, we assume the input data is valid.
		' Calculate the totals per package and grand totals.

		' Calculate and display amount of PackageA
		Try

			' This array will hold the integers we need to perform
			' mathematical calculations with.
			Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
										Convert.ToInt32(Label2.Text), _
										Convert.ToInt32(Label3.Text)}
			Dim intTotalA As Integer		' PackageA Total
			Dim intTotalB As Integer		' PackageB Total
			Dim intTotalC As Integer		' PackageC Total



			' This function will create a message box, which will show all the values
			' of the labels, and then show the resulting sum of all three integers.
			MessageBox.Show("Package A: = " + CInt(intTotalA.Text) * 99.00 ", "Package B: = " + CInt(intTotalB.Text) _
							* 199.00 ", Package C: = " + CInt(intTotalC.Text) * 299.00 ", Result = " + Convert.ToString( _
							numbers(0) + numbers(1) + numbers(2)))




		Catch ex As Exception

		End Try

	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Display label results on a message box

Posted 20 March 2008 - 06:47 AM

Where are you getting the syntax error?
Was This Post Helpful? 0
  • +
  • -

#8 Mishka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-March 08

Re: Display label results on a message box

Posted 20 March 2008 - 07:56 AM

	 Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
										Convert.ToInt32(Label2.Text), _
										Convert.ToInt32(Label3.Text)}
			Dim intTotalA As Integer		' PackageA Total
			Dim intTotalB As Integer		' PackageB Total
			Dim intTotalC As Integer		' PackageC Total



			' This function will create a message box, which will show all the values
			' of the labels, and then show the resulting sum of all three integers.
			MessageBox.Show("Package A: = " + CInt(txtTotalA.Text) * 99.00 ", "Package B: = " + CInt(txtTotalB.Text)
							* 199.00 ", Package C: = " + CInt(txtTotalC.Text) * 299.00 ", Result = " + Convert.ToString( _
							numbers(0) + numbers(1) + numbers(2)))


I am getting errors in the following places...

1.)Dim intTotalA As Integer ' PackageA Total
2.)Dim intTotalB As Integer ' PackageB Total
3.)Dim intTotalC As Integer ' PackageC Total

Also getting errors in this block where underlined...
MessageBox.Show("Package A: = " + CInt(txtTotalA.Text) * 99.00 ", "Package B: = " + CInt(txtTotalB.Text)
* 199.00 ", Package C: = " + CInt(txtTotalC.Text) * 299.00 ", Result = " + Convert.ToString( _
numbers(0) + numbers(1) + numbers(2)))

The underlined variables above are where I get the blue lines... and the second block where the underlines are I get the blue lines... plus where I bolded the CInt(txtTotalB.Text)... this variable is coming up in red print not black like the other variables in this block.

Any idea what I am doing wrong? I also need to format the label results that display in the message box to currency. Any help would be appreciated. Thanks
Was This Post Helpful? 0
  • +
  • -

#9 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Display label results on a message box

Posted 20 March 2008 - 08:44 PM

Please post the errors you are recieving with the code, not just the places you are recieving them. (e.g. "Name 'txtTotalA' is not declared").
Was This Post Helpful? 0
  • +
  • -

#10 SpeeDemon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 18-March 08

Re: Display label results on a message box

Posted 20 March 2008 - 11:35 PM

View PostMishka, on 20 Mar, 2008 - 07:56 AM, said:

	 Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
										Convert.ToInt32(Label2.Text), _
										Convert.ToInt32(Label3.Text)}
			Dim intTotalA As Integer		' PackageA Total
			Dim intTotalB As Integer		' PackageB Total
			Dim intTotalC As Integer		' PackageC Total



			' This function will create a message box, which will show all the values
			' of the labels, and then show the resulting sum of all three integers.
			MessageBox.Show("Package A: = " + CInt(txtTotalA.Text) * 99.00 ", "Package B: = " + CInt(txtTotalB.Text)
							* 199.00 ", Package C: = " + CInt(txtTotalC.Text) * 299.00 ", Result = " + Convert.ToString( _
							numbers(0) + numbers(1) + numbers(2)))


You declare values "intTotalA" etc, then later call "txtTotalA".

Should the MessageBox.Show read "intTotalA" etc instead? This will also avoid the warnings at your declarations. They are unused.
Was This Post Helpful? 0
  • +
  • -

#11 Mishka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-March 08

Re: Display label results on a message box

Posted 21 March 2008 - 09:06 AM

Error 1 Variable 'intTotalA' hides a variable in an enclosing block. line 80 column 17
Error 2 Variable 'intTotalB' hides a variable in an enclosing block. line 81 column 17
Error 3 Variable 'intTotalC' hides a variable in an enclosing block. line 82 column 17
Error 4 Option Strict On disallows implicit conversions from 'String' to 'Double'. line 88 column 29
Error 5 Comma, ')', or a valid expression continuation expected. line 88 column 71
Error 6 Syntax error. line 89 column 29

The block starts with line 70 and ends on line 97

' Calculate the totals per package and grand totals.

		' Calculate and display amount of PackageA
		Try

			' This array will hold the integers we need to perform
			' mathematical calculations with.
			Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
										Convert.ToInt32(Label2.Text), _
										Convert.ToInt32(Label3.Text)}
			Dim [u]intTotalA [/u] As Integer		' PackageA Total
			Dim [u]intTotalB [/u] As Integer		' PackageB Total
			Dim [u]intTotalC[/u] As Integer		' PackageC Total



			' This function will create a message box, which will show all the values
			' of the labels, and then show the resulting sum of all three integers.
			MessageBox.Show[u]("Package A: = "[/u] + CInt(intTotalA) * 99.00[u] ", "[/u]Package B: = " + CInt(intTotalB)
						   [u] * [/u] 199.00 ", Package C: = " + CInt(intTotalC) * 299.00 ", Result = " + Convert.ToString( _
							numbers(0) + numbers(1) + numbers(2)))




		Catch ex As Exception

		End Try


I don't know how to get the line #s to display in the code when posting otherwise I would have done that to make it easier to count which lines are causing the errors, so I just underlined the parts where errors occur.
Was This Post Helpful? 0
  • +
  • -

#12 Mishka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-March 08

Re: Display label results on a message box

Posted 21 March 2008 - 09:25 AM

I changed some of my code and now I only get one error message... on line 89 column 29

Error 1 Option Strict On disallows implicit conversions from 'String' to 'Double'. line 88 column 29

MessageBox.Show("Label1 = " <- this bold/underlined part is where i get an error


' Calculate the totals per package and grand totals.

		' Calculate and display amount of PackageA
		Try

			' This array will hold the integers we need to perform
			' mathematical calculations with.
			Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
										Convert.ToInt32(Label2.Text), _
										Convert.ToInt32(Label3.Text)}
			Dim intLabel1 As Integer		' PackageA Total
			Dim intLabel2 As Integer		' PackageB Total
			Dim intLabel3 As Integer		' PackageC Total



			' This function will create a message box, which will show all the values
			' of the labels, and then show the resulting sum of all three integers.
			MessageBox.Show("Label1 = " + CInt(Label1.Text) * 99.0 + ", Label2 = " + CInt(Label2.Text) _
							* 199.0 + ", Label3 = " + CInt(Label3.Text) * 299.0 + ", Result = " + Convert.ToString( _
							numbers(0) + numbers(1) + numbers(2)))




		Catch ex As Exception

		End Try

Was This Post Helpful? 0
  • +
  • -

#13 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,433
  • Joined: 22-February 08

Re: Display label results on a message box

Posted 21 March 2008 - 10:39 AM

when u print them out to a messagebox, convert them all to string. they dont need to be ints at that point cause ur not going to be doing anything with them except displaying them
Was This Post Helpful? 0
  • +
  • -

#14 Mishka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-March 08

Re: Display label results on a message box

Posted 23 March 2008 - 02:05 PM

I am getting one error on the ("Label1 = " line... when I put my mouse over this I get a message saying "Option strict on disallows implicet conversions from 'String' to 'Double'"... how do I fix this... and what do I need to change in the messagebox block to convert them to sting and not use integers???

 ' This array will hold the integers we need to perform
			' mathematical calculations with.
			Dim numbers() As Integer = {Convert.ToInt32(Label1.Text), _
										Convert.ToInt32(Label2.Text), _
										Convert.ToInt32(Label3.Text)}
			Dim intLabel1 As Integer		' PackageA Total
			Dim intLabel2 As Integer		' PackageB Total
			Dim intLabel3 As Integer		' PackageC Total



			' This function will create a message box, which will show all the values
			' of the labels, and then show the resulting sum of all three integers.
			MessageBox.Show(" Label1 = " + CInt(txtPackageA.Text) * 99.0 + ", Label2 = " + CInt(txtPackageB.Text) _
							* 199.0 + ", Label3 = " + CInt(txtPackageC.Text) * 299.0 + ", Result = " + Convert.ToString( _
							numbers(0) + numbers(1) + numbers(2)))

Was This Post Helpful? 0
  • +
  • -

#15 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Display label results on a message box

Posted 23 March 2008 - 02:22 PM

After you perform your calculations, convert the result back to a String.
MessageBox.Show(" Label1 = " + (CInt(txtPackageA.Text) * 99.0).ToString + ", Label2 = " + (CInt(txtPackageB.Text) _
   * 199.0).ToString + ", Label3 = " + (CInt(txtPackageC.Text) * 299.0).ToString + ", Result = " + Convert.ToString( _
   numbers(0) + numbers(1) + numbers(2)))

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2