473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to find missing number from a range

Hi,
I ll try to find a way to find the missing number from range of numbers from a specific field and show this number with msgbox.
Any ideas?

Thanks in advance.
Jul 11 '12 #1

✓ answered by Mariostg

Here is an untested loop that gives another potential solution
Expand|Select|Wrap|Line Numbers
  1. Do while not rs.BOF and not rs.EOF //rs is a recordset ordered ASC by ID
  2.     thisID=rs!ID
  3.     rs.movenext
  4.     if thisID + 1<> rs!ID then
  5.         msgbox "Range Broken between " & thisID & " and " & rs!ID
  6.     endif
  7. Loop

8 5395
pod
298 100+
not very clear but here is a sub that follows the gist of what I can get from your request
Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub test()
  3. complete_range = Array(1, 2, 3, 4, 5)
  4. incomplete_range = Array(1, 2, 4, 5)
  5. For Each num1 In complete_range
  6.     flag = False
  7.     For Each num2 In incomplete_range
  8.         If num2 = num1 Then
  9.             flag = True
  10.         End If
  11.     Next
  12.     If flag = False Then
  13.         MsgBox num1
  14.     End If
  15. Next
  16.  
  17. End Sub
Jul 11 '12 #2
Thanks Pol for your reply.
My problem is that i have a field in table with name (id) and i want to see if the id field has sequence on it and if it has not to show in msgbox which number is missing from range...
Jul 11 '12 #3
pod
298 100+
OK, then you can still apply the same logic
Expand|Select|Wrap|Line Numbers
  1. Sub sub1()
  2.     Dim rst As ADODB.Recordset
  3.     Call opendb
  4.     Set rst = objConn.Execute("SELECT id FROM Table1")
  5.     'where objConn is my Connection Object
  6.  
  7.     For num = 1 To YourTableMaxID ' ... SELECT MAX(id) FROM YourTable
  8.         flag = False
  9.         Do While Not rst.EOF
  10.             dbID = rst(0)
  11.             If dbID = num Then
  12.                 flag = True
  13.             End If
  14.             rst.MoveNext
  15.         Loop
  16.         If flag = False Then
  17.             MsgBox num
  18.         End If
  19.         rst.MoveFirst
  20.     Next
  21. End Sub
Jul 12 '12 #4
zmbd
5,501 Expert Mod 4TB
freedemi

Pod was kind enough to post a code for you; however, I would like to see the code with which you have already tried to solve the issue.

It could be something fairly simple in the logic. I know that when I did this in school, I over thought the solution (typical back then... forgot the "keep it simple..." rule). This was a favorite problem of the CompSci prof at university given to students... just because it is so easy to over think the solution.

I do have a code that will work on a simple table so if you will post your code (please remember to use the [code][/code] tags) I would be willing to compare the two.

thnx
-z
Jul 12 '12 #5
Mariostg
332 100+
Here is an untested loop that gives another potential solution
Expand|Select|Wrap|Line Numbers
  1. Do while not rs.BOF and not rs.EOF //rs is a recordset ordered ASC by ID
  2.     thisID=rs!ID
  3.     rs.movenext
  4.     if thisID + 1<> rs!ID then
  5.         msgbox "Range Broken between " & thisID & " and " & rs!ID
  6.     endif
  7. Loop
Jul 13 '12 #6
zmbd
5,501 Expert Mod 4TB
I'd still like to see what Freedemi has tried to solve the problem. As I said, this is a favorite problem given to comp-sci students by the profs at my university. The application for finding breaks in a contiguous series is very useful and something banks will do on statements etc... I have such a code in several of my databases that checks for serialized tamper seals on test containers... missing seal.... potential problems.

I have a nice little code that will give the report as asked for in OP. Once Freedemi's code is posted, I will gladly compare it with mine.

-z
Jul 13 '12 #7
Mariostg
332 100+
Oh definitely zmbd. We all expect the OP to post his final solution or an explanation for future reference.
Jul 13 '12 #8
NeoPa
32,556 Expert Mod 16PB
Some of us (IE. the site) also expect the OP to provide their working/non-working code in the first post, along with a question that makes better sense.

Code relative to the OP's current understanding is so much more valuable than simple posted solutions - Hence the rules in place to encourage decent questions as well as responsive replies.

This question was borderline. If it hadn't already triggered so many responses I would have deleted it and let the OP post it again properly. Any members or experts can bring such questions to the attention of the mods by reporting them.
Jul 14 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: nospam | last post by:
Hi, I have an application whose textareas rows automatically resize onFocus to the number of lines in the textArea. The cols are set to 100% (in a CSS file) in order to always take the full...
0
by: Fiaz Idris | last post by:
I am an access newbie and I have the following question. Say, There is a text box in a form for input a number range and the user inputs the following. TextBox: AA123453,57-59,500,505-507,556...
2
by: Randy | last post by:
How do you do a find on a range of Dates in a Date field from the find dialog box?
4
by: Mahesh BS | last post by:
Hello, I need to write a query to find out a set of missing number in a given sequence. Eg : a Column in some table has the following data
5
by: le0 | last post by:
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...
3
by: sharugan | last post by:
Hi All, I have requirement to find out the number of pages in a document. The document could be DOC , TXT ,PDF images etc.I want to be able to upload and find out number of pages in an uploaded...
5
debasisdas
by: debasisdas | last post by:
A ten-digit number contains every digit from 0 to 9. The digits are arranged so that the number formed by the first two digits, reading from left to right, is divisible by 2, the number formed by...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
10
by: fil66 | last post by:
Hi There, Is it possible to expand Hex number range? Here is what I have in a text file... 002A:002F 03E0:03E0 03E2:03E2 07AF:07B1
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.