Answered MSGBOX loop

PRo-Beaniie

Well-known member
Joined
Mar 17, 2011
Messages
55
Location
Hertford, Hertfordshire, United Kingdom
Programming Experience
3-5
Hey Guys,

Im still fairly new to VB and i have a problem with a msgbox loop in my form it bugging me as i was in college earlier trying to figure it out my friend had the same problem too but he managed to fix his loop .... i however was not so fortunate... its probably a stupid mistake somwhere but mabye you guys could help me spot it ... this is were i think the error lies...:confused:

VB.NET:
    Private Sub CheckHit()
        For Me.x = 1 To NumOfEnemy
            'Timer Main Collision Code ...
            If (Missile.Top + Missile.Height >= Enemy(x).Top) And (Missile.Top <= Enemy(x).Top + Enemy(x).Height) And (Missile.Left + Missile.Width >= Enemy(x).Left) And (Missile.Left <= Enemy(x).Left + Enemy(x).Width) And Enemy(x).Visible = True Then
                Enemy(x).Visible = False
                Enemy(x).Left = -100
                Missile.Visible = False
                ShotDown += 1
        Missile.Top = -100
        ScoreBoard.Text = ScoreBoard.Text + 25
        Enemy(x).Visible = True
        EnemySpeed = EnemySpeed + 0.5
            End If
        Next
        'ScoreBoard Variables ...
        If ScoreBoard.Text = 100 Then
            TimerMain.Enabled = False
            GameTimer.Enabled = False
            MsgBox(" Nice One you kicked thier ass! ")
        End If
    End Sub
 
Last edited:
I cannot tell for sure without knowing what's going wrong, but my bet is it's with this line.
VB.NET:
ScoreBoard.Text = ScoreBoard.Text + 25
Remember that scoreboard is a text box and scoreboard.text is a text string. 25 + 25 is 2525 if you're dealing with strings!
Either use
VB.NET:
Scoreboard.text = val(Scoreboard.text) + 25
or much better declare a new integer variable to keep the score rather than using the string in the first place.

VB.NET:
Dim Score as Integer
...
Score = Score + 25
Scorebox.text = Score
 

Latest posts

Back
Top