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.
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.
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.....
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
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.
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
Re: Transferring data from textbox to textbox in sequence Vb6
Quote:
Originally Posted by
SamOscarBrown
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.
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
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).
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
Re: Transferring data from textbox to textbox in sequence Vb6
Guess we can keep on guessing until OP answers better....
Re: Transferring data from textbox to textbox in sequence Vb6
Quote:
Originally Posted by
ChrisE
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
...
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.
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.
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
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~
Re: Transferring data from textbox to textbox in sequence Vb6
Quote:
Originally Posted by
Phill.W
> "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.
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