Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No score being updated...

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Dear All,
Thanks for a brilliant forum!

I have the following problem...
I am creating a little fun learning exercise...
It is battleships.
I have a form, called BattleArray

The form has about 64 txtfields bound to a table Player1

The txt fields are not named exactly after the table of fields.
The txt boxes have the following naming conventions.

P1a1 to P1a8 (e.g. Pla1, Pla2, Pla3 etc.)

Right now I am consentrating on getting the above working.

I have buttons next to my gridd of txtBoxes.

Labled A1, A2, A3, A4, A5 etc. till A8 for the first row.

I have a field in the table Player1 called Score.

I also have an unbound txtbox called Play1Score

What I want to happen is when the Button A1 for instance is clicked for it to check whether the txtbox P2a1 is null or has a 1 in it, then if it has a 1 to change that 1 to HIT.

I then want the clicked button to calculate the new score if a HIT happens, by going through row A1 to 8, check if it has any HIT in it. and then per hit adding a 1 to the score.

Code I have come up with is below.
BUTTON CODE
Code:
[blue]Private Sub[/blue] P1a1Button_Click()
[blue]On Error GoTo[/blue] Err_P1a1Button_Click

[blue]Dim[/blue] i [blue]As Integer[/blue]
    i = 0
    
    [blue]If[/blue] IsNull(P2a1) [blue]Then[/blue]
        MsgBox "MISS!", vbInformation, "MISS!"
        txtInvisi.SetFocus
        P1a1Button.ForeColor = RGB(0, 0, 255)
        
    [blue]ElseIf[/blue] P2a1 = "1" [blue]Then[/blue]
        MsgBox "HIT!", vbExclamation, "HIT!"
        txtInvisi.SetFocus
        P1a1Button.ForeColor = RGB(255, 0, 0)
        Me.P2a1 = "HIT"
        Me.Play1Score = Player1Score(Pl1Score)
    [blue]End If[/blue]
    
      
 
Exit_P1a1Button_Click:
    [blue]Exit Sub[/blue]

Err_P1a1Button_Click:
    MsgBox Err.Description
    [blue]Resume[/blue] Exit_P1a1Button_Click
    
[blue]End Sub[/blue]

Code:
[blue]Private Function[/blue] Player1Score(Pl1Score)
[green]'function Player1Score begin[/green]
[blue]Dim[/blue] i [blue]As Integer[/blue]
        i = 1
[green]'Player1.Score = Pl1Score[/green]
Me.Play1Score = Pl1Score
Pl1Score = 0
    
    [blue]For[/blue] i = 1 [blue]To[/blue] 8
    
        [blue]Select Case[/blue] P2ai
    
        [blue]Case[/blue] P2ai = "HIT"
        Pl1Score = Pl1Score + 1
        [blue]End Select[/blue]
    
    [blue]Next[/blue] i
    

[blue]End Function[/blue]

It does not seem to add the score into Play1Score on the FORM...
I am a complete noob at functions, so I don't know if and how to pull the right values into the button code..
Please help!
Thanks

Thank you,

Kind regards

Triacona
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top