Advertisement
2002VB String Manipulation #19600

IsNullEx

This code provides an IsNull function like that used in SQL Server. This allows you to check if a variable contains null, and if so return a specific value. This can prevent you from having to write things like iif(not isnull(rst!FieldName), rst!FieldName, ""). For new programmers, especially those working with databases, you will quickly become aware that trying to access a database field that contains a null value often results in the dreaded error #94 - Invalid Use of Null, which means you constantly have to write code to trap for that possibility.

AI

ملخص الذكاء الاصطناعي: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

كود المصدر
original-source
Public Function IsNullEx(ValueToCheck As Variant, varWhatToReturnIfNull) As Variant
  If IsNull(ValueToCheck) Then
    IsNullEx = varWhatToReturnIfNull
  Else
    IsNullEx = ValueToCheck
  End If
End Function
Usage example:
txtClientName = IsNullEx(rst!ClientName, "unknown")

<%
Function SortAlpha(ary, direction)
'###############################################################
'# USAGE: Call The function as any other, specify ASC or DESC #
'#    to change the ordering direction. This is meant to  #
'#    be similar to SQL style syntax            #
'###############################################################
  StopWork=False
  Do Until StopWork=True
    StopWork=True
    For i = 0 to UBound(ary)
      If i=UBound(ary) then Exit For
      If UCase(Direction) = "DESC" Then
        If ary(i) < ary(i+1) Then
          firstval = ary(i)
          secondval = ary(i+1)
          ary(i) = secondval
          ary(i+1) = firstval
          StopWork=False
        End If
      Else
        If ary(i) > ary(i+1) Then
          firstval = ary(i)
          secondval = ary(i+1)
          ary(i) = secondval
          ary(i+1) = firstval
          StopWork=False
        End If
      End If
    Next
  Loop
  SortAlpha=ary
End Function

Function Sort(ary)
  KeepChecking = TRUE
  Do Until KeepChecking = FALSE
    KeepChecking = FALSE
    For I = 0 to UBound(ary)
      If I = UBound(ary) Then Exit For
      If ary(I) > ary(I+1) Then
        FirstValue = ary(I)
        SecondValue = ary(I+1)
        ary(I) = SecondValue
        ary(I+1) = FirstValue
        KeepChecking = TRUE
      End If
    Next
  Loop
  Sort = ary
End Function
Function PrintArray(ary)
  For i=0 to UBound(ary)
    Response.Write(ary(i) & "<BR>" & vbCrLf)
  Next
End Function
Dim MyArray
MyArray = Array(1,5,"shawn","says","hello",123,12,98)
PrintArray(MyArray)
Response.Write("<HR><h1>Sorted Alpha ASC</h1><br><br>")
PrintArray(SortAlpha(MyArray, "ASC"))
Response.Write("<HR><h1>Sorted Alpha DESC</h1><br><br>")
PrintArray(SortAlpha(MyArray, "DESC"))
Response.Write "<HR>"
For I = 0 to Ubound(Sort(MyArray))
  Response.Write MyArray(I) & "<br>" & vbCRLF
Next
%>
التعليقات الأصلية (3)
مسترجع من Wayback Machine