I have a Recordset obtained by the following query:
SELECT DISTINCT [Number] FROM NUMBERS WHERE CODE = 7 ORDER BY [Number]
The Recordset will therefore be a list of ordered numbers, eg. [6,14,37,59,81,145]
I would like to generate a long string of numbers made up of only 0s and 1s, where it is all 0s except in positions designated by the numbers in the recordset: eg. 6,14,37,59, etc.
The result would therefore look something like:
rs is the Recordset, I have the following code so far. Would this work?
intLower = 1 While Not (rs.BOF Or rs.EOF) intUpper = rs!Number For intSlot = intLower To intUpper strOutput = strOutput & IIf(rs!Number = intSlot, 1, 0) Next intSlot rs.moveNext intLower = intUpper + 1 Wend
Note: I realise this is similar to an earlier question of mine, but I am now asking how to do this when the numbers are contained in a Recordset. Also note that I do not want to use a function that converts a recordset to an array, because I am using DAO and apparently the GetRows is problematic.
preguntado el 02 de febrero de 12 a las 10:02
Qué tal si;
dim value as long dim result as String do while not rs.EOF value = rs!Number If (value > Len(result)) then result = result & String$(value - Len(result), "0") Mid$(result, value, 1) = "1" rs.moveNext loop msgbox result
Edit as they are sorted;
dim result as String do while not rs.EOF result = result & String$(rs!Number - Len(result) - 1, "0") & "1" rs.moveNext loop msgbox result