dcsimg
Results 1 to 37 of 37

Thread: Finding the closest next greater value from multiple textboxes

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Finding the closest next greater value from multiple textboxes


    I'm trying to code a simple program that scan the greater next value from textbox10 to the following boxes 1 to 9 and the greater value should be placed in textbox11.

    Example:

    Text1 = 4
    Text2 = 0
    Text3 = 1
    Text4 = 9
    Text5 = 2
    Text6 = 9
    Text7 = 9
    Text8 = 3
    Text9 = 1

    Text10 = 9
    Textbox11 = 0

    The value of textbox10 should scan and find the next greater value from box1 to box9 and copy it in textbox11. Must scan in 0 to 9 order like the example above after 9 is "0" and if the zero wasn't there the answer should be "1" it doesn't matter if it repeats twice. The scan should always be in this order
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 etc, etc..
    Last edited by CoderVB; Sep 25th, 2019 at 01:21 PM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,900

    Re: How to find the closest value from textboxes in array

    Code:
        Dim iSmallestDiff As Single
        Dim iClosestValue As Single
        Dim c As Long
        Dim txt As TextBox
        Dim iDiff As Single
        Dim iSet As Boolean
        
        For c = 1 To 5 ' it will scan the 5 textboxes, from Text1 to Text5
            Set txt = Me.Controls("Text" & CStr(c)) ' sets the textbox controls Text1 to text5 to a variable, one at a time
            iDiff = Abs(Val(txt.Text) - Val(Text6.Text)) ' in the iDiff variable, it puts the difference that the value of the current textbox has with the value of Text6
            If (iDiff < iSmallestDiff) Or (iSmallestDiff = 0) And Not iSet Then ' if the difference is less than the previous, or if it is zero because it is the first (it is Text1), the variable iSet will be False and it will enter too
                iSmallestDiff = iDiff ' remember this difference that is now the smallest, for the next time
                iClosestValue = Val(txt.Text) ' the current value that is closest to the value of Text6 is this, for now
                iSet = True ' it means that the variable iSmallestDiff has a meaningful value (If iSet is True, it means that if iSmallestDiff has zero it is not because it is just starting)
            End If
        Next c
        Text7.Text = iClosestValue ' write the closest value into Text7
    Attached Files Attached Files
    Last edited by Eduardo-; Sep 13th, 2019 at 12:58 AM.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: How to find the closest value from textboxes in array

    Quote Originally Posted by Eduardo- View Post
    Code:
        Dim iSmallestDiff As Single
        Dim iClosestValue As Single
        Dim c As Long
        Dim txt As TextBox
        Dim iDiff As Single
        Dim iSet As Boolean
        
        For c = 1 To 5 ' it will scan the 5 textboxes, from Text1 to Text5
            Set txt = Me.Controls("Text" & CStr(c)) ' sets the textbox controls Text1 to text5 to a variable, one at a time
            iDiff = Abs(Val(txt.Text) - Val(Text6.Text)) ' in the iDiff variable, it puts the difference that the value of the current textbox has with the value of Text6
            If (iDiff < iSmallestDiff) Or (iSmallestDiff = 0) And Not iSet Then ' if the difference is less than the previous, or if it is zero because it is the first (it is Text1), the variable iSet will be False and it will enter too
                iSmallestDiff = iDiff ' remember this difference that is now the smallest, for the next time
                iClosestValue = Val(txt.Text) ' the current value that is closest to the value of Text6 is this, for now
                iSet = True ' it means that the variable iSmallestDiff has a meaningful value (If iSet is True, it means that if iSmallestDiff has zero it is not because it is just starting)
            End If
        Next c
        Text7.Text = iClosestValue ' write the closest value into Text7



    Thanks man you are amazing everything is almost done with my project. This code is amazing! Is just that now I just need to modify it to count up from 0 to 9 in loop, and find the closest number disregarding an equal number only the ascending closest number. Like if I enter any value from text1 to text5.
    Example:
    Text1 = 4
    Text2 = 0
    Text3 = 1
    Text4 = 9
    Text5 = 2

    Text6 = 9

    Text7 = 0
    It must search in ascending order from 0 to 9 loop disregarding or no counting the same number like 9 but it went to 0.
    The looping count should always be
    0 1 2 3 4 5 6 7 8 9. Thanks once again dude.

  4. #4
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,900

    Re: How to find the closest value from textboxes in array

    Try to do it yourself, how would you modify the code for doing that? (please post here what you would do)

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: How to find the closest value from textboxes in array

    Quote Originally Posted by Eduardo- View Post
    Try to do it yourself, how would you modify the code for doing that? (please post here what you would do)
    I already did modified by changing greater than symbols but I can't figure out the code for not counting the same number and looping 0 to 9, thanks anyway.

  6. #6
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,900

    Re: How to find the closest value from textboxes in array

    If by "an equal number" you mean to disregard equal number to Text6:

    Code:
        Dim iSmallestDiff As Single
        Dim iClosestValue As Single
        Dim c As Long
        Dim txt As TextBox
        Dim iDiff As Single
        Dim iSet As Boolean
        
        For c = 1 To 9 
            Set txt = Me.Controls("Text" & CStr(c))
            iDiff = Abs(Val(txt.Text) - Val(Text6.Text))
            If iDiff <> 0 Then 
                If (iDiff < iSmallestDiff) Or (iSmallestDiff = 0) And Not iSet Then 
                    iSmallestDiff = iDiff
                    iClosestValue = Val(txt.Text)
                    iSet = True
                End If
            End If
        Next c
        Text7.Text = iClosestValue
    If by "an equal number" you mean when there are more than one closest to take the last one:


    Code:
        Dim iSmallestDiff As Single
        Dim iClosestValue As Single
        Dim c As Long
        Dim txt As TextBox
        Dim iDiff As Single
        Dim iSet As Boolean
        
        For c = 1 To 9 
            Set txt = Me.Controls("Text" & CStr(c))
            iDiff = Abs(Val(txt.Text) - Val(Text6.Text))
            If (iDiff <= iSmallestDiff) Or (iSmallestDiff = 0) And Not iSet Then 
                iSmallestDiff = iDiff
                iClosestValue = Val(txt.Text)
                iSet = True
            End If
        Next c
        Text7.Text = iClosestValue

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    How to find the greater number in all textboxes from one text box

    I'm close to finishing a small program that i started, but got stuck with the last part. And I'm just starting to learn programming, so might be a stupid question.

    I have 9 text boxes, each having its own number. The box 10 is where I enter the number to compare to all text boxes. How can i get the text box with the greater number to text box 10?

    All help is appreciated!

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,557

    Re: How to find the greater number in all textboxes from one text box

    is this actually different to your other thread?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,342

    Re: How to find the greater number in all textboxes from one text box

    Just playing around during my morning coffee...

    Code:
    Private Sub Command_Click()
    '1. Made the text boxes an array Text(0) to Text(9)
    '2. No validation of numerics at all
    '3. It is assumed all text boxes have data
    '4  If nothing was greater keep the value where it was
    
        Dim lngTextBox10 As Long
        Dim lngCtr As Long
        
        lngTextBox10 = Text(9).Text
        
        For lngCtr = 0 To 8
            If clng(Text(lngCtr).Text) > lngTextBox10 Then
                lngTextBox10 = Text(lngCtr).Text
            End If
        Next
        
        Text(9).Text = lngTextBox10
    
    End Sub
    This is not using an array

    Code:
    Dim ctl As Control
        lngTextBox10 = Text10.Text
        For Each ctl In Controls
            If TypeName(ctl) = "TextBox" Then
                If CLng(ctl.Text) > lngTextBox10 Then
                    lngTextBox10 = ctl.Text
                End If
            End If
        Next
        
        Text10.Text = lngTextBox10
    Last edited by TysonLPrice; Sep 19th, 2019 at 10:49 AM.
    Please remember next time...elections matter!

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: How to find the greater number in all textboxes from one text box

    Quote Originally Posted by TysonLPrice View Post
    Just playing around during my morning coffee...

    Code:
    Private Sub Command_Click()
    '1. Made the text boxes an array Text(0) to Text(9)
    '2. No validation of numerics at all
    '3. It is assumed all text boxes have data
    '4  If nothing was greater keep the value where it was
    
        Dim lngTextBox10 As Long
        Dim lngCtr As Long
        
        lngTextBox10 = Text(9).Text
        
        For lngCtr = 0 To 8
            If clng(Text(lngCtr).Text) > lngTextBox10 Then
                lngTextBox10 = Text(lngCtr).Text
            End If
        Next
        
        Text(9).Text = lngTextBox10
    
    End Sub
    This is not using an array

    Code:
    Dim ctl As Control
        lngTextBox10 = Text10.Text
        For Each ctl In Controls
            If TypeName(ctl) = "TextBox" Then
                If CLng(ctl.Text) > lngTextBox10 Then
                    lngTextBox10 = ctl.Text
                End If
            End If
        Next
        
        Text10.Text = lngTextBox10



    I'm sorry. I'm trying to create a code that will scan 9 boxes that any number should be greater than textbox10 and copy that number in textbox11. Kind of like a timer digits counting from 0 to 9 When clicking the button the code should scan in 0 to 9 order. If there's a a number like 9 in textbox10 and a 0 in box1 and the other boxes are 2 then the number copied in textbox11 should be "0".

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,465

    Re: How to find the greater number in all textboxes from one text box

    Quote Originally Posted by westconn1 View Post
    is this actually different to your other thread?
    This is the 3rd thread on the same question.

    @CoderVB. Please stop posting the same question multiple times. The original thread should've been kept going until you got it resolved.

    Now you are likely to get some of the same responses you got in the other two threads -- wasting of time/effort. Of course, others will have noticed you keep posting the same question and simply ignore your threads altogether.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    837

    Re: finding the greater value of textboxes in sync.

    I read your post three times and still have no idea what your end goal is. Its not clear why, in your example, Textbox11 is supposed to equal 2. 2 isn't the "next greater number" than any number listed in your example. I also have no idea why, in your list of numbers at the end, some of them are in quotes. I'm also genuinely curious how an interferometer can possibly be related to what you are trying to code here, but that's another issue altogether.

    Edit: Wait, I think I might see what you mean. If there is no number greater than what is in Textbox10, which can happen if:

    TextBox10 contains 9, which guarantees no single digit can be greater
    or
    TextBox10 doesn't contain 9, but there is still no number greater than it in the other textboxes

    Then you "roll over" back to 0 and start the search anew, in which case you are actually looking for the lowest value in the list.

    Otherwise you look for the next largest digit from Textbox1-Textbox9 in comparison to TextBox10

    Is that correct?
    Last edited by OptionBase1; Sep 19th, 2019 at 10:59 PM.

  13. #13
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,535

    Re: finding the greater value of textboxes in sync.

    I'm thinking it sounds correct. Since this thread didn't make much sense, e.g. " look for the next greater number to textbox6 10 and that greater number copy it in textbox11" (where did textbox6 come from?), I looked back at his other posts to see if together a consensus could emerge. In the earlier threads, textbox6 was the "textbox10" in this thread, i.e. he had five textboxes with numbers in them and textbox6 was the "search key".

    Anyway, giving more than one example output for a given input would have been nice, since a "case of one" isn't much of a test.

    Based on your interpretation, then entering the following numbers in Textbox10 should result with the following values in Textbox11. If that is the desired result, you have a clearer definition of the requirement.
    Code:
    Box 10, Box 11
    0     ,  2
    1     ,  2
    2     ,  3
    3     ,  4
    4     ,  5
    5     ,  6
    6     ,  7
    7     ,  2
    8     ,  2
    9     ,  2
    CoderVB, is that what you're looking for, i.e. someone enters a number in Textbox10 and Textbox11 is set to the above result for the given contents of Textboxes 1 to 9?

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,557

    Re: How to find the greater number in all textboxes from one text box

    If there's a a number like 9 in textbox10 and a 0 in box1 and the other boxes are 2 then the number copied in textbox11 should be "0".
    i totally miss the logic in this, please explain why 0 would be > 9 or 2
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  15. #15
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,096

    Re: How to find the greater number in all textboxes from one text box

    based on a Table in a Database
    you can use Sql to do the Job

    Code:
    SELECT *
    FROM Tabelle1
    WHERE ABS(785 - Feld1) = (SELECT MIN(ABS(785 - Feld1)) FROM Tabelle1 );
    Tabelle1 = is the Name of the Database Table
    Feld1 = is the Field to search in
    785 = is the Input value to search
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  16. #16

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: How to find the closest value from textboxes in array

    This is what i've done so far but still trying.
    Attached Files Attached Files

  17. #17
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,225

    Re: Finding the closest next greater value from multiple textboxes

    I suspect that anyone who gives you the full solution will get jumped on by the other members.
    The first training exercise I would recommend to you is to get familiar with control arrays, as that will allow you to navigate through all of your textboxes.
    The textboxes that you have called Text1, Text2 etc could be called say txtValues.
    You 'draw' a single textbox on the form called txtValues.
    If you then copy it (click it then press Ctrl C), and attempt to paste another onto the form (click the form and press Ctrl V), VB will ask if you would like to make a control array. Click Yes
    If you then keep clicking the form and pressing Ctrl V, you will get your control array.
    The first one will have an Index value of 0, which we wish to avoid, in your scenario. After you have created all of the copies, you could delete that first one.

    Here is an example of iterating through the controls -
    Code:
    Private Sub Command1_Click()
     Dim i As Integer
      For i = 1 To txtValues.UBound
        Debug.Print txtValues(i).Text
    
      Next i
    End Sub
    Hope This Partially helps,
    Rob
    PS Those members having trouble with double postings - If you go to advanced before submitting your post, that avoids double posts

  18. #18
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,535

    Re: Finding the closest next greater value from multiple textboxes

    Well, I don't see what you say you want to do can possibly be of any benefit to what you want to do, but....

    I looked at the code you posted in the link that ChrisE posted earlier this morning (but got sidetracked) and some of your textboxes had indexes, which would prevent the code from running. So, I deleted those index values from the property lists.

    Then you had the line that made no sense at all.

    iDiff = Abs(Val(txt.Text) > Val(Text10.Text))

    This is going to compare two values and that will be either True or False, and then take the Absolute value of True (-1) or False (0).
    So iDiff is set to 0 if txt.Text is less or equal to Text10, or it is set to 1 if txt.Text is greater than Text10.

    Setting iDiff to 0 or 1 is not what the code Eduardo gave you intended to do.

    In your other thread,
    http://www.vbforums.com/showthread.p...tboxes-in-sync
    you didn't respond to OptionBase1's or my post to clarify if what we deduced is what you wanted.
    I gave you a table of inputs and outputs based on the assumption, so that you could verify, yes or no, whether that is what you expected to show up in Text11, based on the inputs in Text10 with the given data.

    Since you posted a broken program in the thread that ChrisE linked to, and I had already modified the code to work on the assumption of dealing with Integers and following the rules that OptionBase1 and I assume is what you want from the other post, I'll post the code in the button that did that. You can fix the index property problems and see if the code does what you say you want it to do.
    I still can't see why it would be useful for what you apparently want to do.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
       'Find the smallest value greater than Textbox10,
       'or if there is none, then the smallest value overall
       
        Dim SmallestValue As Integer
        Dim SmallestGreater As Integer
        Dim c As Long
        Dim txt As TextBox
        Dim ValToCmp As Integer
        Dim TestVal As Integer
        
        ValToCmp = Int(Val(Text10.Text))
        SmallestValue = Int(Val(Text1.Text))
        For c = 1 To 9
            Set txt = Me.Controls("Text" & CStr(c))
            TestVal = Int(Val(txt.Text))
            If TestVal > ValToCmp Then                 'look for numbers greater than our input
                If SmallestGreater > 0 Then            'If we've assigned a number before
                    If TestVal < SmallestGreater Then  '  see if this one is less
                        SmallestGreater = TestVal
                    End If
                Else                                   'else this is first number found greater than input
                  SmallestGreater = TestVal
                End If
            End If
            If TestVal < SmallestValue Then  'keep track of the smallest number found as well
                SmallestValue = TestVal
            End If
        Next c
        If SmallestGreater <> 0 Then     'if we found a number > input
          Text11.Text = SmallestGreater  '  assign it
        Else
          Text11.Text = SmallestValue    'else assign the smallest found
        End If
    
    End Sub

  19. #19
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,342

    Re: Finding the closest next greater value from multiple textboxes

    Quote Originally Posted by CoderVB View Post

    I'm trying to code a simple program that scan the greater next value from textbox10 to the following boxes 1 to 9 and the greater value should be placed in textbox11.

    Example:

    Text1 = 4
    Text2 = 0
    Text3 = 1
    Text4 = 9
    Text5 = 2
    Text6 = 9
    Text7 = 9
    Text8 = 3
    Text9 = 1

    Text10 = 9
    Textbox11 = 0

    The value of textbox10 should scan and find the next greater value from box1 to box9 and copy it in textbox11. Must scan in 0 to 9 order like the example above after 9 is "0" and if the zero wasn't there the answer should be "1" it doesn't matter if it repeats twice. The scan should always be in this order
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 etc, etc..

    I would appreciate your help, thank you
    You didn't seem to appreciate when I tried to help before:

    http://www.vbforums.com/showthread.p...t=#post5417149
    Please remember next time...elections matter!

  20. #20
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,232

    Re: How to find the closest value from textboxes in array

    Please stop posting the same question in multiple threads. One thread per question.

    I have merged all the different threads that I found, of which there were several. If those answers are not sufficient, then you need to say why they are not sufficient. If you expect somebody to simply write the code for you, then you may have come to the wrong place.
    My usual boring signature: Nothing

  21. #21

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: How to find the greater number in all textboxes from one text box

    Thanks friend but I fixed my question above to fix the code.

  22. #22

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: finding the greater value of textboxes in sync.

    Quote Originally Posted by passel View Post
    I'm thinking it sounds correct. Since this thread didn't make much sense, e.g. " look for the next greater number to textbox6 10 and that greater number copy it in textbox11" (where did textbox6 come from?), I looked back at his other posts to see if together a consensus could emerge. In the earlier threads, textbox6 was the "textbox10" in this thread, i.e. he had five textboxes with numbers in them and textbox6 was the "search key".

    Anyway, giving more than one example output for a given input would have been nice, since a "case of one" isn't much of a test.

    Based on your interpretation, then entering the following numbers in Textbox10 should result with the following values in Textbox11. If that is the desired result, you have a clearer definition of the requirement.
    Code:
    Box 10, Box 11
    0     ,  2
    1     ,  2
    2     ,  3
    3     ,  4
    4     ,  5
    5     ,  6
    6     ,  7
    7     ,  2
    8     ,  2
    9     ,  2
    CoderVB, is that what you're looking for, i.e. someone enters a number in Textbox10 and Textbox11 is set to the above result for the given contents of Textboxes 1 to 9?
    A made a example above the question, I would appreciate your help. Thanks

  23. #23

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: finding the greater value of textboxes in sync.

    Quote Originally Posted by passel View Post
    I'm thinking it sounds correct. Since this thread didn't make much sense, e.g. " look for the next greater number to textbox6 10 and that greater number copy it in textbox11" (where did textbox6 come from?), I looked back at his other posts to see if together a consensus could emerge. In the earlier threads, textbox6 was the "textbox10" in this thread, i.e. he had five textboxes with numbers in them and textbox6 was the "search key".

    Anyway, giving more than one example output for a given input would have been nice, since a "case of one" isn't much of a test.

    Based on your interpretation, then entering the following numbers in Textbox10 should result with the following values in Textbox11. If that is the desired result, you have a clearer definition of the requirement.
    Code:
    Box 10, Box 11
    0     ,  2
    1     ,  2
    2     ,  3
    3     ,  4
    4     ,  5
    5     ,  6
    6     ,  7
    7     ,  2
    8     ,  2
    9     ,  2
    CoderVB, is that what you're looking for, i.e. someone enters a number in Textbox10 and Textbox11 is set to the above result for the given contents of Textboxes 1 to 9?
    A made a example above the question, I would appreciate your help. Thanks

  24. #24
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,096

    Re: Finding the closest next greater value from multiple textboxes

    I looked at you Code(Program) from post#16

    Image
    Name:  nonsence.png
