Ok so I am creating this scoring game using motorsport drivers.

The scores are in variables for example score.vettel is vettels score for the current gameweek.

A player has 6 drivers d1,d2,d3,d4,d5,d6 which are in the variable player(x).d1 where x is the player number. Maxsize is the number of players I have (so it loops from the first user to the last)

For x = 1 To Maxsize
If player(x).d1 = "VETTEL"
Then player(x).score = player(x).score + score.vettel
End If
Next

Of course I would have to do this loop for all drivers in all driver slots (d1,d2,d3,d4...)

For x = 1 To Maxsize
If player(x).d2 = "VETTEL"
Then player(x).score = player(x).score + score.vettel
End If
Next

Is there any way to make it so that I do not have to write all of this code but shorten it to something like:

For x = 1 To Maxsize
If player(x).d1 - player(x).d6 = "VETTEL"
Then player(x).score = player(x).score + score.vettel
End If
Next

Many thanks

Maybe you could use an arraylist (drivers in the example below) instead of 6 different variables (d1 - d6). Then you could do something like this.

If player(x).drivers.Contains("VETTEL") Then
  player(x).score += score.vettel
End If
commented: quite helpful:) +12

Sorry I didn't realise I made this post. Thanks anyway, its works well. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.