0

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 by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Jx_Man
0

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.