Display label results on a message boxdoes anyone know how this can be done?
16 Replies - 18231 Views - Last Post: 24 March 2008 - 08:50 PM
#1
Display label results on a message box
Posted 17 March 2008 - 05:24 PM
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
Replies To: Display label results on a message box
#2
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
#3
Re: Display label results on a message box
Posted 17 March 2008 - 10:45 PM
' 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.
#4
Re: Display label results on a message box
Posted 18 March 2008 - 03:27 PM
<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>
#5
Re: Display label results on a message box
Posted 18 March 2008 - 03:42 PM
ferrari12508, on 18 Mar, 2008 - 03:27 PM, said:
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
#6
Re: Display label results on a message box
Posted 20 March 2008 - 06:41 AM
' 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
#7
Re: Display label results on a message box
Posted 20 March 2008 - 06:47 AM
#8
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
#9
Re: Display label results on a message box
Posted 20 March 2008 - 08:44 PM
#10
Re: Display label results on a message box
Posted 20 March 2008 - 11:35 PM
Mishka, 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.
#11
Re: Display label results on a message box
Posted 21 March 2008 - 09:06 AM
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.
#12
Re: Display label results on a message box
Posted 21 March 2008 - 09:25 AM
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
#13
Re: Display label results on a message box
Posted 21 March 2008 - 10:39 AM
#14
Re: Display label results on a message box
Posted 23 March 2008 - 02:05 PM
' 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)))
#15
Re: Display label results on a message box
Posted 23 March 2008 - 02:22 PM
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)))
|
|

New Topic/Question
Reply




MultiQuote





|