Problem with a very simple code in Visual basic
Because input box returns string, not number, so conatenation of 3 and 4
gives 34.
Declare variables
dim a as double, b as double
or dim a as integer, b as integer.
It will convert it to numbers, however it will crash when user enters
not numbers.
So you can:
dim A as string, b as string
dim iA as integer, iB as integer
and using isNumber you can check if data enterd by user is a number and
after that convert it to integer
iA = cInt (A)
Vepa wrote:
Hi,
I'm beginning my studies with Visual Basic on my Excel 2003 and I have a
problem with calculations concerning adding. I will write the source and I
hope somebody could help me. The problem is that the calculation below gives
me a result 34 if A=3 and B=4. However if I try to multiply these numbers the
program gives me the right answer..
Sub Investments()
A = InputBox("Enter domestic investment amount")
B = InputBox("Enter foreign investment amount")
TotalInvestment = A + B
MsgBox "The total investment= " & TotalInvestment
End Sub
Regards
Vepa
|