View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Problem with a very simple code in Visual basic

The problem is that A and B as string (text) variables, and the
"+" sign is the old way of concatenating (combining) strings.
Instead, try,

Dim A As Double
Dim B As Double
Dim C As Double
A = Application.InputBox(prompt:="Enter A:", Type:=1)
B = Application.InputBox(prompt:="Enter B:", Type:=1)
C = A + B

The Type:=1 argument restricts users to entering numbers. It
prevents non-numeric entry.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Vepa" wrote in message
...
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