Visual Basic Help

Posts 1–4 of 4 · Page 1 of 1
Visual Basic Help
So I'm new at this Visual Basic stuff, and I did a calculator but then I wanted to add a "variable name" that could show up on message boxes.
Example:

FirstNumber = Val(TextBox1.Text)
SecondNumber = Val(TextBox2.Text)

Label1.Text = FirstNumber - SecondNumber

MessageBox.Show("Calculated {FirstNumber} - {SecondNumber}.")

the coding here a bit awful, but can it be done or not?
Quote Originally Posted by zTwix0R View Post
So I'm new at this Visual Basic stuff, and I did a calculator but then I wanted to add a "variable name" that could show up on message boxes.
Example:

FirstNumber = Val(TextBox1.Text)
SecondNumber = Val(TextBox2.Text)

Label1.Text = FirstNumber - SecondNumber

MessageBox.Show("Calculated {FirstNumber} - {SecondNumber}.")

the coding here a bit awful, but can it be done or not?
nononono.

Code:
MessageBox.Show("Calculated" & FirstNumber - SecondNumber)
Otherwise, all the other stuff should work.
Quote Originally Posted by zTwix0R View Post
Example:
Code:
MessageBox.Show("Calculated {FirstNumber} - {SecondNumber}.")
That looks very C++ ish, where the values are substituted into the string : The "format" string functions. I don't think vb has an equivalent.

Code:
Dim FirstNumber As Integer = Val(TextBox1.Text)
Dim SecondNumber As Ineger = Val(TextBox2.Text)

Label1.Text = (FirstNumber - SecondNumber).ToString()

MessageBox.Show("Calculated " & FirstNumber.ToString() & " - " & SecondNumber.ToString())
edit:

If you don't have Option Strict on, you don't need to call .ToString() on the Integers. It's a little verbose; probably more clear to a beginner to just leave them off.


Code:
Dim FirstNumber As Integer = Val(TextBox1.Text)
Dim SecondNumber As Ineger = Val(TextBox2.Text)

Label1.Text = (FirstNumber - SecondNumber).ToString()

MessageBox.Show("Calculated " & FirstNumber & " - " & SecondNumber)
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?