Reputation: 3440
I'm having a really hard time finding an answer for this, with such generic terminology, and it's possible my question is still difficult to parse. I have some code with a variable representing the amount of free disk space remaining as a percentage. I want to call it into a function, where I use the reverse amount in a message to the user, i.e. the amount of used space. Can I do a little math in the function call?
Public Sub MyApp()
Dim nFreeSpace As Integer
nFreeSpace = GetFreeSpace
DisplayUsedSpace 100 - nFreeSpace 'Is this valid?
End Sub
Private Function DisplayUsedSpace(ByVal nUsedSpace As Integer) As Boolean
MsgBox("You have used " & nUsedSpace & "% of your disk drive space.")
End Function
Upvotes: 2
Views: 145
Reputation: 16257
Of course you can - VB will calc the expression first.
You could also reverse it before the call
Public Sub MyApp()
Dim nUsedSpace As Integer
nUsedSpace = 100 - GetFreeSpace
DisplayUsedSpace nUsedSpace
End Sub
If you want it really compact:
Public Sub MyApp()
Call DisplayUsedSpace(100 - GetFreeSpace)
End Sub
Upvotes: 3
Reputation: 12804
Yes, that is valid. Although, I probably would write it as this
Call DisplayUsedSpace(100 - nFreeSpace)
But, your code would work fine too.
Upvotes: 5