We recently used the randomize function and a SELECT CASE statement on some specific webpages on ASPFree. We discovered the randomize statement begins with 0 when using VB.NET. Let us explain.
'SELECT CASE starting at 1 and no ELSE statement 'Problem is once in a while nothing displays
<html> <body> <% Dim r as new Random() Select r.Next(3)
Case 1 response.write("some bold text") Case 2 response.write("some underlined text") Case 3 response.write("some italic text") End Select %>
</body> </html>
Every so often nothing would be displayed. After some investigation and understanding if there isn't an ELSE in the SELECT CASE statement why text to wouldn't display? In the specific function, an ELSE statement wasn't appropriate. What we found is to start the CASE statement at zero(0) instead of 1. The other option is to put an ELSE statement if applies. We wanted to understand why this was happening.
'SELECT CASE starting at 0 and no ELSE statement 'an ELSE statement would solve it also.
<html> <body> <% Dim r as new Random() Select r.Next(3)
Case 1 response.write("some bold text") Case 2 response.write("some underlined text") Case 3 response.write("some italic text") Else response.write("Default text to be displayed") End Select %> </body> </html>
OR
'SELECT CASE starting at 0 and no ELSE statement 'Something will display everytime.
<html> <body> <% Dim r as new Random()
Select r.Next(3)
Case 0 response.write("some bold text") Case 1 response.write("some underlined text") Case 2 response.write("some italic text") End Select %>
</body> </html>
This probably isn't rocket science, after an hour or so of going WHAT!#@%@. This problem was solved, the easiest things can make a developer go crazy when working on a project. Hopefully this tip saves you the frustration we discovered!