Results 1 to 17 of 17

Thread: Programming trouble - Easy to solve?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Programming trouble - Easy to solve?

    I have a little problem...I have 4 items and I need to pick the best item...after I get 2 values from a textbox....
    Item Value1 Value2
    A 256 8
    B 512 14
    C 512 28
    D 1024 60

    I need to pick an item which can handle the number...
    for example...

    Value1 = 100 and Value2 = 6 Returns Item A
    Value1 = 100 and Value2 = 10 Returns Item B
    Value1 = 600 and Value2 = 2 Returns Item D

    Can anyone give me a good algorithm to solve this?

  2. #2
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Should it always go the one higher? So if you have an item say 354 12 and and an item 454 12 you are looking for 355 12 it will choose 454 12? Im a bit confused as to the priority of the checking. is it the first number to check first then the second or vice versa? What do the 2 numbers represent as im confused as to why your 2 examples of 100 return A and B?
    Last edited by Blobby; Sep 19th, 2002 at 07:35 AM.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  3. #3
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Also, what are you storing your items in? have you got an array or something?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96
    True...
    It will always check for the highest possible...
    Both Value1 and Value2 need to be higher...

    I just have them plain....

    As the given items A-D are the only possible...

    They can probably be stored in an array...
    I just need the easiest and fastest way

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Hiya Chrissie, try this one ...
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    How long u got, ill knock u something up?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  7. #7
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Okay, I was posting before you wrote that, I've modified it slightly - the last one added both numbers up & checked for the line with the highest entry, this one makes sure both individual numbers are higher...
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Hmmm

    Thanks...But it's not doing exactly what I meant...

    I have 2 textboxes...Value1.text and Value2.text

    Where I enter random numbers...then I have to get the best option...

    Not always the highest but the highest after my 2 textbox inputs...

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    This is the algorithm:
    VB Code:
    1. Private Sub Command1_Click()
    2. 'Given e1 () being a multidemnsional array of numbers
    3. Dim e(4, 2) As Long
    4. e(0, 0) = 256
    5. e(0, 1) = 8
    6. e(1, 0) = 512
    7. e(1, 1) = 14
    8. e(2, 0) = 512
    9. e(2, 1) = 28
    10. e(3, 0) = 1024
    11. e(3, 1) = 60
    12.  
    13. 'Given x = first number, y= second number:
    14. x = CLng(Text1.Text)
    15. y = CLng(Text2.Text)
    16. For I = 0 To 3
    17.   If x < e(I, 0) Then
    18.   For K = 0 To 3
    19.     If y < e(K, 1) Then Exit For
    20.     Next
    21.   Exit For
    22.   End If
    23. Next
    24.  
    25.  
    26.   MsgBox e(I, 0)
    27.   MsgBox e(K, 1)
    28.  
    29.  
    30. End Sub
    Last edited by nemaroller; Sep 19th, 2002 at 08:38 AM.

  10. #10
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    working on it......
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  11. #11
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    nemaroller, surely that wont work as your second for loop is referencing array element (0,3)?
    Last edited by Blobby; Sep 19th, 2002 at 08:26 AM.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  12. #12
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    no it wouldn't, but now it does... its been updated. Ah, the clarification effects of nicotine...
    Last edited by nemaroller; Sep 19th, 2002 at 08:30 AM.

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I had to change it again.... so much for nicotine.... now it truly works I PROMISE

  14. #14
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    hehehe Well it looks like shes buggered off anyway
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Almost...

    Almost...thanks for all your great help...

    When I enter
    100 and 24...
    I want to have 512 - 28 returned...
    Instead I get 256 and 28....

    So both need to be true...

    Sorry for my weak explanation...

    Note: I'm not watching this board all the time...have other stuff to do aswell...

  16. #16
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Post

    I'm going to expect a little appreciation for this one...

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. 'Given e1 () being a multidemnsional array of numbers
    4. Dim e(4, 2) As Long
    5. e(0, 0) = 256
    6. e(0, 1) = 8
    7. e(1, 0) = 512
    8. e(1, 1) = 14
    9. e(2, 0) = 512
    10. e(2, 1) = 28
    11. e(3, 0) = 1024
    12. e(3, 1) = 60
    13.  
    14. 'Given x = first number, y= second number:
    15. x = CLng(Text1.Text)
    16. y = CLng(Text2.Text)
    17. For i = 0 To 3
    18.   If Not x > e(i, 0) And Not y > e(i, 1) Then  Exit For
    19. Next
    20.  
    21. 'if i>3 then msgbox ("not found") else
    22.   MsgBox e(i, 0)
    23.   MsgBox e(i, 1)
    24.  
    25. End Sub
    Last edited by nemaroller; Sep 19th, 2002 at 09:25 AM.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    The Netherlands
    Posts
    96

    Fantastic

    Thanks a lot -xxx-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width