How can I clean the buffer from the folder picker?

E

Excel 009

What I meant
program = Subs
workbook = Excel file

When the program finishs, a public variable will be terminated, but I
want to know if there is a way to keep it still alive.

Here is an example:

Say this is the only code in my module in the whole project.

Public strX as String

Function getString(str as String) as String
strX = str
getString = strX
End Function

Sub x()
Msgbox getString
End Sub

After I ran Sub x(), the

The message came up and after I click Ok, the program terminated. stX
is lost.
I want to know if there is a way to keep it still alive (not store it
physically some where, but only in memory).
 
N

NickHK

Change your code slightly yo that below. Then call it repaeted from the
button click. The value of the variable is retianed.
I just thought; you're not using End anywhere in your code are you ? Because
that clear all variables.

NickHK

'<Worksheet code>
Private Sub CommandButton3_Click()
Call x
End Sub
'</Worksheet code>

'< Module code>
Public strX As String

Sub x()
If Len(strX) = 0 Then
MsgBox getString("New Value")
Else
MsgBox "the value of strX is " & Chr(34) & strX & Chr(34)
End If
End Sub

Function getString(str As String) As String
strX = str
getString = strX
End Function
'</ Module code>

NickHK
 
E

Excel 009

Thanks, Nick. What I need to know is a way to retain the StrX value
after all the subs finished running.

For example, I created

Sub y()
MsgBox strX
End Sub

in additional to your code. When I clicked the button, the message
comes up with the StrX value. After I clicked "OK" on the message box,
the sub finishs.

Now I run Sub Y. The message is blank because the StrX value is not
retained. In the situation where the Folder Picker is used, the value
is still there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top