I have a problem with my university project
It's a little game, 6 buttons for each players and 2 players so 12 buttons
There is number in each buttons, if a player has his 6 buttons at 0, he can't play
I have try some Public Function and i'm actually working with a very simple one but i think this is not the problem
My function is here
And in my form, the problem is here, i've tried many things but i don't know how do to that ... I read my lesson and I'm searching on the internet, i have no idea ..
True you don't re-enable the button.
You can simplify things.
Public Function PeutJouer(ByVal joueur As Integer) As Boolean Dim sum As Integer Dim start As Integer = (joueur - 1) * 7 For i As Integer = start To start + 5 sum += tableau(i) Next Return sum <> 0 End Function
Btn1P1.Enabled = PeutJouer(1)
Did you show all the relevant code? You are declaring
Dim tableau(12) As Integer but the array is never filled with values. Probably
tableau should be declared at the form level and not locally in this function. If you already have both, remove the local declaration, because it hides the one at form level. You also need to return the result from the function. I don't see this in your function.
Note that this
If x <> 0 Then booleanVariable = True Else booleanVariable = True End If
can be simplified to
booleanVariable = x <> 0
i.e., the condition is an expression yielding the Boolean result
False already and you can use this value directly. When working with numeric values you don't write
If x + y = 1 Then r = 1 Else If x + y = 2 Then r = 2 .... You simply write
r = x + y.