Hi
Dare I ask another question!
I have a second form which opens via a button on main form. This form shows a score table (32 textboxes) The display/saving/loading/hiding for this form all work OK.
I now have a new score (4 of the text boxes) to change.
The following Sub seems to achieve the resorting of the ScoresTable Collection (the score table text boxes) inserting a new score appropriately. However, this doesn't change the values on the score table but the changes are saved to disc from a subsequent Write operation. So if I rerun the App, the new scores are now showing correctly.
What am I missing here to make the changes Hope there is enough info there.
Sub CheckIfScoreGetIntoTable() Dim Flag As Integer = 0, i As Integer = 1 Dim t1, t2, t3, t4 As New TextBoxt1.Text = WordSearch.PlayerName.Text
t2.Text = WordSearch.Skill.Text
t3.Text = WordSearch.WordCount.Text
t4.Text = WordSearch.ScoreCount.Text
For i = WordSearch.ScoresTable.Count To 4 Step -4 If Val(t4.Text) > Val(WordSearch.ScoresTable(i).text) ThenFlag = i
End If Next If Flag > 0 ThenWordSearch.ScoresTable.Add(t1, , Flag - 3)
WordSearch.ScoresTable.Add(t2, , Flag - 2)
WordSearch.ScoresTable.Add(t3, , Flag - 1)
WordSearch.ScoresTable.Add(t4, , Flag)
i = WordSearch.ScoresTable.Count
WordSearch.ScoresTable.Remove(i)
WordSearch.ScoresTable.Remove(i - 1)
WordSearch.ScoresTable.Remove(i - 2)
WordSearch.ScoresTable.Remove(i - 3)
WriteScoresToFile()
End If End Sub
(newbie) How to refresh text box contents
TheToefistJU
Yes
My.Application.DoEvents Method
what it will do is cause the application to Process all Windows messages currently in the message queue.
In which case the updating of the text box contents.
This can be useful when then the updates are happening so quickly so in a loop where there are numerous iterations but not much processing between the applications - which sometimes causes the controls to not refresh each time.
My.Application.DoEvents may slow some applications down a little as its yielding to allow all the windows messages (requests to update say the textbox display) but you get some behaviour which you expect.
Use very judiciously, only as and when required.
Risotto
Hi
For anyone still reading here about this troublesone problem, I have finally got it working. I'm unsure as to why my new approach works and the old didn't, but here below is the new working procedure.
I introduced a
Public ScoresPanel As New Panel
into the mix, and from then on, builr the new routine arounf that.
A final thanks to all for the help in getting me over this mountain. More threads to follow for other issues
-----------------------------------------------------------------
Sub CheckIfScoreGetIntoTable() Dim Flag As Integer = 0, r As Integer = 0, c As Integer = 1 Dim tt As New TextBox For Each tt In ScoresPanel.Controls If c = 4 Then If Val(WordSearch.ScoreCount.Text) < Val(tt.Text) ThenFlag = r
End Ifc = 0
End Ifr += 1
c += 1
Next If Flag < ScoresPanel.Controls.Count - 1 Then For r = ScoresPanel.Controls.Count - 4 To Flag + 1 Step -4ScoresPanel.Controls(r).Text = ScoresPanel.Controls(r - 4).Text
ScoresPanel.Controls(r + 1).Text = ScoresPanel.Controls(r - 3).Text
ScoresPanel.Controls(r + 2).Text = ScoresPanel.Controls(r - 2).Text
ScoresPanel.Controls(r + 3).Text = ScoresPanel.Controls(r - 1).Text
Next If Flag = 0 ThenScoresPanel.Controls(Flag).Text = WordSearch.PlayerName.Text
ScoresPanel.Controls(Flag + 1).Text = WordSearch.Skill.Text
ScoresPanel.Controls(Flag + 2).Text = WordSearch.WordCount.Text
ScoresPanel.Controls(Flag + 3).Text = WordSearch.ScoreCount.Text
ElseScoresPanel.Controls(Flag + 1).Text = WordSearch.PlayerName.Text
ScoresPanel.Controls(Flag + 2).Text = WordSearch.Skill.Text
ScoresPanel.Controls(Flag + 3).Text = WordSearch.WordCount.Text
ScoresPanel.Controls(Flag + 4).Text = WordSearch.ScoreCount.Text
End IfnewScoresForm.Show()
End If End SubAnthonyAM444
I don't think a doevents is all that's necessary. It sounds as if this process is at quiesence.
Leshay... after updating... try a refresh on those boxes.
There is another proprty of the CLR at the back of my mind where one form is updating another has a kink in it and I'm tring to remember why that is.
Jonathan Blackburn
Yes, your right that these textboxes are not linked to textboxes on a form.
If you want to link the reference variables to textboxes on the forms
Dim t1 as textbox = form1.textbox1
Dim t2 as textbox = form1.textbox2
Dim t3 as textbox = form1.textbox3
Dim t4 as textbox = form1.textbox4
This would link the reference variables with actual instances of textboxes on
an instance of a form called form1
Dim t1 as textbox = new textbox
Dim t1 as new textbox
will simply create a textbox control in memory.
Ean L. Towne
When I used
Dim t1, t2, t3, t4 As New TextBox
these 4 are used to format the game results ready (hopefully) to use further down to add to the scoretable collection - they are just temporary variables.
As I said, they are doing the job since after the whole subroutine exits, the new scorestable is correctly written to a text file. (writing the contents of the ScoresTable Collection)
Getting back to your suggestion. I can't see any difference (I would defer to you correcting me) between the two methods (considering the local use). eg
Dim
t1 As TextBox = WordSearch.PlayerNameand
Dim
t1 As TextBoxt1.Text = WordSearch.PlayerName.Text
I have now ammended as per your suggestion as follows:
Sub CheckIfScoreGetIntoTable() Dim Flag As Integer = 0, i As Integer = 1 Dim t1 As TextBox = WordSearch.PlayerName Dim t2 As TextBox = WordSearch.PlayerNamet2.Text = WordSearch.Skill.Text
' this is a combobox Dim t3 As TextBox = WordSearch.WordCount Dim t4 As TextBox = WordSearch.ScoreCount For i = WordSearch.ScoresTable.Count To 4 Step -4 If Val(t4.Text) > Val(WordSearch.ScoresTable(i).text) ThenFlag = i
End If Next If Flag > 0 ThenWordSearch.ScoresTable.Add(t1, , Flag - 3)
WordSearch.ScoresTable.Add(t2, , Flag - 2)
WordSearch.ScoresTable.Add(t3, , Flag - 1)
WordSearch.ScoresTable.Add(t4, , Flag)
i = WordSearch.ScoresTable.Count
WordSearch.ScoresTable.Remove(i)
WordSearch.ScoresTable.Remove(i - 1)
WordSearch.ScoresTable.Remove(i - 2)
WordSearch.ScoresTable.Remove(i - 3)
End If End SubUsing this code still results in exactly the same behaviour. The ScoresTable continues with the old values, but on reloading the app the correct new ScoresTable is displayed. The ScoresTable textboxes are the ScoresTable Collection.
Richard Willis
Leshay,
Since you are doing dynamic controls now... largely I stick with them for a lot of reasons. It's a little more work but... you learn more and it requires more than just be clicking on boxes.....
I acknowledge you.
bander
Krobar
I'm not sure how two of us missed this:
Dim t1, t2, t3, t4 As New TextBox
You're creating four textboxes, then setting the values and using them. These textboxes have nothing to do with the text boxes on your forms, they are just floating in the ether, not displaying anywhere. What is it you're trying to do here I suspect you want to create a delegate, which is a function definition in one class, which is tied to a function that can be in another class. Defining a delegate, hooking it up to a method in the form with the text boxes, and then calling it from the method that has the data to update ( passing that data through and setting the text boxes with it ) is the way to pass data to another form. Or, if you have the form as a member variable, define properties that set the text on the text boxes, and set them that way.
xpy1999
OK, well the problem you have is that if you're dynamically adding these text boxes, you don't have a referene to them, although you can name them and search for them in the controls collection.
Any reason you can't just use labels, added in the normal way, without needing any panels
It sounds to my like your high score form should just initialise itself by working out what the current high scores are, by whatever method you use, and the main form should be responsibile for storing the high scores, if a new high score exists.
Scott Simms
cgraus
I'm afraid most of that is over my head, but I will try to explain further.
The game main form has most of the controls and a game grid of 72 textboxes. One button opens the High score table which is a form with a panel with 32 text boxes displaying the high score data. All this works reasonable fine, even if the code may be clunky.
So now I have a new score, and the routine I posted is my attempt to check/sort the scores and hopefully to redisplay them.
Here are some snippets that might be relevant
In the score table run time create routine the following is done
newP.Controls.Add(newT)
newT is a text box added to a new panel (32 of them),
WordSearch.ScoresTable.Add(newT)
adds the same textboxes to the
Public ScoresTable As New CollectionThen, I am eventually trying to effect the changes to the score table by altering the collection of text boxes as shown in the procedure posted previously.
eg WordSearch.ScoresTable.Add(t1, , Flag - 3)I suspect I am not explaining it very well though.
Kenshiro
cgraus
OK, some more info was posted while I was working on my last reply. I'll have a play with some of that,
Regarding the question of my choosing dynamic over pre made controls, well that was because I figured I needed to learn, and that seemed a more worthy method to that end. I can certainly see that if this was a critical application for me, that I would have to think simple instead of complex. I feel I am learning more from my miskes than if I nade simple forms which I could possibly deal with more easily.
I had thought of posting larger pieces of code to simplify my explanations of the problem, but I thought I would wait until I had read the forum rules before doing that - just in case it wasn't permitted to overdo the post size.
I'll be back soon though
Ian Price
Hi again ReneeC
I am having flashbacks about the points you raised in the other thread. Although I can't see those point being pertinent here, I can't help but think that they may well be
When you say try a refresh on those boxes - what do you mean If you mean what I think you mean, then that's what this problematic procedure is supposed to be doing!
To simplify. If you have a form with boxes based on a Public Collection, and you changed some properties of some of the boxes by manipulating the Collection boxes - then how would you refresh them
In my previous posted procedure, I thought I was doing the refresh by adding the new textboxes and deleting the old textboxes from the Collection ScoreTable
I am thinking that because, in effect, that what I did with the 72 textbox main form - via
Sub PlaceNewLettersInGrid(ByVal RefreshWord As String) Dim t As New TextBox, fillstring As Stringfillstring = MakeRandomString(RefreshWord)
For Each t In myTextboxest.BackColor = Color.White
t.Text = Microsoft.VisualBasic.Left(fillstring, 1)
fillstring = Microsoft.VisualBasic.Right(fillstring, Len(fillstring) - 1)
NextWordInputString.Text =
""WhatWordToFind.Text = RefreshWord
FindWhichWord = RefreshWord
End Subshadow-k8
Unfortunately, that didn't work. I wish it did.
timbailey