By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,315 Members | 1,736 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,315 IT Pros & Developers. It's quick & easy.

missing number

P: n/a
le0
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

Leo :(
Aug 25 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"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?

One approach might be to read all the ItemNo values
(SELECT ItemNo FROM {your_table} ORDER BY ItemNo)
determine the lowest and the highest numbers as integers
then loop throught the recordset to identify what's missing.
Aug 25 '06 #2

P: n/a
"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>
Aug 25 '06 #3

P: n/a
le0

"McKirahan" <Ne**@McKirahan.comwrote in message
news:gt******************************@comcast.com. ..
"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 'COMMENT: your condition here is always
false
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>


Aug 25 '06 #4

P: n/a
"le0" <le*********@gmail.comwrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...

[snip]

It appears that your last post was incomplete;
that is, you didn't include any comments.
Aug 25 '06 #5

P: n/a
"McKirahan" <Ne**@McKirahan.comwrote in message
news:v8******************************@comcast.com. ..
"le0" <le*********@gmail.comwrote in message
news:uw**************@TK2MSFTNGP05.phx.gbl...

[snip]

It appears that your last post was incomplete;
that is, you didn't include any comments.
On re-re-re-reading it I finally found your buried comment:
'COMMENT: your condition here is always false

Did you try the code? It works for me.
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
If 1 is found then intNUM=1 and intITM=1.
If 3 is the next number then intNUM=2 and intITM=3.
Thus, 2 < 3 and 2 will be identified as missing.
Aug 25 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.