|
A thread doesn't call "it's own sub" as threads are not limited to a single sub, as you put it. You setup a loop inside the sub to keep itself running until some bailout condition is met. Using Thread.Abort is a poor choice to end a thread.
|
|
|
|
|
You wrote " A thread doesn't call "it's own sub""
I have done just this and things seem to work ok, or have I inadvertently started a memory leak?
You wrote "You setup a loop inside the sub to keep itself running until some bailout condition is met."
So to clarify, I guess you are saying once a sub is started as a thread, inside that sub, if you want it to continue to run (like TCPListener) keep looping as long as you want it to listen.
"Using Thread.Abort is a poor choice to end a thread."
As an aside, what is the proper method to terminate the thread and can it be terminated from within the 'threaded' sub?
|
|
|
|
|
crashcup wrote: I have done just this and things seem to work ok, or have I inadvertently started a memory leak?
crashcup wrote: As an aside, what is the proper method to terminate the thread and can it be terminated from within the 'threaded' sub?
Your description is a bit vague, but, you may have done that. You do not need to keep launching a new thread to execute the sub again. Like I said, you can setup a loop in the sub that keeps executing until a bailout condition is met, such as a boolean variable (flag) being set. With each iteration of the loop, it should check to see if this flag is set and, if so, bail out of the loop and let the code end itself, which also kills the thread automatically.
|
|
|
|
|
Thanks. I'll accepth this answer, and change my sub to keep looping.
|
|
|
|
|
For future reference, I was only using your terminology. If you want to avoid some confusion later on (like someone mistaking you for VB6 code), use the term "method" instead of "sub". "sub" and "function" are just syntax leftovers from the old VBx days.
|
|
|
|
|
Hey guys well i am trying to sort an array that is already filled with string data at form load. in 4 different labels the array displays the values. When a user click an arrange button I am trying to sort each element in the labels in ascending order. So for example the labels are loaded with this data: (please HELP)
'this code is at form LOAD and sends each value in the array to each label one at a time
For i As Integer = 0 To ShuffleCards.cards2.Length - 1 Step 4
'gets the corresponding value from the array and pass to labelbox
lblPlayer1.Text += ShuffleCards.cards2(i)
lblPlayer2.Text += ShuffleCards.cards2(i + 1)
lblPlayer3.Text += ShuffleCards.cards2(i + 2)
lblPlayer4.Text += ShuffleCards.cards2(i + 3)
Next 'end for
'*********************************************************
'this next code is where i am having trouble trying to sort in ascending order each value the label already has in it
'RIGHT NOW ALL IT IS DOING IS ONLY DISPLAYING ONE VALUE AND NOT THE CORRECT DATA THAT THE LABEL HAS ALREADY BEEN LOADED
'WITH
Private Sub btnArrange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnArrange.Click
'*************************************************
'this sub will sort the players cards in increasing
'order using sort
Dim j, temp, count As Integer
lblPlayer1.Text = ""
lblPlayer2.Text = ""
lblPlayer3.Text = ""
lblPlayer4.Text = ""
For i As Integer = 0 To ShuffleCards.cards2.Length - 1 Step 4
'this will sort your array in ascending order
For count = 0 To ShuffleCards.cards2.Length - 1
For j = count + 1 To ShuffleCards.cards2.Length - 1
If ShuffleCards.cards2(count) > ShuffleCards.cards2(j) Then
ShuffleCards.cards2(count) = ShuffleCards.cards2(j)
ShuffleCards.cards2(j) = temp
End If
Next j
Next count
lblPlayer1.Text += ShuffleCards.cards2(temp)
lblPlayer2.Text += ShuffleCards.cards2(temp + 1)
lblPlayer3.Text += ShuffleCards.cards2(temp + 2)
lblPlayer4.Text += ShuffleCards.cards2(temp + 3)
Next
End Sub
|
|
|
|
|
Hi,
arrays and collections in .NET have a Sort() method that takes care of it, with a default sort order depending on element type, and a way to specify your own sort order; I explained it here[^].
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
PAguilar09 wrote: For count = 0 To ShuffleCards.cards2.Length - 1
For j = count + 1 To ShuffleCards.cards2.Length - 1
If ShuffleCards.cards2(count) > ShuffleCards.cards2(j) Then
ShuffleCards.cards2(count) = ShuffleCards.cards2(j)
ShuffleCards.cards2(j) = temp
End If
Next j
Next count
you must set a value for temp when swapping two cards, a normal swap takes 3 statements inside the IF.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Okay i tried fixing my code but I am still not getting my labels to sort the values they contain in ascending order??
the labels look like this at form load:
Player 1: D7 HK D2 CK D10 H5 HA C4 C6 C7 H2 SJ D3
Player2: DA S6 HQ CJ DQ D9 CQ H6 C3 SA S8 D5 D8
When i hit Arrange button the output should
sort them in ascending order: P1: C4 C6 D2 D3 D7 D10 H2 H5 HK HA SJ
AND SO ON AND SO ON FOR 4 OTHER LABELS
but i dont know what I am missing or not doing correctly??? Please help
For i As Integer = 0 To ShuffleCards.cards2.Length - 1
'this will sort your array in ascending order
' For count = 0 To ShuffleCards.cards2.Length - 1 Step 4
For j = count + 1 To ShuffleCards.cards2.Length - 1
If ShuffleCards.cards2(count) > ShuffleCards.cards2(j) Then
ShuffleCards.cards2(count) = ShuffleCards.cards2(j)
'temp = ShuffleCards.cards2(j)
lblPlayer1.Text += ShuffleCards.cards2(j)
lblPlayer2.Text += ShuffleCards.cards2(j + 1)
lblPlayer3.Text += ShuffleCards.cards2(j + 2)
lblPlayer4.Text += ShuffleCards.cards2(j + 3)
End If
Next j
'Next count
Next
|
|
|
|
|
1.
you are not following up on earlier replies.
I told you a swap needs 3 statements, you had 2, and now you only have 1.
If you were to use the available Sort() method, you would need less of your code, and hence would have fewer bugs.
2.
what kind of order is "C4 C6 D2 D3 D7 D10 H2 H5 HK HA SJ"?
- it is not numeric as these aren't numbers;
- it is not alphabetic as then D10 would precede D2, and HA would precede HK.
Hence you need your own Comparer; read my article on sorting.
3.
I think you're not up to the job you set yourself.
I recommend you read a basic book on VB.NET and work your way through it.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
i tried using .Sort()but i just keep getting an error. In class we were told to use a two-dim sort to arrange this type of array containing values such as: "DK C2 SJ H10"
|
|
|
|
|
hi,how are you?
What code would do this?
Please help me.
Thanks!
|
|
|
|
|
I found the answer
The code is
Private Sub FillComboBox()
Tv.PathSeparator = ">>>"
Dim nodes As New List(Of TreeNode)
Dim queue As New Queue(Of TreeNode)
Dim top As TreeNode
Dim nod As TreeNode
For Each top In Tv.Nodes
queue.Enqueue(top)
Next
While (queue.Count > 0)
top = queue.Dequeue
nodes.Add(top)
For Each nod In top.Nodes
queue.Enqueue(nod)
Next
End While
' nodes.Sort(System.Collections.Generic.IComparer(Of TreeView))
For i As Integer = 0 To nodes.Count - 1
GroupQuestionsCbo.Items.Add(nodes(i).FullPath)
Next
End Sub
|
|
|
|
|
I'm glad you found your answer, because your question was very ambiguous.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Hello everyone
I'd like a movie resolution get,now How to get a movie resolution (film file)?
Please help,
|
|
|
|
|
|
That's shown in the shell, you can try to get it from there, or you can use DirectX to examine the video directly.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Is a good way.But there is no other way,for example api.
Thanks for your answer.
|
|
|
|
|
miladbiranvand wrote: But there is no other way,for example api.
Yes, there's a much better way, that's why I told you a different way.
Like I said, if there's a way to question the shell for this value, I am not familiar with it ( google, perhaps ? ). In fact, I had to do this recently and was surprised at how hard it was. I use a DirectX library to do it using DirectX.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Okay guys here is was i am trying to do. I have an array that has been loaded with a list of data. The user clicks a button that will take each element in the array and display it in SEPARATE Label Boxes. I need help figuring out how to accomplish this though. here is my current code, right now I have it sending all the elements in the array to only one Labelbox, and i need to do somethign like this:
label1.text WOULD EQUAL first value in array
label2.text WOULD EQUAL second value in array
label3.text would equal third value
label4.text would EQUAL 4th value in array
then the next item(5th value) would display in label 1
then the 6th would be in label2 and so on and so on..... until last element has passed to the corresponding label
Right now the code i am showing is only passing the whole array to label1
Private Sub btnDeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeal.Click
'***********************************************************
'this subroutine will deal each player his/her own cards
'in a round robin fashion and display them in each
'players label box
'***********************************************************
For i As Integer = 0 To cards2.Length - 1
'cards2 being myarray
'gets the values from the array
lblPlayer1.Text += cards2(i)
Next
End Sub
|
|
|
|
|
PAguilar09 wrote: lblPlayer1.Text += cards2(i)
Because that is what you are doing. You are not setting text for the other labels anywhere. Instead of stepping by 1 in your for loop, step by 5. And set the text of all the five labels just like you have done for label1. Something like this in your loop:
lblPlayer1.Text += cards2(i)
lblPlayer2.Text += cards2(i+1)
lblPlayer3.Text += cards2(i+2)
lblPlayer4.Text += cards2(i+3)
lblPlayer5.Text += cards2(i+4)
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
You got a lot of suggestions the last time you asked this. This code is better in that it does *something*, but it doesn't seem to consider any of the suggestions you were given before.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I need the code to: choose a color, and get the "Hex" code for it, the 6 figure code used in css. So basically A ColorDialog and when they choose the color it prints out the 6 digit HTML hex code name of the color, for use in the css of web pages.
Please help me with coding that, this is what I have so far:
If TextBox1.Text = "" Then
Button1.Text = "Choose Color"
TextBox1.Text = ColorDialog1.Color.ToArgb
TextBox1.BackColor = ColorDialog1.Color
ElseIf TextBox2.Text = "" Then
Button1.Text = "Choose Another"
TextBox2.Text = ColorDialog1.Color.ToArgb.ToString
TextBox2.BackColor = ColorDialog1.Color
ElseIf TextBox3.Text = "" Then
TextBox3.Text = ColorDialog1.Color.ToArgb.ToString
TextBox3.BackColor = ColorDialog1.Color
ElseIf TextBox4.Text = "" Then
TextBox4.Text = ColorDialog1.Color.ToArgb.ToString
TextBox4.BackColor = ColorDialog1.Color
ElseIf TextBox5.Text = "" Then
TextBox5.Text = ColorDialog1.Color.ToArgb.ToString
TextBox5.BackColor = ColorDialog1.Color
ElseIf TextBox6.Text = "" Then
TextBox6.Text = ColorDialog1.Color.ToArgb.ToString
TextBox6.BackColor = ColorDialog1.Color
ElseIf TextBox7.Text = "" Then
TextBox7.Text = ColorDialog1.Color.ToArgb.ToString
TextBox7.BackColor = ColorDialog1.Color
ElseIf TextBox8.Text = "" Then
TextBox8.Text = ColorDialog1.Color.ToArgb.ToString
TextBox8.BackColor = ColorDialog1.Color
ElseIf TextBox9.Text = "" Then
TextBox9.Text = ColorDialog1.Color.ToArgb.ToString
TextBox9.BackColor = ColorDialog1.Color
ElseIf TextBox10.Text = "" Then
TextBox10.Text = ColorDialog1.Color.ToArgb.ToString
TextBox10.BackColor = ColorDialog1.Color
Else
TextBox1.Text = ""
TextBox1.BackColor = Color.White
TextBox2.Text = ""
TextBox2.BackColor = Color.White
TextBox3.Text = ""
TextBox3.BackColor = Color.White
TextBox4.Text = ""
TextBox4.BackColor = Color.White
TextBox5.Text = ""
TextBox5.BackColor = Color.White
TextBox6.Text = ""
TextBox6.BackColor = Color.White
TextBox7.Text = ""
TextBox7.BackColor = Color.White
TextBox8.Text = ""
TextBox8.BackColor = Color.White
TextBox9.Text = ""
TextBox9.BackColor = Color.White
TextBox10.Text = ""
TextBox10.BackColor = Color.White
TextBox1.Text = ColorDialog1.Color.ToArgb.ToString
TextBox1.BackColor = ColorDialog1.Color
End If
I have 10 textboxes to choose 10 colors, and once the click Choose another after all the textboxes had already been filled, it will reset the form, and paste the new color in the first textbox. Please Help, Thank-You!!!
|
|
|
|
|
Your hex value is RGB in hex, so just use the ToString overload with a format string to make it show in hex ( I think it's just X, or perhaps H )
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hello. One program code Gsm_Modem to send or receive has to face. hardware that me with the USB port. Anyone who can help me.
Tanks!
|
|
|
|