Can anyone tell me what this code does.

Private Sub MysteryCode_Click(ByVal sender As _
         System.Object, ByVal e As System.EventArgs) _
         Handles MysteryCode.Click

        ' Determines MYSTERVALUE base on number entered by user
        Dim Y As Integer, X As Integer, MYSTERYVALUE As Integer

        ' initialization phase
        X = 1 'prepare to loop
        MYSTERYVALUE = 0 'set MYSTERVALUE To 0

        ' processing phase
        While X <= 10 ' loop 10 times
            Y = X ^ 2 ' X raised to the power of 2
            MYSTERYVALUE = MYSTERYVALUE + Y ' add MYSTERVALUE to Y
            X = X + 1 ' add 1 to X
        End While

        ' display MYSTERYVALUE 
        Text = "Value is " & MYSTERYVALUE
    End Sub

Edited 4 Years Ago by mike_2000_17: Fixed formatting

looks like it should add the squares of the numbers 1 through 10. Should return 385.

as jeff said your code result is 385.
i add message box to show the result. see the red one.

Private Sub MysteryCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MysteryCode.Click
        
        ' Determines MYSTERVALUE base on number entered by user
        Dim Y As Integer, X As Integer, MYSTERYVALUE As Integer

        ' initialization phase
        X = 1 'prepare to loop
        MYSTERYVALUE = 0 'set MYSTERVALUE To 0

        ' processing phase
        While X <= 10 ' loop 10 times
            Y = X ^ 2 ' X raised to the power of 2
            MYSTERYVALUE = MYSTERYVALUE + Y ' add MYSTERVALUE to Y
            X = X + 1 ' add 1 to X
        End While

        ' display MYSTERYVALUE 
        Text = "Value is " & MYSTERYVALUE
        MsgBox(Text)
    End Sub
This article has been dead for over six months. Start a new discussion instead.