Example The GetTextColor function uses the (1and1 web hosting) Switch function
Example The GetTextColor function uses the Switch function to return an RGB color value that depends on the sign of the integer passed to it as a parameter. To access the Color structure, it imports the System.Drawing namespace of the Base Class Library. Private Function GetTextColor(lValue As Integer) As Integer Dim fColor As New Color Dim iColor As Integer fColor = Switch(lValue > 0, Color.Blue, _ lValue = 0, Color.Black, _ lValue < 0, Color.Red) ' Convert color name to RGB color and strip out ' high order byte of high-order word iColor = fColor.ToArgb and &H00FFFFFF GetTextColor = iColor End Function Programming Tips and Gotchas The Switch function can prove to be an efficient alternative to If...Then...Else statements, but it can't be used in situations where multiple lines of code are required to be executed on finding the first True expression. Programming Tips and Gotchas Switch does not use short-circuiting. That is, even though it returns only the first True expression, it evaluates all expressions. As a result, Switch will generate a runtime error if any of these expressions are invalid. See Also Choose Function SYD Function Class Microsoft.VisualBasic.Financial Syntax SYD(cost, salvage, life, period ) cost Use: Required Data Type: Double
Hint: This post is supported by Gama web hosting php services