I think John was wondering why you were using VB6 Express edition rather
than Visual Basic 2005 Express Edition. You can get Visual Basic 2005
Express for free from the following web site:
http://msdn.microsoft.com/vstudio/express/vb/default.aspx
Integer is the correct data type to use. A data type indicates what type of
data your program is working with for a certain operation. This is because
numbers, for example, can be represented using characters, but you can't add
characters; you can only add numbers. On the other hand, you can place 2
numbers "next to" each other to form a new number. For example:
Dim one As String = "1"
Dim two As String = "2"
txtAnswer.Text = one + two ' answer is "12"
txtAnswer.Text = two - one ' exception thrown
Dim a as Integer = 1
Dim b as Integer = 2
txtAnswer.Text = a + b ' answer is 3
txtAnswer.Text = a - b ' answer is -1
txtAnswer.Text = a & b ' exception thrown
Now, there will may some confusion, as VB allows you to optionally use
incorrect data types by using the compiler option strict off, which is
unfortunately the default. This means that the compiler will perform some
data type conversions automagically, such as:
txtAnswer.Text = a + b ' answer is 3
txtAnswer is a TextBox. It contains text that the user types or works with
as text, or String data type. When option strict is off, the above line of
code will automagically convert [a + b] (3) to "3". But don't get them mixed
up. It's always better to keep track of your data types. Even with option
strict on, the following will work:
txtAnswer.Text = CType(a + b, String) ' converts 3 to "3"
If you don't keep track of your data types, you may experience errors that
are hard to track down.
Now, as to assigning them values, you can do this programmatically, as I've
illustrated above, or you can get input from the user, as in:
Dim first as Integer
Dim second as Integer
first = Convert.ToInt32(txtInputFirst.Text)
second = Convert.ToInt32(txtInputSecond.Text)
txtAnswer.Text = CType(first + second, String)
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
dick23 said:
No I haven 't assigned them a number. If I want the user to input the
numbers and come up with an answer then I guess Integer is not the correct
Data Type to use
I am liitle new to this, I have a book I am using called Visual Basic 2005
but download the VB6 express edition from Microsoft