Adding numbers

Dumferling

Member
Local time
Today, 01:26
Joined
Apr 28, 2020
Messages
102
I have extracted a series of numbers from a list box and now I want to total them and store the result in a variable. When I do this I get 12345 which is just the numbers as extracted (Dim as Integer). How do I get them to actually add them together? I am sure this is simple but I can't see why it is not working. Code below:

Dim vblFin, vblOps, vblRep, vblReg, vblAlt, vblTotal As Integer
vblFin = Me.RiskFinancial.Column(1)
vblOps = Me.RiskOperational.Column(1)
vblRep = Me.RiskReputational.Column(1)
vblReg = Me.RiskRegulatory.Column(1)
vblAlt = Me.RiskAlternatives.Column(1)
vblTotal = vblFin + vblOps + vblRep + vblReg + vblAlt
 
Perhaps Dim your variables correctly?
Only vbTotal is an integer, the rest are Variant. :(

You need to explicitly define each one.
Dim A as integer, B as integer etc.....
 
You need to explicitly define your variables

This Dim vblFin, vblOps, vblRep, vblReg, vblAlt, vblTotal As Integer
Only dims vblTotal as an integer, the rest aren't being defined so are actually being dimmed as Variants

Dim vblFin As Integer, vblOps As Integer, vblRep As Integer, vblReg As Integer, vblAlt As Integer, vblTotal As Integer
 
you can also use:

...
...
vblTotal = Val(vblFin & "")+ Val(vblOps & "") + Val(vblRep & "") + Val(vblReg +& "") + Val( vblAlt & "")
 
You need to explicitly define your variables

This Dim vblFin, vblOps, vblRep, vblReg, vblAlt, vblTotal As Integer
Only dims vblTotal as an integer, the rest aren't being defined so are actually being dimmed as Variants

Dim vblFin As Integer, vblOps As Integer, vblRep As Integer, vblReg As Integer, vblAlt As Integer, vblTotal As Integer
Always the simple stuff that trips me up. Thanks!
 

Users who are viewing this thread

Back
Top Bottom