My issue is simple...my attempts at solution have failed. I am developing a replica of an old game show, Tic Tac Dough.
On the program, initially nine categories are shown in a tic-tic-toe type arrangement. After a contestant chooses and answers (either correctly or incorrectly) a question in a category, an X or an O is placed where the category existed.
I have written code to populate the nine textboxes (textbox1 array---1 to 9) with the categories I initially place in a listbox. After a contestant answers a question in one of the categories, I place an X or an O in that textbox1(?) of the corresponding chosen category.
I then remove that category from the listbox. Then, I attempted to shuffle the categories once again and place them in the remaining eight(8) textboxes, attempting to keep the X or O in the one chosen. And then, the next step would be to place a second X or O in one of those remaining eight textboxes, and repeat the process of removing from the listbox, shuffling the listbox, and then repopulating the remaining seven listboxes, and so forth until all nine categories have been selected.
My problem is that after I remove one of the categories and try to repopulate the textboxes, I cannot figure out how to keep the X or O in the chosen textbox, and populate the other eight.
I know this is a long drawn out explanation...I hope the following code (which does NOT do as I wish on the Command1 button once an item has been removed from the listbox) will help you understand my dilemma.
I have nine textboxes (textbox1(1 through 9)(multiline=true), a listbox1, a command1 (to shuffle categories and repopulate the (nine) textboxes) and an array of option boxes (option1(0) and option1(1) determine which player is playing)...here's the code:
EDIT: Sorry...these are the steps:
Launch the program
Click on the Command1 button
Select one of the nine textboxes (categories)
Click on the Command1 button again---THIS IS WHERE IT DOES NOT DO AS I WISH>
On the program, initially nine categories are shown in a tic-tic-toe type arrangement. After a contestant chooses and answers (either correctly or incorrectly) a question in a category, an X or an O is placed where the category existed.
I have written code to populate the nine textboxes (textbox1 array---1 to 9) with the categories I initially place in a listbox. After a contestant answers a question in one of the categories, I place an X or an O in that textbox1(?) of the corresponding chosen category.
I then remove that category from the listbox. Then, I attempted to shuffle the categories once again and place them in the remaining eight(8) textboxes, attempting to keep the X or O in the one chosen. And then, the next step would be to place a second X or O in one of those remaining eight textboxes, and repeat the process of removing from the listbox, shuffling the listbox, and then repopulating the remaining seven listboxes, and so forth until all nine categories have been selected.
My problem is that after I remove one of the categories and try to repopulate the textboxes, I cannot figure out how to keep the X or O in the chosen textbox, and populate the other eight.
I know this is a long drawn out explanation...I hope the following code (which does NOT do as I wish on the Command1 button once an item has been removed from the listbox) will help you understand my dilemma.
I have nine textboxes (textbox1(1 through 9)(multiline=true), a listbox1, a command1 (to shuffle categories and repopulate the (nine) textboxes) and an array of option boxes (option1(0) and option1(1) determine which player is playing)...here's the code:
Code:
Option Explicit
Private Sub Command1_Click()
'****reorder list1 randomly*******************************
Dim x As Integer, y As Integer, colTemp As New Collection
For x = 0 To List1.ListCount - 1
colTemp.Add List1.List(x)
Next
List1.Clear
Do While colTemp.Count
Randomize
y = Int((colTemp.Count * Rnd) + 1)
List1.AddItem colTemp(y)
colTemp.Remove y
Loop
'*********Populate textboxes with entries in listbox1
For x = 1 To List1.ListCount
List1.ListIndex = x - 1
Text1(x).Text = List1.Text
If Text1(x).Text = "X" Or Text1(x).Text = "O" Then
Text1(x).FontSize = 48 'to adjust for larger fonts
Else
Text1(x).FontSize = 24 'to adjust for smaller fonts to fit into multiline textboxes
End If
Next x
End Sub
Private Sub Form_Load()
Me.Width = Screen.Width
Image1.Left = 0
Image1.Top = 0
Image1.Width = Me.Width
Image1.Height = Me.Height - 200
resetBoardToStart 'Sets "1" through "9" as displayed texts on text1() array
popListBox 'Initially sets up Categories to use for questions
Randomize
End Sub
Private Sub resetBoardToStart() ' 'Sets/Resets "1" through "9" as displayed texts on text1() array
Dim x As Integer
For x = 1 To 9
Text1(x).Text = Str(x)
Next x
End Sub
Private Sub popListBox() 'Categories for questions-will be populated from ACCESS DB in future
List1.AddItem ("WORLD WAR II")
List1.AddItem ("COMIC STRIPS")
List1.AddItem ("THE STAGE")
List1.AddItem ("FACES")
List1.AddItem ("AQUATIC BIOLOGY")
List1.AddItem ("WOMEN IN SONGS")
List1.AddItem ("US GEOGRAPHY")
List1.AddItem ("JUMP IN CATEGORY")
List1.AddItem ("WHO AM I?")
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
Private Sub Text1_Click(Index As Integer) 'click event of the textbox array--done after a contestant guesses
'(more to be done on this if the answer is incorrect, but for now, just assuming the answer IS correct and the X or the O is placed in the selected textbox)
'*****Depending upon which of the two contestants are playing, put an X or an O in one of the nine textboxes
Dim myText As String, x As Integer, myArray(8) As Integer
myText = Text1(Index).Text
If Option1(0).Value = True Then 'Player # 1's turn
Text1(Index).Text = "X"
Else 'Player #2's turn
Text1(Index).Text = "O"
End If
'Removes selected Category (one of the original nine) from the listbox
For x = List1.ListCount - 1 To 0 Step -1
List1.ListIndex = x
If myText = List1.Text Then
myArray(x) = List1.ListIndex
List1.RemoveItem (x)
End If
Next x
Text1(Index).FontSize = 48
End Sub
Launch the program
Click on the Command1 button
Select one of the nine textboxes (categories)
Click on the Command1 button again---THIS IS WHERE IT DOES NOT DO AS I WISH>