"McKirahan" <Ne**@McKirahan.comwrote in message
news:rK******************************@comcast.com. ..
"le0" <le*********@gmail.comwrote in message
news:#2**************@TK2MSFTNGP02.phx.gbl...
Hello guys,
Im really having a hard time doing this, I have a record set with the
ItemNo
field with the data type as Text. In the record that I have, I want to
find
the missing number in the series
for example:
1
3
4.1
4.2
5
missing number is 2.
How can I display the missing number in the browser or give me a return
value that notifies me that there is a missing number in the series. Is
there any function for that? Or how can i do that using a loop?
btw im using ASP Classic and MS Access Database
How do you define "missing"? Wouldn't 4 also be missing?
Also, as a text field, might it contain non-numeric values?
Also, will the first and lowest number always be 1 and will it exist?
Here's one solution. Watch for word-wrap.
<% @Language="VBScript" %>
<% Option Explicit
'*
'* Declare Constants
'*
Const cASP = "ItemNo.asp"
Const cMDB = "ItemNo.mdb"
Const cDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
'*
'* Declare Variables
'*
Dim intITM
Dim strITM
strITM = "Numbers present: "
Dim intNUM
intNUM = 0
Dim strNUM
strNUM = "Numbers missing: "
Dim strSQL
strSQL = "SELECT ItemNo From ItemNo ORDER BY ItemNo"
'*
'* Declare Objects
'*
Dim objADO
Set objADO = Server.CreateObject("ADODB.Connection")
objADO.Open cDSN & Server.MapPath(cMDB)
Dim objRST
Set objRST = objADO.Execute(strSQL)
'*
'* Read Recordset
'*
Do While Not objRST.EOF
intNUM = intNUM + 1
strITM = strITM & "<br>" & objRST("ItemNo").Value
intITM = Int(objRST("ItemNo").Value)
If intNUM < intITM Then
For intNUM = intNUM To (intITM-1)
strNUM = strNUM & "<br>" & intNUM
Next
End If
intNUM = intITM
objRST.MoveNext
Loop
'*
'* Destroy Objects
'*
Set objRST = Nothing
objADO.Close
Set objADO = Nothing
%>
<html>
<head>
<title><%=cASP%></title>
</head>
<body>
<%=strITM%>
<hr>
<%=strNUM%>
</body>
</html>