I have a form where I gather values from a couple of text boxes. The user can either leave the box blank or enter a whole number typically between 1 and 2000. I'm new to passing values between subs but am trying to learn, so I think this is where my problem may be. As I step through the following code, I am not able to set the value for ‘NoC’ when the following if statement is ‘true’: If NoCAdd + NoCTot = NoCAdd then NoC = NoCAdd. The NoC = NoCAdd line is skipped and when hovering over ‘NoC’ the value is ‘0’ even if NoCAdd has a value of say '3'.
Since the main code is basically setting the value for 'NoC', I am assuming that nothing in the following Subs are affecting this value. Is that corrcet?
Also, I want to hold the value for 'NoC' in the following subs, should I call it ByVal rather than the way I currently show it. (info.: I have more than one following sub, but do not change the value of 'NoC' in them, only use it for other calculations)
What am I doing wrong? Thank you in advance.
Since the main code is basically setting the value for 'NoC', I am assuming that nothing in the following Subs are affecting this value. Is that corrcet?
Also, I want to hold the value for 'NoC' in the following subs, should I call it ByVal rather than the way I currently show it. (info.: I have more than one following sub, but do not change the value of 'NoC' in them, only use it for other calculations)
What am I doing wrong? Thank you in advance.
Code:
Sub FormC()
Dim NoCAdd As Variant, NoCTot As Variant
Dim NoC As Long
If IsNumeric(TextBox1) Then NoCAdd = TextBox1 Else NoCAdd = 0
If IsNumeric(TextBox2) Then NoCTot = TextBox2 Else NoCTot = 0
If NoCAdd + NoCTot > 0 Then
If NoCAdd + NoCTot = NoCAdd Then
NoC = NoCAdd
Else
NoC = 0
End If
End If
If NoC > 0 then
Call anothersub (NoC, NoCAdd, NoCTot)
End If
End Sub
Sub anothersub(NoC As Long, ByVal NoCAdd As Long, ByVal NoCTot As Long)
*more code*
End Sub