Hi, I have a simple piece of code that calculates the mass of a gas at a known pressure within a fixed volume (please see below). However, when I run said code, I get a 'Run-time error '6': Overflow' error. When I scroll the curser across the offending line (i.e. m(1) =...) the last bit in brackets (i.e. ...(R * T * Z)) shows up as '(R * T * Z) = <Overflow>'. After several hours of head scratching, I found that if I slightly changed the ordering to (R * Z * T) i.e. reverse the T and Z, the code works.
Public Const V = 20
Public Const atm = 1.013
Public Const Mwt = 28.01
Public Const R = 8314
Public Const T = 278
Sub Example()
Dim P(1 To 2), m(1 To 2) As Variant
P(1) = 0
Z = 0.9991
m(1) = (P(1) + atm) * (10 ^ 5) * V * Mwt / (R * T * Z)
ActiveCell.Value = m(1)
End Sub
I'm not the most proficient VBA user (so I'm guessing the reason is obvious), but I am at a complete loss as to why reversing the Z and T variables would make a difference.
Any help / assistance / enlightenment anyone could provide would be much appreciated.
Kind regards,
2016LM
Public Const V = 20
Public Const atm = 1.013
Public Const Mwt = 28.01
Public Const R = 8314
Public Const T = 278
Sub Example()
Dim P(1 To 2), m(1 To 2) As Variant
P(1) = 0
Z = 0.9991
m(1) = (P(1) + atm) * (10 ^ 5) * V * Mwt / (R * T * Z)
ActiveCell.Value = m(1)
End Sub
I'm not the most proficient VBA user (so I'm guessing the reason is obvious), but I am at a complete loss as to why reversing the Z and T variables would make a difference.
Any help / assistance / enlightenment anyone could provide would be much appreciated.
Kind regards,
2016LM