dcsimg
Results 1 to 17 of 17

Thread: Transferring data from textbox to textbox in sequence Vb6

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    35

    Transferring data from textbox to textbox in sequence Vb6

    Hi everyone!!
    Once again im stuck trying to transfer data from 4 textbox to other 4 but bust be filled in consecutive order.

    Example:
    These are the above textboxes that must be transferred to textbox5 to textbox8 in the bottom.

    Textbox1 ( has number 5)
    Textbox2 ( has number 7)
    Textbox3 ( has number 4)
    Textbox4 ( has number 1)


    Textbox5 ( must get any number from above filled here then go to next textbo)
    Textbox6 ( must get any 3 left number from above and go next textbox)
    Textbox7 ( must get any 2 number left from above and go next textbox)
    Textbox8 ( the last number left from above here)

    The numbers from above must be transferred in any order but must be filled in sequence from textbox5 to textbox8.

  2. #2
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    665

    Re: Transferring data from textbox to textbox in sequence Vb6

    Sorry, but that sounds like Homework to me.

    What have you tried so far?

    Personally, I'd create a set (array) of values to choose from, then loop through the target TextBoxes (read up on Control Arrays) and, for each one, select a value from the set, then remove that value from the set.

    Regards, Phill W.

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,166

    Re: Transferring data from textbox to textbox in sequence Vb6

    Huh?
    If i understand correctly, you have values in Text1-4, and those values have to be transferred to Text5-8 in order of text5, 6, 7 and last 8, but choosing randomly values from Text1 to 4?
    Sounds like the Lottery Problem.....
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    Definitely appears to be homework of some sort. But, a couple of questions for you to ponder.

    Your title suggests that you want what is in textbox1 to go to textbox5, textbox2 to go to textbox6, and so forth (you said in your title "IN SEQUENCE".

    But then your post says 'in any order'....and "in sequence"....which is it?

    If I can guess at what your instructor (or homework book) desires, is that you have four textboxes, each with a 'number' in it. And you are to take those four numbers and put them in four new textboxes, but it doesn't matter which number ends up where. When you say 'in any order', do you mean, 'in random order'? If so, you might use RANDOM/RND to populate an array (as suggested by Phil) so that the array ends up with values in elements 0-3 'in any order'. Then, simply, as again Phil stated, go through that array from top to bottom and put each element's array in textboxes 5 through 8. Of course, using ARRAYS of textboxes would make this simpler, but not a necessity.

    So, IS this a homework assignment? If so, PLEASE show us code you have thought through first so we can guide you better.

    Sammi

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    I don't think it is so much a lottery as it is a door prize selection, or horse race.
    I think the sequential part, as already stated, is the output text boxes, 5,6,7,8.
    So, it is a simple drawing from a hat or bag type program.
    The first number drawn goes in the first textbox (5).
    Then you continue drawing from the numbers remaining, filling each textbox in turn.

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,166

    Re: Transferring data from textbox to textbox in sequence Vb6

    Ok, not Lottery per se, but Passel is right.
    It's more like a raffle: First place, second place and so on....
    It basically boils down to:
    Draw a random number without putting it back, but adhere to the order of the draw.

    I remember once writing an algorithm you could use for a scenario like this. Should be in the Codebank somewhere

    EDIT: Found it
    http://www.vbforums.com/showthread.p...hlight=Lottery
    Last edited by Zvoni; Apr 12th, 2019 at 07:23 AM.
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2014
    Posts
    35

    Re: Transferring data from textbox to textbox in sequence Vb6

    Quote Originally Posted by SamOscarBrown View Post
    Definitely appears to be homework of some sort. But, a couple of questions for you to ponder.

    Your title suggests that you want what is in textbox1 to go to textbox5, textbox2 to go to textbox6, and so forth (you said in your title "IN SEQUENCE".

    But then your post says 'in any order'....and "in sequence"....which is it?

    If I can guess at what your instructor (or homework book) desires, is that you have four textboxes, each with a 'number' in it. And you are to take those four numbers and put them in four new textboxes, but it doesn't matter which number ends up where. When you say 'in any order', do you mean, 'in random order'? If so, you might use RANDOM/RND to populate an array (as suggested by Phil) so that the array ends up with values in elements 0-3 'in any order'. Then, simply, as again Phil stated, go through that array from top to bottom and put each element's array in textboxes 5 through 8. Of course, using ARRAYS of textboxes would make this simpler, but not a necessity.

    So, IS this a homework assignment? If so, PLEASE show us code you have thought through first so we can guide you better.

    Sammi
    Im sorry for the bad information ive given but doesn't need to be randomly but when transferring the data to textbox5, 6, 7, 8 must not make mistake to repeat the answer in the same textbox.
    So far I made this code but is too large so im looking for something simple someone here might know since im newbie coding in vb6. Whatever result I get from the numbers from above must be put in order to the following textbox5, textbox6, textbox7, textbox8.

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    if it does not need to be random, just copy the values from textboxes1 to 4 into textboxes 5 to 8 then, try like
    Code:
    for t = 1 to 4
        me.controls("textbox" & t + 4) = me.controls("textbox" & t)
    next
    while this will fill in order as requested the user really won't see it
    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
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,406

    Re: Transferring data from textbox to textbox in sequence Vb6

    I THINK now, that OP wants textboxes 5 through 8 to have values lowest to highest of the other four textboxes.... ("must be put in order to the...."). In that case, one could use a sort routine, or because there are only four boxes (1-4), use a CASE or IF or IIF statement to make sure the lowest number goes in textbox 5, the next in textbox 6, etc. At least that is what I am READING/THINKING from post #7. (and this sound more like what an actual homework assignment might be---OP never tells us if so).

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    I think he means all possible combinations of
    5 7 4 1
    1 4 7 5
    etc...

    just a guess
    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.

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    just a guess
    Guess we can keep on guessing until OP answers better....

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,920

    Re: Transferring data from textbox to textbox in sequence Vb6

    Quote Originally Posted by ChrisE View Post
    I think he means all possible combinations of
    5 7 4 1
    1 4 7 5
    etc...

    just a guess
    Well, I think the instructions from the first post were fairly clear, once you moved on, then came back and read it again after a short gestation period. The later "clarification" did seem to cloudy the waters, though.
    Quote Originally Posted by CoderVB View Post
    ...
    Textbox5 ( must get any number from above filled here then go to next textbo)
    Textbox6 ( must get any 3 left number from above and go next textbox)
    Textbox7 ( must get any 2 number left from above and go next textbox)
    Textbox8 ( the last number left from above here)

    The numbers from above must be transferred in any order but must be filled in sequence from textbox5 to textbox8.
    My translation.
    Textbox5 is set to any one of the numbers from the above four textboxes.
    Textbox6 is set to any one of the three remaining numbers.
    Textbox7 is set to either one of the two remaining numbers.
    Textbox8 is set to the last number remaining.

    The order of the numbers in the four textboxes (boxes 5 to 8) can be filled in any order.

    The caveat "but must be filled in sequence from textbox5 to textbox8" is somewhat confusing, but perhaps means that it is desired that the boxes be filled slow enough that you see the "transfers" happen. Which might mean that you would want a "pick" button, that at each hit would transfer one of the numbers each time it is clicked, or perhaps use a timer so that there is a short delay, say a 1/4 second or more between each pick.

    I also think the OP's misunderstanding of how the use of Random numbers would play into the solution is confusing him as well.

  13. #13
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    665

    Re: Transferring data from textbox to textbox in sequence Vb6

    > "Whatever result I get from the numbers from above must be put in order ..."

    Now that sounds more like a Sorting problem.

    I would suggest that the only sane code for this involves Control Arrays, so that you can loop through the source TextBoxes and write to each target TextBox in turn. You can create a Control Array by setting the Index property of each TextBox and then setting their Names to be the same:

    Code:
    TextBox1 becomes SourceTextBox( 0 ) ' Name:= SourceTextBox, Index := 0 
    TextBox2 -> SourceTextBox( 1 )
    TextBox3 -> SourceTextBox( 2 )
    TextBox4 -> SourceTextBox( 3 )
    
    TextBox5 -> TargetTextBox( 0 ) ' Name:= TargetTextBox, Index := 0 
    TextBox6 -> TargetTextBox( 1 )
    TextBox7 -> TargetTextBox( 2 )
    TextBox8 -> TargetTextBox( 3 )
    
    For idx = 0 To 3 
       TargetTextBox( idx ).Text = SourceTextBox( idx ).Text 
    Next
    Alternatively, instead of changing the Controls themselves, you can create an Array of Controls in your code:

    Code:
    Dim sources as TextBox( 3 )
    Set sources( 0 ) = textBox1 
    Set sources( 1 ) = textBox2 
    Set sources( 2 ) = textBox3 
    Set sources( 3 ) = textBox4 
    
    Dim targets as TextBox( 3 )
    Set targets( 0 ) = textBox5 
    Set targets( 1 ) = textBox6 
    Set targets( 2 ) = textBox7 
    Set targets( 3 ) = textBox8 
    
    For idx = 0 To 3 
       targets( idx ).Text = sources( idx ).Text 
    Next
    Now you just have to work out how to transfer the values in the right order.

    For this small a data set, I'd suggest a simple Insert Sort - loop through source values, find the smallest, write it to the [next] target, "rinse and repeat" until done.

    Regards, Phill W.

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    Well, looks like OP already has turned in his project to the teacher! ~smile~

    And, to end this guessing game, I offer ONE way to do this (homework or not), but it is dependent upon values in the first set of four textboxes. If between 0 and 9, or 10 and 19, or 20 and 29, etc, etc, then the attached project will do just fine. It allows for a 'immediate' transfer of the values, or, using a timer, shows the transfer slowly one by one.

    enjoy

    Code:
    Option Explicit
        Dim intVar As Integer
    
    
    Private Sub Command1_Click() 'put values in second set of textboxes all at once, sorted
        List1.Clear
        Dim intVar As Integer
        For intVar = 0 To 3
            Text2(intVar).Text = "" 'clear text2 boxes
            List1.AddItem (Text1(intVar).Text)  'list1.sorted property is set to TRUE in IDE  (because the values are less than 10---
                                                'will not work otherwise)
        Next intVar
        For intVar = 0 To 3
            List1.ListIndex = intVar
            Text2(intVar).Text = List1.Text
        Next intVar
    End Sub
    
    
    Private Sub Command2_Click() 'populate text2 boxes one by one
        List1.Clear
        For intVar = 0 To 3
            Text2(intVar).Text = "" 'clear text2 boxes
            List1.AddItem (Text1(intVar).Text)  'list1.sorted property is set to TRUE in IDE
        Next intVar
        Timer1.Enabled = True
        Command2.Enabled = False 'to prevent user from clicking more than once while timer is run
    End Sub
    
    
    Private Sub Command3_Click()
        For intVar = 0 To 3
            Text2(intVar).Text = ""
        Next intVar
    End Sub
    
    
    Private Sub Form_Load()
        Timer1.Interval = 1000 '1 second
        Timer1.Enabled = False
        For intVar = 0 To 3
            Text2(intVar).Text = ""
        Next intVar
        Text1(0).Text = 5
        Text1(1).Text = 7
        Text1(2).Text = 4
        Text1(3).Text = 1
        List1.Visible = False 'using a SORTED listbox not visible to the user
    End Sub
    
    
    Private Sub Timer1_Timer()
        Static x As Integer
        List1.ListIndex = x
        Text2(x).Text = List1.Text
        x = x + 1
        If x > 3 Then
            x = 0
            Timer1.Enabled = False
            Command2.Enabled = True
        End If
    End Sub

    PROJECT: Attachment 167527

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    OR, to use a simple bubble sort, simply add this code (use this code -command4- instead of command1 or command2):

    Code:
    Private Sub Command4_Click()    
        Dim j As Integer
        Dim k As Integer
        Dim strTmp As String
        ' copy numbers from text1 to text2
        For j = Text1.LBound To Text1.UBound
            Text2(j).Text = Text1(j).Text
        Next j
        ' sort txtOut
        For j = Text2.LBound To Text2.UBound - 1
            For k = j + 1 To Text2.UBound
                If Val(Text2(j).Text) > Val(Text2(k).Text) Then
                    strTmp = Text2(j).Text
                    Text2(j).Text = Text2(k).Text
                    Text2(k) = strTmp
                End If
            Next k
        Next j
    End Sub
    if you want to do it slowly, you can keep text2 boxes forecolor and backcolor the same until you go through a timer to change one or the other! ~smile~

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,920

    Re: Transferring data from textbox to textbox in sequence Vb6

    Quote Originally Posted by Phill.W View Post
    > "Whatever result I get from the numbers from above must be put in order ..."

    Now that sounds more like a Sorting problem.
    ...
    Regards, Phill W.
    No, I don't think it is a sorting problem, especially since you dropped the rest of the statement.

    >"Whatever result I get from the numbers from above must be put in order to the following textbox5, textbox6, textbox7, textbox8. "

    It is somewhat likely to interpret that statement in isolation to indicate that the "numbers must be put in order", meaning to sort the numbers, but that doesn't agree with the rest of the statements made in the first post. The "put" in this case, is referring to the textboxes, meaning the numbers being selected, without repeats, must be "put" in the textboxes in the order they are picked, i.e. the first number selected in textbox5, second in textbox6, etc...

    That was actually more clearly stated at the end of the first post.

    > "The numbers from above must be transferred in any order but must be filled in sequence from textbox5 to textbox8."

    That is why I said that a timer or single action "pick or draw a number" from the textboxes must be implemented in order to actually see the transfer rather than the result, otherwise how could you verify in what order (sequence) the textboxes were filled.
    Last edited by passel; Apr 15th, 2019 at 08:21 AM.

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

    Re: Transferring data from textbox to textbox in sequence Vb6

    Ok, I'm done havin' fun...back to mowing...but first, here is an updated project to possibly do what OP wants...again, just guessing....so many variables...

    Attachment 167541

Tags for this Thread

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