表紙へ

VB.NET

呼び出し元プロシージャ名を取得する

 

Public Function MyFunction() As String

    MsgBox(New StackFrame(1).GetMethod.Name)

End Function

1 の部分を 2 にすると、呼び出しもとの呼び出し元が取得できる。このように呼び出し履歴を遡る(さかのぼる)ことが出来る。

 

実際に試せる例

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Call MyFunction()

End Sub

Public Function MyFunction() As String

    MsgBox(New StackFrame(1).GetMethod.Name)

End Function

この例を実行すると「Button1_Click」と表示される。

 

 


VB6には同じ機能は用意されていません。