I am writing a set of Visual Basic functions that simulate the list functions 
available in ColdFusion.  I have a question on behaviors since I do not have 
access to a Coldfusion server to test at this time.

How does the ValuList function behave when a bad query/column pair are passed?  
Does it throw an error, or does it just not return anything?

As a bonus, here is my VB6 code so far:

=== Code Start ===

Option Explicit

'Set constants for lists
Private Const ListDelimiterDefault = ","

Public Function ListLen(ByVal List As String, Optional ByVal Delimiter As 
String = ListDelimiterDefault) As Integer
   'Get the length of the list
   ListLen = UBound(Split(List, Delimiter)) + 1
   
End Function

Public Function ListGetAt(ByVal List As String, ByVal Position As Integer, 
Optional ByVal Delimiter As String = ListDelimiterDefault) As String
   Dim TempArray
   'Get the list element at X
   'Convert to array
   TempArray = Split(List, Delimiter)
   'Make sure that the position is not out of bounds
   If Position - 1 > TempArray.UBound Then
      ListGetAt = ""
   Else
      ListGetAt = LTrim(RTrim(TempArray(Position - 1)))
   End If
End Function

Public Function ValueList(ByVal rsRecords As ADODB.Recordset, ByVal ColumnName 
As String, Optional ByVal Delimiter As String = ListDelimiterDefault) As String
   'This function converts an ADODB recordset column to a
   'list like the ColdFusion ValueList function.  It
   'assumes that both the recordset and column name  that
   'are passed are valid.  No error catching is included
   'in the function.  The bounds should be tested before
   'the function is called.
   Dim TempList As String
   TempList = ""
   'Convert the RecordSet Column to a list
   Do While Not rsRecords.EOF
      'Is there an element in the list?
      If Len(TempList) > 0 Then
         'Yes  - Add the delimiter
         TempList = TempList + Delimiter
         
      End If
      
      TempList = TempList & CStr(rsRecords(ColumnName))
      rsRecords.MoveNext
      
   Loop
   
   rsRecords.MoveFirst
   
   ValueList = TempList
   
End Function

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:218665
Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5

Reply via email to