OK so you should probably be using a class, something like this - >
Code:
Public Class Countries
Private _name As String
Private _code As String
Private _capital As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property Code() As String
Get
Return _code
End Get
Set(ByVal value As String)
_code = value
End Set
End Property
Public Property Capital() As String
Get
Return _capital
End Get
Set(ByVal value As String)
_capital = value
End Set
End Property
End Class
Then you can do this -
n.b. - personally i would be pulling my country data form a database but here i will just add a couple manually
Code:
Dim CountryList As New List(Of Countries)
' put this as a form / class level variable
'Load the country info
Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim _Countries As New Countries
_Countries.Name = "USA"
_Countries.Code = "0001"
_Countries.Capital = "Washington DC"
CountryList.Add(_Countries)
_Countries = New Countries
_Countries.Name = "Canada"
_Countries.Code = "0002"
_Countries.Capital = "Ottawa"
CountryList.Add(_Countries)
End Sub
'Then the FindCapital function
Code:
Function FindCapital(ByVal CountryCode As Integer, ByVal CountryName As String) As List(Of Countries)
Dim selectedValues As List(Of Countries)
selectedValues = CountryList.FindAll(Function(p) p.Name = CountryName And p.Code = CountryCode)
Return selectedValues
End Function
and you can then use your list like this to return either a Capital OR a list of countries and country information -
Code:
Sub TestGetCapital()
Dim CountryCapitals As List(Of Countries)
Dim Capital As String
CountryCapitals = FindCapital("0001", "USA")
Capital = CountryCapitals(0).Capital
End Sub
Sub TestGetAllCountries()
Dim item As Countries
Dim name As String
Dim capital As String
Dim code As String
For Each item In CountryList
name = item.Name
capital = item.Capital
code = item.Code
'do stuff with values
Next
End Sub
Obviously these are just examples so i have used strings to hold the returned data, but you could put into a list view or grid or text-boxes or whatever you want really.