Views: 99
Size:  6.3 KB

    what has Hours,Minutes etc got to do with ?... you will have to explain the Logic behind this
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  25. #25
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,188

    Re: Finding the closest next greater value from multiple textboxes

    Couldn't resist...HAD to come back! With all these 'experts' trying to provide guidance, it intrigued me why all wanted so desperately to to get to the bottom of this.

    And, as I said before (in a now long gone thread), OP is using flawed logic. But, after see the previous post, I can see there really is no logic at all involved.

    OP----WITHOUT using IT terms (ie textbox), just WHAT (in english please), are you trying to do?

    A STATEMENT MIGHT be like this:

    I want to develop a program that displays time (in hours, minutes, seconds and milliseconds). Then, I want the user to be able to enter a value (between/inclusive 0 and 9) in order to ......(WHATEVER THAT MAY BE--I can't deduce that from your code).

    Sam

  26. #26
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,342

    Re: Finding the closest next greater value from multiple textboxes

    This is turning out like those emails where someone replies to all, and then someone replies "don't reply to all" to everybody, then the next person does that also, then they get nastier as the whole distribution sees everyone saying "don't reply to all", then a manager steps in and says "stop it".
    Please remember next time...elections matter!

  27. #27
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,535

    Re: finding the greater value of textboxes in sync.

    Quote Originally Posted by CoderVB View Post
    A made a example above the question, I would appreciate your help. Thanks
    And I posted a fix to the example you posted, based on our assumption. It is in post #18 of this merged thread.
    Your example was merged as post #16, and I posted in post #18 what I had to do to fix the example to get it to compile and run, and then the code that replaces the code in the button to process the input in text10 and update text11. You should try it and see if it meets your requirements, although I can't see how meeting those requirements can be of any use to what your textboxes represent, if indeed they are an elapsed time readout.

    Finding the next highest digit from an input, in any of those textboxes seems completely useless to me.
    Last edited by passel; Sep 26th, 2019 at 12:29 PM.

  28. #28
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,225

    Re: Finding the closest next greater value from multiple textboxes

    Sam has hit the nail on the head.
    You must learn the ability to clearly express your problem and needs, without cluttering it with your expected/suspected solutions.

    Imagine there exists a programmer in the world, who leaves all of us for dead.
    He can knock up a solution in a couple of minutes, for tasks that would take the rest of us hours/days.
    He charges $10,000 an hour.
    We will tee you up with him.
    You must enter into a contract with him for this problem.
    HOWEVER, if he gives you a solution in under 5 minutes there will be no charge.

    Now would you like to have another go at expressing your need ?

  29. #29

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: Finding the closest next greater value from multiple textboxes

    Quote Originally Posted by TysonLPrice View Post
    You didn't seem to appreciate when I tried to help before:

    http://www.vbforums.com/showthread.p...t=#post5417149
    Thanks anyway, the code didn't work as i mentioned above my post but I'm still trying.

  30. #30

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: Finding the closest next greater value from multiple textboxes

    This is sample only. If I make the code successful i will have to make modifications to multiple timers each using Nanoseconds. My goal is to measure the timers in sequence to find the shape of waves signals which are different using a regular oscilloscope.

    I just need the right function for this code. I made a sample above my post. Thankyou anyway for your contribution. When I find the right code function in the answers
    I'll let everyone here know.

  31. #31
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,188

    Re: Finding the closest next greater value from multiple textboxes

    Quote Originally Posted by CoderVB View Post
    My goal is to measure the timers in sequence to find the shape of waves signals which are different using a regular oscilloscope.
    .
    NOW THAT MAKES SENSE! Good job explaining what you want to do. HOWEVER, not being much of an engineer (although I did get a degree in CE), I would have no idea on how to approach this problem. But now that you have provided what you want to do in terms some can understand, I'll bet some folks out there just may be able to help you with this. There are probably even some who have already written code to do just what you are requesting....let's wait and see.

    EDIT: But, I DO imagine there may be some more explaining needed....

  32. #32
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,535

    Re: Finding the closest next greater value from multiple textboxes

    Quote Originally Posted by CoderVB View Post
    This is sample only. If I make the code successful i will have to make modifications to multiple timers each using Nanoseconds. My goal is to measure the timers in sequence to find the shape of waves signals which are different using a regular oscilloscope.

    I just need the right function for this code. I made a sample above my post. Thankyou anyway for your contribution. When I find the right code function in the answers
    I'll let everyone here know.
    Ok, what was wrong with the code in post #18?
    It did what you said you wanted (although what you said you wanted doesn't make any sense for the task, as far as I can see).

    If you had multiple timers, and you wanted to find the next greater time than the current timer, then you would want to compare the whole timestamp against the current timestamp, not individual digits of the timestamp.

    From your latest description, it would seem like you're essentially trying to create a higher resolution digital oscilloscope, i.e. a digital oscilloscope samples the signal at a given rate, and you would like to coordinate multiple devices to increase their effective sampling rate.

    If you had a device that could sample 100 million times per second, and you had ten of them, and they could be synchronized so that each one triggered the next, you could end up sampling a billion times per second, if you sorted the results from the 10 devices.

    If that is what you're attempting, good luck. That would be generating a lot of data pretty quickly, so memory could run out in a hurry. For high rates of sampling conversion, you're dependent on the equipment's storage capability because there wouldn't be sufficient bandwidth to get the data to the PC for storage.

    The fact that you need to search would seem like that perhaps the sampling isn't coordinated between devices, and one would have to wonder how accurate the timestamp between devices would be to ensure the samples are actually in the true sample order when ordered by timestamps.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  33. #33

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: Finding the closest next greater value from multiple textboxes

    Thanks alot , finally finished my project but still trying to modify your code. I need to count only selected boxes, "not from 1 to 9"
    C = 1 to 9
    Last part is getting me stuck, this code is simple but couldn't figure it out yet.

  34. #34

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: Finding the closest next greater value from multiple textboxes

    Sorry, it didn't work for me. I'm using VB6

  35. #35
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,225

    Re: Finding the closest next greater value from multiple textboxes

    If you click 'Reply With quote' on the post you are replying to, we might have a clue what (to whom) your post is responding to.
    Rob
    PS Did you take out that contract with the super programmer ?
    If you did, have a guess as to how big your bill is now

  36. #36

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    33

    Re: Finding the closest next greater value from multiple textboxes

    Thank you for your help, I think your code works as expected but how do you change from sequence boxes like "1 to 9" when I just want to choose boxes that are not in sequence like text2, text5, text7, text9?

  37. #37
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,535

    Re: Finding the closest next greater value from multiple textboxes

    Well, obviously you change the loop, For c = 1 To 9, to something that will select the numbers not in sequence. Since I don't know how you want to choose the values, and I assume they wouldn't be just be a random sequence, I can't suggest anything in detail.

    But since this sounds a lot like what TravismarkI is doing in this thread perhaps if he successfully posts his zip file, you can see how he checks the adjacent boxes, to a box, rather than sequencing through all the boxes, unless TravismarkI is an alias for you, in which case you should already know.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width