Hello there, i have been working on a simple program but cant get my head around it. It does not show any errors at the moment but when i run it does not do the things i would like it to do. I will paste in the code first and explain it below.
Public Class Form1
Const limit = 3
'Dim Countries(17, 17) As Byte
'Dim Capitals(17, 17) As Byte
Dim Countries(,) = {{"England", 0}, {"Russia", 1}, {"France", 2}, {"Portugal", 3}, {"Poland", 4}, {"New Zealand", 5}, {"Germany", 6}, {"Spain", 7}, {"Argentina", 8}, {"China", 9}, {"Japan", 10}, {"Monaco", 11}, {"Italy", 12}, {"Austria", 13}, {"Switzerland", 14}, {"Norway", 15}, {"Turkey", 16}}
Dim Capitals(,) = {{"London", 0}, {"Moscow", 1}, {"Paris", 2}, {"Lizbona", 3}, {"Warsaw", 4}, {"Wellington", 5}, {"Berlin", 6}, {"Madrid", 7}, {"Buenos Aires", 8}, {"Beijing", 9}, {"Tokyo", 10}, {"Monaco", 11}, {"Rome", 12}, {"Vienna", 13}, {"Bern", 14}, {"Oslo", 15}, {"Ankara", 16}}
'Dim All(16, 1) As String
Dim x As Integer
Dim y As Integer
Private Sub ShuffleItems()
Dim Random As New System.Random
lstCountries.BeginUpdate()
lstCapitals.BeginUpdate()
Dim ArrayList As New System.Collections.ArrayList(Countries)
Dim ArrayList1 As New System.Collections.ArrayList(Capitals)
lstCountries.Items.Clear()
lstCapitals.Items.Clear()
While ArrayList.Count > 0
Dim Index As System.Int32 = Random.Next(0, ArrayList.Count)
lstCountries.Items.Add(ArrayList(Index))
ArrayList.RemoveAt(Index)
End While
While ArrayList1.Count > 0
Dim Index As System.Int32 = Random.Next(0, ArrayList1.Count)
lstCapitals.Items.Add(ArrayList1(Index))
ArrayList1.RemoveAt(Index)
End While
lstCountries.EndUpdate()
lstCapitals.EndUpdate()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim count As Integer = -1
'Dim shuffle As New Random
'All(0, 0) = "England"
'All(0, 1) = "London"
'All(1, 0) = "Russia"
'All(1, 1) = "Moscow"
'All(2, 0) = "France"
'All(2, 1) = "Paris"
'All(3, 0) = "Germany"
'All(3, 1) = "Berlin"
'All(4, 0) = "Spain"
'All(4, 1) = "Madrid"
'Countries = {("England",0),( "Russia",1), ("France",2),( "Portugal",3), ("Poland",4), ("New Zealand",5), ("Germany",6), ("Spain",7), ("Argentina",8), ("China",9), ("Japan",10), ("Monaco",11), ("Italy",12), ("Austria",13), ("Switzerland",14), ("Norway",15), ("Turkey",16)}
'Capitals = {("London",0),( "Moscow",1),( "Paris",2),( "Lizbona",3),( "Warsaw",4),( "Wellington",5),( "Berlin",6), ("Madrid",7),( "Buenos Aires",8),( "Beijing",9),( "Tokyo",10),( "Monaco",11),( "Rome",12), ("Vienna",13) ,("Bern",14), ("Oslo",15), ("Ankara",16)}
'Countries(0) = "England"
'Countries(1) = "Russia"
'Countries(2) = "France"
'Countries(3) = "Portugal"
'Capitals(0) = "London"
'Capitals(1) = "Moscow"
'Capitals(2) = "Paris"
'Capitals(3) = "Lizbona"
ShuffleItems()
'lstCountries.SelectedIndex = shuffle.Next(0, lstCountries.Items.Count - 1)
'Do While count < Countries.Length - 1
' count = count + 1
' lstCountries.Items.Add(Countries(count))
' lstCapitals.Items.Add(Capitals(count))
'Loop
End Sub
Private Sub btnCheck_Click(sender As System.Object, e As System.EventArgs) Handles btnCheck.Click
Dim x As Integer
Dim y As Integer
For x = 0 To Countries.Length - 1
x += 1
If Countries(y, x) = lstCountries.SelectedItem.ToString And Countries(y, x) = lstCapitals.SelectedItem.ToString Then
lstCapitals.Items.RemoveAt(lstCapitals.SelectedIndex)
lstCountries.Items.RemoveAt(lstCountries.SelectedIndex)
End If
Next
'If lstCapitals.SelectedIndex = lstCountries.SelectedIndex Then
' lstCapitals.Items.RemoveAt(lstCapitals.SelectedIndex)
' lstCountries.Items.RemoveAt(lstCountries.SelectedIndex)
' MsgBox("Well done")
'ElseIf lstCountries.SelectedIndex <> lstCapitals.SelectedIndex Then
' MsgBox("Incorrect match")
' lstCapitals.ClearSelected()
' lstCountries.ClearSelected()
'End If
End Sub
Private Sub btnQuit_Click(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click
Dim intResponse As Integer
intResponse = MsgBox("Are you sure you want to quit?", _
vbYesNo + vbQuestion, _
"Quit")
If intResponse = vbYes Then
End
End If
End Sub
Private Sub btnHelp_Click(sender As System.Object, e As System.EventArgs) Handles btnHelp.Click
Me.Hide()
Form2.Show()
End Sub
End Class
So basically the form has help button to show instructions, quit to quit the program and check to check whether the country from listbox lstCountries matches the correct capital in lstCapitals.
The idea of the program is to shuffle the items in two arraylists and then add them to seperate listboxes called lstCountries and lstCapitals.
At start i used 1 dimensional array and it worked like a charm for mixing up items in arrays and then adding them to listboxes, but then the problem had to match the correct Country with correct Capital and it only worked if i picked the items on the same index such as 1 and 1(straight line).
It all sounds complicated and confusing, but any help will help.
P.S alot of code is commented out, because i have tried many ways to make it work.


