Solved

# vb.net playing with numbers challenge

Posted on 2011-05-09
Medium Priority
340 Views
Hello EE,

I have DatagridView that the user can press a "add" button and via textboxes he enters values.
the grid has columns like that:

From1       To1             From2          To2        From3            To3     (until 5) ..

i have 10 textboxes in the same way.

fact1:  All textboxes are MaxLength of 3 (only numbers)   (0 to 999)
fact2: From1 and To1 must have numbers in it.
fact3: if from2,3,4,5 and to2,3,4,5 are blank I consider that its the MIN inside the from (0) to the MAX inside the TO (999)
fact4: you need both values in from1,2,3,4,5 and in to1,2,3,4,5  not just a from or a to you know..
fact5: The From needs to be always less than the To...

if your first Row  is :   From1:  1000 and To1 :1500

you cannot add another Row  From1 1100 to To1 1600   because 1100 is already between 1000 and 1500.
same thing, lets say you add a new row with from1 900 to 1600 well it cant because between 900 to 1600 there are numbers already inside 1000 to 1500.. you get it ?

now the tricky part...
if you had the same 1000 to 1500 in the second row, it can be fine only if the From2 and To2 are different
if from2 and to2 are the same, you need to go see if from3 to to3 are different... etc until 5 you know?

so im not sure and to do all that.. im quite lost...can you help ?
0
Question by:PhilippeRenaud
• 5
• 3

LVL 41

Expert Comment

ID: 35724040
For each set, you have to check the from and to is not within the range of another set.

so say new set is has two vars:  New_Min and New_Max

class set
public property min as int
public property max as int
public property RowID as int
end class

public function can_add_or_change(RowID) as Boolean
Dim can_add as boolean = true
Dim sets as new List(of set)

for each s in sets
if (new_min >= s.min or new_min <= s.max or new_max >= s.min or new_max <= s.max) and s.Row_Id <> rowID
exit for
end if
next

sets(RowId).min = newmin
sets(RowID).Max = newmax
return true
else
'Let user know they have made a mistake
return false
end if
end function

Then it's just a matter of keeping track of the list.  Let each row number be the rowID.  Update the rows as necessary within the list.  Using the logic of can_add to guide you.
0

LVL 1

Author Comment

ID: 35724756
min max is my from to?

what about the thing I said about that it could be the same from1 and to1 but if others are different and so on ? is that your RowID!?
0

LVL 86

Expert Comment

ID: 35724883
After verifying that you don't have any time slot collisions, concatenate all the from/to fields for that row into a string with consistent formatting (like ensuring they have leading zeros to the same number of digits and making them comma separated).  Then you can use that string as the KEY that you add to a Dictionary/HashTable.  If the key already exists then you know you have a duplicate row.
0

LVL 1

Author Comment

ID: 35724906
I see mmm

so lets say I had 3 rather than 5..

I would have

100,500,001,009,010,050   that would be my key ?
0

LVL 1

Author Comment

ID: 35724910
what doyuo mean by time slot?
0

LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 35724915
Correct.  Just leave off any blank entries.  This should allow partial matches but prevent any rows from having exactly the same sequences.  This does NOT take into account if the time slots in a row were out of order though!  You'd have to sort them first if this is an issue...
0

LVL 86

Expert Comment

ID: 35724919
I guess a "number slot" is a better description...sorry.
0

LVL 1

Author Comment

ID: 35724946
what if they dont have all the same formatting (i said 3  0 to 999) in my example but in realtity it varies. but it will never be like 10..

should I put 10 leading zero to be safe?  I guess its no trouble right?
0

LVL 1

Author Closing Comment

ID: 35725215
Idle_Mind, you are right but I am not sure how to implement it.

I will create new question, can u help in the next one?  I understand i can find duplicates keys but what If I have:

1000,2000,0001,0004,0010,0050
and
1000,2000,0000,0003,0020,0060

both are not duplicate but it should still fail because from 0000 to 0003 there is 0001 and 0002 and 0003 inside it already in the first line (between 0001 and 0004)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
###### Suggested Courses
Course of the Month14 days, 23 hours left to enroll

#### 839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.