R
Rob W
Greetings,
I have a structure as follows:-
Structure Player 'Structure for a player Symbol and
name
Dim Symbol As Char
Dim Name As String
End Structure
Dim Players(1) As Player 'Array for TWO structured player elements
It will only ever as the array is dimensioned hold TWO values, for my
functions I have been passing in an integer variable to select either item 0
or 1.
An example of a function below:-
Function SwapPlayer(ByVal playerTurn As Integer)
'Swap players turn
If playerTurn = 0 Then
playerTurn = 1
Else
playerTurn = 0
End If
'Print whos turn it is
Me.Text = "Your turn " & Players(playerTurn).Name & "(" &
Players(playerTurn).Symbol & ")"
Return playerTurn
End Function
This works fine, however I was recommended to use a Boolean as it will be
more efficient as there will only ever be TWO values, unfortunately a
Boolean is true/false or -1/0 and not 0/1 which would be ideal to access the
array items.
Can anyone suggest the cleanest method to have a Boolean variable used to
pass in a value of 0 or 1 to my functions to select the appropriate array
Item (perhaps a method in the structure)?
I was recommended to use it for simplicity but the only way I can think of
using it relies on conversions and I'm not sure if I would be over
complicating matters.
Thanks
Rob
I have a structure as follows:-
Structure Player 'Structure for a player Symbol and
name
Dim Symbol As Char
Dim Name As String
End Structure
Dim Players(1) As Player 'Array for TWO structured player elements
It will only ever as the array is dimensioned hold TWO values, for my
functions I have been passing in an integer variable to select either item 0
or 1.
An example of a function below:-
Function SwapPlayer(ByVal playerTurn As Integer)
'Swap players turn
If playerTurn = 0 Then
playerTurn = 1
Else
playerTurn = 0
End If
'Print whos turn it is
Me.Text = "Your turn " & Players(playerTurn).Name & "(" &
Players(playerTurn).Symbol & ")"
Return playerTurn
End Function
This works fine, however I was recommended to use a Boolean as it will be
more efficient as there will only ever be TWO values, unfortunately a
Boolean is true/false or -1/0 and not 0/1 which would be ideal to access the
array items.
Can anyone suggest the cleanest method to have a Boolean variable used to
pass in a value of 0 or 1 to my functions to select the appropriate array
Item (perhaps a method in the structure)?
I was recommended to use it for simplicity but the only way I can think of
using it relies on conversions and I'm not sure if I would be over
complicating matters.
Thanks
Rob