开发者

Re-Call a String/Object from previous Sub

Is it possible to recall a string or object that was stored in a previous sub? The below code gives you an idea as to what I am trying to do.

Sub StoreUserData()
Dim StorName as Object
End 

Sub WriteUserFile()
'Recall StorN开发者_运维百科ame here
End Sub


You need to make it into a field:

Dim StorName as Object

Sub StoreUserData()
  'Do stuff with  StoreName
End 

Sub WriteUserFile()
'Recall StorName here
End Sub

If it is declared within a method, it is a local variable and not visible outside the method.

I suggest reading about Scope in Visual Basic.


Local variables are only accessible within their respective code block. To be able to access it you would have to widen its scope like this:

Class MyClass

    Dim storName as Object

    Sub StoreUserData()
        storName = something
    End Sub

    Sub WriteUserFile()
        ' Use storName here
    End Sub

End Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