Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<b>Another simple question</b>

Status
Not open for further replies.

The

Programmer
Jul 30, 2001
92
CA
How would you make a variable have a limit of zero being the lowest you can go? (In runtime the user will be subracting from a variable, and I don't want it to go below 0).
 
I do not know of an integer variable with a minimum of zero, but if there is and you try to set it to a below zero value you wil get an error.
Creating a property wil do it, reading the property will look like this:
Text1 = Form1.myposint
setting the property wil look like this:
Form1.myposint = Text1
the property looks like this:
Dim aPositiveInt As Integer

Public Property Let myposint(new_myposint As Integer)
If new_myposint > -1 Then
aPositiveInt = new_myposint
Else
' Something is trying to give a value lower than 0 take appropriate action
MsgBox "Can`t make the value lower than zero"
End If
End Property

Public Property Get myposint() As Integer
myposint = aPositiveInt
End Property
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top