Search code examples
excelcatiavba

declaring and initializing global variables


I have this userform with two buttons , one saying "next" and other saying "start" . Apart from this there exists a module of name "module1" containing the whole operation code. the idea is that clicking start initializes a variable "angle" as 0 and for every click of "next" , the value of angle increases by 1 and the module1 is called. but the value of angle doesn't increase , here is my code

1: code for start

Public angle As Integer

    Private Sub Start_Click()
    angle = angle+1
End Sub

2 : code for next

Private Sub Next_Click()
    Module1.CATMain (angle)
    angle= angle + 1
End Sub

3 : code for module 1

Sub CATMain(ByVal angle As Integer)
    '* code*
End sub

Where am i going wrong , the value of angle doesn't get incremented and the module is being called with same value every time . thanks in advance


Solution

  • I got this code (without the "Module1."). Works with Excel 2010. All code is in Module1.

    Public angle As Integer
    
    Private Sub Start_Click()
         angle = angle + 1
    End Sub
    
    Private Sub Next_Click()
        CATMain (angle)
        angle = angle + 1
    End Sub
    
    Sub CATMain(ByVal angle As Integer)
        MsgBox (angle)
    End Sub
    

    Edit: The code didn't work if any part is in the worksheet section.