I have about 17 2-d arrays which need to be accessed based on user selection. I'd like to use a variable to represent these, but I get this error:
Too many arguments to 'Public ReadOnly Default Property Chars(index As Integer) As Char'
Here is a sample of my code:
ElseIf EcoType = "MB" Then
If MatrixVeg.Substring(0, 2) = "CO" Then
x = Array.IndexOf(CO, MatrixVeg)
EcoGroup = "MBCO"
ElseIf MatrixVeg.Substring(0, 2) = "HL" Then
x = Array.IndexOf(HL, MatrixVeg)
EcoGroup = "MBHL"
ElseIf MatrixVeg.Substring(0, 2) = "OF" Then
x = Array.IndexOf(OFF, MatrixVeg)
EcoGroup = "MBOF"
ElseIf MatrixVeg.Substring(0, 2) = "OW" Then
x = Array.IndexOf(OW, MatrixVeg)
EcoGroup = "MBOW"
ElseIf MatrixVeg.Substring(0, 2) = "SP" Then
x = Array.IndexOf(SP, MatrixVeg)
EcoGroup = "MBSP"
ElseIf MatrixVeg.Substring(0, 2) = "WC" Then
x = Array.IndexOf(WC, MatrixVeg)
EcoGroup = "MBWC"
ElseIf MatrixVeg.Substring(0, 2) = "WD" Then
x = Array.IndexOf(WD, MatrixVeg)
EcoGroup = "MBWD"
End If
End If
y = Array.IndexOf(ST, MatrixSoil)
Ecosite = EcoGroup(y, x)
Return Ecosite
Any help is greatly appreciated.
From your code and comments, it appears that MCO, MBHL,MBOF, etc. are variables, but in your If statements, you assign Ecogroup string values instead of the variables themselves.
All you should have to do to fix this is remove the quotation marks when you assign the values (e.g. EcoGroup = MBCO).
On a stylistic note, I'd recommend using a Select Case statement for this situation. Take a look at this revised code:
ElseIf EcoType = "MB" Then
Select Case MatrixVeg.Substring(0, 2)
Case "CO"
x = Array.IndexOf(CO, MatrixVeg)
EcoGroup = MBCO
Case "HL"
x = Array.IndexOf(HL, MatrixVeg)
EcoGroup = MBHL
Case "OF"
x = Array.IndexOf(OFF, MatrixVeg)
EcoGroup = MBOF
Case "OW"
x = Array.IndexOf(OW, MatrixVeg)
EcoGroup = MBOW
Case "SP"
x = Array.IndexOf(SP, MatrixVeg)
EcoGroup = MBSP
Case "WC"
x = Array.IndexOf(WC, MatrixVeg)
EcoGroup = MBWC
Case "WD"
x = Array.IndexOf(WD, MatrixVeg)
EcoGroup = MBWD
End Select
End If
y = Array.IndexOf(ST, MatrixSoil)
Ecosite = EcoGroup(y, x)
Return Ecosite
Related
I'm trying to build a chart composed of up-to-100% stacked columns, each with 4 series and, once built, upon hovering upon the series, return all bound data (in this case, user names)
I'm very close to what i want, but the tooltip is showing only the sums, which is expected, but i dont know how to proceed. If there's another way that passes over the hover, like clicking and, in the click, I recognize the series and all those that are there, that would help immensely too
What I Have right now
What I Want
After looking it up, i built the chart this way:
(right now its a code nightmare, but i will methodify everything properly later)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sql As New SqlCommand(my query, my connector)
connect()
Dim rs = sql.ExecuteReader
Dim dtTest1 As DataTable = New DataTable
If rs.Read Then
dtTest1.Load(rs)
End If
disconnect()
Dim arrayTempoCallback(dtTest1.Rows.Count) As Double
Dim arrayTempoInaptidao(dtTest1.Rows.Count) As Double
Dim arrayTempoParabens(dtTest1.Rows.Count) As Double
Dim arrayTempoRecusa(dtTest1.Rows.Count) As Double
Dim arrayTempoSemDados(dtTest1.Rows.Count) As Double
For Each item In dtTest1.Rows
arrayTempoCallback(dtTest1.Rows.IndexOf(item)) = item("TEMPO_CALLBACK")
arrayTempoInaptidao(dtTest1.Rows.IndexOf(item)) = item("TEMPO_INAPTIDAO")
arrayTempoParabens(dtTest1.Rows.IndexOf(item)) = item("TEMPO_PARABENS")
arrayTempoRecusa(dtTest1.Rows.IndexOf(item)) = item("TEMPO_RECUSA")
arrayTempoSemDados(dtTest1.Rows.IndexOf(item)) = item("TEMPO_SEMDADOS")
Next
Dim QuartisCallBack = Quartiles(arrayTempoCallback)
Dim QuartisTempoInaptidao = Quartiles(arrayTempoInaptidao)
Dim QuartisTempoParabens = Quartiles(arrayTempoParabens)
Dim QuartisTempoRecusa = Quartiles(arrayTempoRecusa)
Dim QuartisTempoSemDados = Quartiles(arrayTempoSemDados)
Dim tabelafinal As New DataTable
tabelafinal.Columns.Add("VALORES", GetType(String))
tabelafinal.Columns.Add("COLUNA", GetType(String))
tabelafinal.Columns.Add("COR", GetType(String))
Dim somaS As Integer = 0
Dim somaH As Integer = 0
Dim somaC As Integer = 0
Dim somaD As Integer = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_INAPTIDAO") < QuartisTempoInaptidao.Item1 Then
somaS += 1
ElseIf linha("TEMPO_INAPTIDAO") >= QuartisTempoInaptidao.Item1 AndAlso linha("TEMPO_INAPTIDAO") < QuartisTempoInaptidao.Item2 Then
somaH += 1
ElseIf linha("TEMPO_INAPTIDAO") >= QuartisTempoInaptidao.Item2 AndAlso linha("TEMPO_INAPTIDAO") < QuartisTempoInaptidao.Item3 Then
somaC += 1
ElseIf linha("TEMPO_INAPTIDAO") >= QuartisTempoInaptidao.Item3 Then
somaD += 1
End If
Next
tabelafinal.Rows.Add(somaS, "TM_INAP", "D")
tabelafinal.Rows.Add(somaH, "TM_INAP", "C")
tabelafinal.Rows.Add(somaC, "TM_INAP", "H")
tabelafinal.Rows.Add(somaD, "TM_INAP", "S")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_PARABENS") < QuartisTempoParabens.Item1 Then
somaS += 1
ElseIf linha("TEMPO_PARABENS") >= QuartisTempoParabens.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisTempoParabens.Item2 Then
somaH += 1
ElseIf linha("TEMPO_PARABENS") >= QuartisTempoParabens.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisTempoParabens.Item3 Then
somaC += 1
ElseIf linha("TEMPO_PARABENS") >= QuartisTempoParabens.Item3 Then
somaD += 1
End If
Next
tabelafinal.Rows.Add(somaS, "TM_PARABENS", "S")
tabelafinal.Rows.Add(somaH, "TM_PARABENS", "H")
tabelafinal.Rows.Add(somaC, "TM_PARABENS", "C")
tabelafinal.Rows.Add(somaD, "TM_PARABENS", "D")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_RECUSA") < QuartisTempoRecusa.Item1 Then
somaS += 1
ElseIf linha("TEMPO_RECUSA") >= QuartisTempoRecusa.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisTempoRecusa.Item2 Then
somaH += 1
ElseIf linha("TEMPO_RECUSA") >= QuartisTempoRecusa.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisTempoRecusa.Item3 Then
somaC += 1
ElseIf linha("TEMPO_RECUSA") >= QuartisTempoRecusa.Item3 Then
somaD += 1
End If
Next
tabelafinal.Rows.Add(somaS, "TM_RECUSA", "S")
tabelafinal.Rows.Add(somaH, "TM_RECUSA", "H")
tabelafinal.Rows.Add(somaC, "TM_RECUSA", "C")
tabelafinal.Rows.Add(somaD, "TM_RECUSA", "D")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_SEMDADOS") < QuartisTempoSemDados.Item1 Then
somaS += 1
ElseIf linha("TEMPO_SEMDADOS") >= QuartisTempoSemDados.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisTempoSemDados.Item2 Then
somaH += 1
ElseIf linha("TEMPO_SEMDADOS") >= QuartisTempoSemDados.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisTempoSemDados.Item3 Then
somaC += 1
ElseIf linha("TEMPO_SEMDADOS") >= QuartisTempoSemDados.Item3 Then
somaD += 1
End If
Next
Dim somaFinalSemDadosS As Integer = If(somaS < 0, 0, somaS)
Dim somaFinalSemDadosH As Integer = If(somaH < 0, 0, somaH)
Dim somaFinalSemDadosC As Integer = If(somaC < 0, 0, somaC)
Dim somaFinalSemDadosD As Integer = If(somaD < 0, 0, somaD)
tabelafinal.Rows.Add(somaFinalSemDadosS, "TM_SEMDADOS", "S")
tabelafinal.Rows.Add(somaFinalSemDadosH, "TM_SEMDADOS", "H")
tabelafinal.Rows.Add(somaFinalSemDadosC, "TM_SEMDADOS", "C")
tabelafinal.Rows.Add(somaFinalSemDadosD, "TM_SEMDADOS", "D")
somaC = somaD = somaH = somaS = 0
For Each linha In dtTest1.Rows
If linha("TEMPO_CALLBACK") < QuartisCallBack.Item1 Then
somaS += 1
ElseIf linha("TEMPO_CALLBACK") >= QuartisCallBack.Item1 AndAlso linha("TEMPO_PARABENS") < QuartisCallBack.Item2 Then
somaH += 1
ElseIf linha("TEMPO_CALLBACK") >= QuartisCallBack.Item2 AndAlso linha("TEMPO_PARABENS") < QuartisCallBack.Item3 Then
somaC += 1
ElseIf linha("TEMPO_CALLBACK") >= QuartisCallBack.Item3 Then
somaD += 1
End If
Next
Dim somaFinalCallBackS As Integer = If(somaS < 0, 0, somaS)
Dim somaFinalCallBackH As Integer = If(somaH < 0, 0, somaH)
Dim somaFinalCallBackC As Integer = If(somaC < 0, 0, somaC)
Dim somaFinalCallBackD As Integer = If(somaD < 0, 0, somaD)
tabelafinal.Rows.Add(somaFinalCallBackS, "TEMPO_CALLBACK", "S")
tabelafinal.Rows.Add(somaFinalCallBackH, "TEMPO_CALLBACK", "H")
tabelafinal.Rows.Add(somaFinalCallBackC, "TEMPO_CALLBACK", "C")
tabelafinal.Rows.Add(somaFinalCallBackD, "TEMPO_CALLBACK", "D")
Dim dv As DataView = New DataView(tabelafinal)
Chart1.AlignDataPointsByAxisLabel()
Chart1.DataBindCrossTable(dv, "COR", "COLUNA", "VALORES", "")
For Each cs As Series In Chart1.Series
cs.ChartType = SeriesChartType.StackedColumn100
cs.ToolTip = "Pessoas = #VALY"
Next
End Sub
Friend Function Quartiles(ByVal afVal As Double()) As Tuple(Of Double, Double, Double)
Dim iSize As Integer = afVal.Length
System.Array.Sort(afVal)
Dim iMid As Integer = iSize / 2
Dim fQ1 As Double = 0
Dim fQ2 As Double = 0
Dim fQ3 As Double = 0
If iSize Mod 2 = 0 Then
fQ2 = (afVal(iMid - 1) + afVal(iMid)) / 2
Dim iMidMid As Integer = iMid / 2
If iMid Mod 2 = 0 Then
fQ1 = (afVal(iMidMid - 1) + afVal(iMidMid)) / 2
fQ3 = (afVal(iMid + iMidMid - 1) + afVal(iMid + iMidMid)) / 2
Else
fQ1 = afVal(iMidMid)
fQ3 = afVal(iMidMid + iMid)
End If
ElseIf iSize = 1 Then
fQ1 = afVal(0)
fQ2 = afVal(0)
fQ3 = afVal(0)
Else
fQ2 = afVal(iMid)
If (iSize - 1) Mod 4 = 0 Then
Dim n As Integer = (iSize - 1) / 4
fQ1 = (afVal(n - 1) * 0.25) + (afVal(n) * 0.75)
fQ3 = (afVal(3 * n) * 0.75) + (afVal(3 * n + 1) * 0.25)
ElseIf (iSize - 3) Mod 4 = 0 Then
Dim n As Integer = (iSize - 3) / 4
fQ1 = (afVal(n) * 0.75) + (afVal(n + 1) * 0.25)
fQ3 = (afVal(3 * n + 1) * 0.25) + (afVal(3 * n + 2) * 0.75)
End If
End If
Return New Tuple(Of Double, Double, Double)(fQ1, fQ2, fQ3)
End Function
End Class
If I understand correctly, you are trying to show a tooltip (when hovering the cursor over one colored 'block' in the chart) that shows information about the data that makes up the point.
The problem is that each 'block' is only a single X and Y value. For example: The DataPoint behind the tooltip that shows 'Pessoas = 392' is actually just a simple DataPoint (Series-S X=5 Y=392) with no additional information.
To show a tooltip the way you want each one will have to be pre-set, like this:
point.ToolTip = "User1 in the series\nUser2 in the series\n..."
With the following global variables:
Dim SpilleBræt(8, 8) As PictureBox
Dim Position(8, 8) As String
Dim MarkeretFelt(8, 8) As String
Dim FeltFarve As String
Dim x As Integer
Dim y As Integer
Dim AktivMarkering As Boolean = 0
Dim SpilleBrik As String
And this code:
Private Sub PictureBox_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FeltValg As PictureBox = CType(sender, PictureBox)
If AktivMarkering = 1 Then
x = Mid(sender.name, sender.name.Length - 1, 1)
y = Mid(sender.name, sender.name.Length, 1)
Select Case Position(y, x)
Case "LightTileMarked"
Me.SpilleBræt(y, x).BackgroundImage = My.Resources.ResourceManager.GetObject(SpilleBrik & "LightTile")
Case "DarkTileMarked"
Me.SpilleBræt(y, x).BackgroundImage = My.Resources.ResourceManager.GetObject(SpilleBrik & "DarkTile")
Case Else
'fjerner markerede
Select Case Position(y, x)
Case "BlackTower", "WhiteTower"
MsgBox("Tårn")
Case "BlackHorse", "WhiteHorse"
MsgBox("Hest")
Case "BlackBishop", "WhiteBishop"
MsgBox("Løber")
Case "WhiteKing", "BlackKing"
MsgBox("Konge")
Case "WhiteQueen", "BlackQueen"
MsgBox("Dronning")
Case "WhitePawn", "BlackPawn"
For k As Integer = y To 1 Step -1
If Position(k, x) = "" Then
If (k + x) Mod 2 = 1 Then
FeltFarve = "DarkTile"
Else
FeltFarve = "LightTile"
End If
Me.SpilleBræt(x, k).BackgroundImage = My.Resources.ResourceManager.GetObject(FeltFarve)
ElseIf Position(k, x) = "WhitePawn" Or Position(k, x) = "BlackPawn" Then
'background død brik
Else
k = 1
End If
Next
End Select
End Select
Else
'indsætter markering
'x,y i picturebox'ens navn fx ->(SpilBrik44) hvor x=4 og y=4
x = Mid(sender.name, sender.name.Length - 1, 1)
y = Mid(sender.name, sender.name.Length, 1)
Select Case Position(y, x)
Case "BlackTower", "WhiteTower"
MsgBox("Tårn")
Case "BlackHorse", "WhiteHorse"
MsgBox("Hest")
Case "BlackBishop", "WhiteBishop"
MsgBox("Løber")
Case "WhiteKing", "BlackKing"
MsgBox("Konge")
Case "WhiteQueen", "BlackQueen"
MsgBox("Dronning")
Case "WhitePawn", "BlackPawn"
For k As Integer = y To 1 Step -1
If Position(k, x) = "" Then
If (k + x) Mod 2 = 1 Then
FeltFarve = "DarkTileMarked"
Else
FeltFarve = "LightTileMarked"
End If
Me.SpilleBræt(x, k).BackgroundImage = My.Resources.ResourceManager.GetObject(FeltFarve)
MarkeretFelt(x, k) = FeltFarve
AktivMarkering = 1
ElseIf Position(k, x) = "WhitePawn" Or Position(k, x) = "BlackPawn" Then
'background død brik
Else
k = 1
End If
Next
End Select
End If
End Sub
I have a problem with the first If statement aktivmarkering=1, goes directly to the 'Else' even though if statements is true.
First time code is run, aktivmarkering is = 0, and therefore it obviously goes to 'Else', but after that one has ben run AktivMarkering is = 1, and first if should be executed. I don't see why not - anyone whos able to help?
Thanks.
I am creating a program and I need help on how I should go at this I need it to read encoded letters and return the correct letter but any loop that I try I just get System.ArgumentOutOfRangeException and it says that I need to make sure that what I am calling is just as long as what is there.
Private Sub btnDecode_Click(sender As Object, e As EventArgs) Handles btnDecode.Click
Do While ((y / 4) = txtDecoded.Text.Length)
If txtEncoded.Text.Substring(y, 1) = "1" Then
y = y + 1
If txtEncoded.Text.Substring(y, 1) = "0" Then
y = y + 1
If txtEncoded.Text.Substring(y, 1) = "1" Then
y = y + 2
strholder2(z) = "S"
ElseIf txtEncoded.Text.Substring(y, 1) = "0" Then
y = y + 2
strholder2(z) = "s"
End If
Else
If txtEncoded.Text.Substring(y, 1) = "5" Then
y = y + 1
If txtEncoded.Text.Substring(y, 1) = "9" Then
y = y + 2
strholder2(z) = "O"
Else
If txtEncoded.Text.Substring(y, 1) = "8" Then
y = y + 2
strholder2(z) = "o"
End If
End If
End If
End If
End If
Loop
Dim h As Integer
For h = 0 To (z)
strencode2 = strencode2 & strholder2(z)
Next
txtDecoded.Text = strencode2
Label1.Text = y.ToString
End Sub
Now that I took Francis Lord's loop into account I figured out how to get it working so thank you Francis Lord and everyone that gave me feedback..
You'll need to put a condition in your While loop to stop it from incrementing the y past the length of your string. Something like
Do While(y < txtEncode.Text.Lenght)
would do, but I'm not too sure how your code is supposed to work so you might have to adjust the condition to match your logic.
I am trying to create a custom function that basically does this:
The function is in column F and looks at column C to see what the valus is in there.
If it is USA_USD it will display USD in colomn F
If it is Australia_AUD the it will display AUD in colomn F
etc.
Function The_Decider(DealCurrency, X)
If DealCurrency = "USA_USD" Then X = "USD"
Else
If DealCurrency = "Australia_AUD" Then X = "AUD"
Else
If DealCurrency = "Switzerland_CHF" Then X = "CHF"
Else
If DealCurrency = "China_CNY" Then X = "CNY"
Else
If DealCurrency = "EMU_EUR" Then X = "EUR"
Else
If DealCurrency = "Great Britain_GBP" Then X = "GBP"
Else
If DealCurrency = "Hong Kong_HKD" Then X = "HKD"
Else
If DealCurrency = "Japan_JPY" Then X = "JPY"
Else
If DealCurrency = "Korea(South)_KRW" Then X = "KRW"
Else
If DealCurrency = "Viet Nam_VND" Then X = "VND"
End Function
Why I am getting #value in column C?
First of all, you don't actually supply a return value at any point. Also you would probably be better going for a Select Case block for the sake of readability.
You should declare the return type in the function header, then use the same name as the function to return the value in your code:
Function The_Decider(ByVal DealCurrency As String) As String '// <~~ return type
Dim X As String
Select Case DealCurrency
Case "USA_USD": X = "USD"
Case "Australia_AUD": X = "AUD"
Case "Switzerland_CHF": X = "CHF"
Case "China_CNY": X = "CNY"
Case "EMU_EUR": X = "EUR"
Case "Great Britain_GBP": X = "GBP"
Case "Hong Kong_HKD": X = "HKD"
Case "Japan_JPY": X = "JPY"
Case "Korea(South)_KRW": X = "KRW"
Case "Viet Nam_VND": X = "VND"
Case Else: X = "Unknown"
End Select
The_Decider = X '// <~~ the part that actually returns the value
End Function
Although seeing as your input appears to have the currency code in the last 3 letters, I wouldn't even use a UDF. Simply using a worksheet formula would suffice:
=RIGHT(C1,3)
So I'm trying to make a game for our final project (high school) and we've recently swaped over to the new Visual Basic 2010 from VB6. But my question today is, that whever I try to use the KeyDown event and call it from another procedure
KeyValue = _5x5_Board_KeyDown(KeyValue)
It is flagging it up as it doesn't contain the "sender" or "e" that is used for the event to activate. And if I enter those into the call for the program, It says they're not defined. But as far as I'm aware, they are system defined.
Public Class _5x5_Board
Dim xpos As Integer
Dim ypos As Integer
Dim Tile(6, 6) As PictureBox
Dim KeyValue As Integer
Private Sub _5x5_Board_Load(ByVal sender As System.Object)
'Test start position (center of the board)
xpos = 3
ypos = 3
'Assisgning all of the picture boxes to the array
'You can ignore this part...
Tile(0, 1) = Tile0_1
Tile(0, 2) = Tile0_2
Tile(0, 3) = Tile0_3
Tile(0, 4) = Tile0_4
Tile(0, 5) = Tile0_5
Tile(1, 0) = Tile1_0
Tile(1, 1) = Tile1_1
Tile(1, 2) = Tile1_2
Tile(1, 3) = Tile1_3
Tile(1, 4) = Tile1_4
Tile(1, 5) = Tile1_5
Tile(1, 6) = Tile1_6
Tile(2, 0) = Tile2_0
Tile(2, 1) = Tile2_1
Tile(2, 2) = Tile2_2
Tile(2, 3) = Tile2_3
Tile(2, 4) = Tile2_4
Tile(2, 5) = Tile2_5
Tile(2, 6) = Tile2_6
Tile(3, 0) = Tile3_0
Tile(3, 1) = Tile3_1
Tile(3, 2) = Tile3_2
Tile(3, 3) = Tile3_3
Tile(3, 4) = Tile3_4
Tile(3, 5) = Tile3_5
Tile(3, 6) = Tile3_6
Tile(4, 0) = Tile4_0
Tile(4, 1) = Tile4_1
Tile(4, 2) = Tile4_2
Tile(4, 3) = Tile4_3
Tile(4, 4) = Tile4_4
Tile(4, 5) = Tile4_5
Tile(4, 6) = Tile4_6
Tile(5, 0) = Tile5_0
Tile(5, 1) = Tile5_1
Tile(5, 2) = Tile5_2
Tile(5, 3) = Tile5_3
Tile(5, 4) = Tile5_4
Tile(5, 5) = Tile5_5
Tile(5, 6) = Tile5_6
Tile(6, 1) = Tile6_1
Tile(6, 2) = Tile6_2
Tile(6, 3) = Tile6_3
Tile(6, 4) = Tile6_4
Tile(6, 5) = Tile6_5
Call GamePlay(xpos, ypos, KeyValue)
End Sub
Private Sub GamePlay(ByRef xpos As Integer, ByRef ypos As Integer, ByRef KeyValue As Integer)
Do
'Sends for answer of the KeyDown event.
'This is the problem bellow
KeyValue = _5x5_Board_KeyDown(KeyValue)
'Decides the position the tile should move to pased on numeric order
Select Case KeyValue
'Up
Case Is = 1
xpos = xpos - 1
'Right
Case Is = 2
ypos = ypos + 1
'Down
Case Is = 3
xpos = xpos + 1
'Left
Case Is = 4
ypos = ypos - 1
End Select
'Colours in the new square on the board of the designated tile
Tile(xpos, ypos).Load("H:\Computing\Project\TileJump\TileJump\TileJump\Resources\Select1.bmp")
Loop Until Keys.Escape = True
End Sub
Private Function _5x5_Board_KeyDown(ByRef KeyValue As Integer, ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'This is to declare the key pressed to a numeric value that is used to declare the new position
If e.KeyCode = Keys.Up Then
KeyValue = 1
'MsgBox("KeyValue is " & KeyValue)
ElseIf e.KeyCode = Keys.Right Then
KeyValue = 2
'MsgBox("KeyValue is " & KeyValue)
ElseIf e.KeyCode = Keys.Down Then
KeyValue = 3
'MsgBox("KeyValue is " & KeyValue)
ElseIf e.KeyCode = Keys.Left Then
KeyValue = 4
'MsgBox("KeyValue is " & KeyValue)
End If
Return KeyValue
End Function
End Class
The above is my code so far. I hope it helps. It may sound really stupid and bad of me, but i've been stuck on this for almost a month
The KeyDown function accepts three parameters : keyvalue (which you have), sender as object (type of object), e as eventargs (which key you pressed)
However, when you call the keydown function, you are only passing the first parameter: keyValue
Instead Call the GamePlay() from within the keydown function, instead of the other way around, this way it will return with an integer instead of getting complicated with the sender and eventargs