VB icon

Toggles & Array Size - "One liners"

Email
Submitted on: 9/16/2017 7:49:49 AM
By: Nicholas Forystek  
Level: Beginner
User Rating: Unrated
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 2986
author picture
 
     Two simple Boolean mathematical functions; the first is Toggles! A switch function! Simply what it does is use math and data type conversions to toggle the input of 1, 0 or -1 and keep it changing like a turbine with subsequent calls. The exception is of the ability of calling it twice with adding on a negative to the input. Example, Toggles(-Toggles(#)), then it toggles from 1 to -1 and -1 to 1, but leaves 0 at 0. The second function returns the number of elements in an array taking into the consideration of allowances to zero elements and zero indices as well as non-zero indices. I wanted both of these functions one line and it was sort of simplistic, but sort of brain racking as well too with the single line formality personally obtained.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Toggles & Array Size - "One liners" 
' Description:Two simple Boolean mathematical functions; the first is Toggles! A switch function! Simply what it does is use math and data type conversions to toggle the input of 1, 0 or -1 and keep it changing like a turbine with subsequent calls. The exception is of the ability of calling it twice with adding on a negative to the input. Example, Toggles(-Toggles(#)), then it toggles from 1 to -1 and -1 to 1, but leaves 0 at 0. The second function returns the number of elements in an array taking into the consideration of allowances to zero elements and zero indices as well as non-zero indices. I wanted both of these functions one line and it was sort of simplistic, but sort of brain racking as well too with the single line formality personally obtained.
' By: Nicholas Forystek
'**************************************

Public Function Toggles(ByVal Value As Long) As Long
 Toggles = (-CInt(CBool(Value)) + -1) + -CInt(Not CBool(-Value + -1))
End Function
Public Function ArraySize(InArray) As Long
 ArraySize = (UBound(InArray) + -CInt(Not CBool(-LBound(InArray))))
End Function


Other 22 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.