Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default How can I clean the buffer from the folder picker?

I am using the folder picker code from John Walken's site. I have a
Sub that brings up the folder picker dialog box. I assigned a string
variable to the selected folder name. After I ran the code, select the
folder and click Ok, the folder value is stored in the string variable.
When I ran the code again (after some procedures took place), before I
selected the folder, the string variable still had the value from the
prior selection. Does any one know how to get ride of the buffered
value without setting the string variable to a blank value. Just
curiours.

- Excel 009

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default How can I clean the buffer from the folder picker?

Did you declare the variable locally or globally? A local variable s/b
destroyed when the sub terminates, global will not (which is a the primary
reason for using it). One other means to make a local variable retain it's
value after the sub terminates is to declare the variable as static (just an
FYI - I doubt that is the case).

Global:
Dim x As String
Sub Test
...
End Sub

Local
Sub Test
Dim x As String
...
End Sub

Static:
Sub Test
Static x As String
....
End Sub

"Excel 009" wrote:

I am using the folder picker code from John Walken's site. I have a
Sub that brings up the folder picker dialog box. I assigned a string
variable to the selected folder name. After I ran the code, select the
folder and click Ok, the folder value is stored in the string variable.
When I ran the code again (after some procedures took place), before I
selected the folder, the string variable still had the value from the
prior selection. Does any one know how to get ride of the buffered
value without setting the string variable to a blank value. Just
curiours.

- Excel 009


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default How can I clean the buffer from the folder picker?

Funny thing is the value of the variable was still there after the sub
is terminated.

Put the code into a module (code can be found in this link)
http://j-walk.com/ss/excel/tips/tip29.htm

assign the folder value to strX

call up the dialog box and select a folder and click Ok.

Type the following into your model.

Sub Test()
MsgBox strX
End Sub

run the sub, and strX still shows up!

I guess it may have something to do with the API, but not quite sure.
If anyone has the answer, please share.

- Excel 009

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How can I clean the buffer from the folder picker?

If you declared strX at the top of the module above an procedures, then it
is a public variabe or module level variable and will retain its value. If
instead, you declare inside the procedure, then the next time the procedure
is run it will have lost its value.

Other that, we would have to see the specific code you are running. I have
run John's code many times in the past and have had no problems or
surprises. It acted as I suspected.

--
Regards,
Tom Ogilvy


"Excel 009" wrote in message
oups.com...
Funny thing is the value of the variable was still there after the sub
is terminated.

Put the code into a module (code can be found in this link)
http://j-walk.com/ss/excel/tips/tip29.htm

assign the folder value to strX

call up the dialog box and select a folder and click Ok.

Type the following into your model.

Sub Test()
MsgBox strX
End Sub

run the sub, and strX still shows up!

I guess it may have something to do with the API, but not quite sure.
If anyone has the answer, please share.

- Excel 009



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default How can I clean the buffer from the folder picker?

The variable IS a public variable, but what I am curious to know is
that when will this variable be destroyed? It seems like once I
assigned value to the variable, it is there even after I run many Sub
manually. When I call up the folder picker dialog box the second time,
if I click Ok without selecting a folder, the old value shows up. I
cleared the clipboard, and it is still there.

(There is nothing wrong with John's code. I appreciate his sharing.)



  #6   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default How can I clean the buffer from the folder picker?

I've also used that code from John's site w/o any surprises. John's macro,
however, does not store the return value into a variable, it only displays a
message box

Sub Test()
Dim Msg As String
Msg = "Please select a location for the backup."
MsgBox GetDirectory(Msg)
End Sub

whereas you are assigning it to the variable strx. The issue, I'm sure, is
not w/John's code or the API, but how you declared strx - Procedure Level or
Module Level? (inside of your sub or outside of your sub - see my first post
for examples).


"Excel 009" wrote:

Funny thing is the value of the variable was still there after the sub
is terminated.

Put the code into a module (code can be found in this link)
http://j-walk.com/ss/excel/tips/tip29.htm

assign the folder value to strX

call up the dialog box and select a folder and click Ok.

Type the following into your model.

Sub Test()
MsgBox strX
End Sub

run the sub, and strX still shows up!

I guess it may have something to do with the API, but not quite sure.
If anyone has the answer, please share.

- Excel 009


  #7   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default How can I clean the buffer from the folder picker?

Hit the post button a little to quick, I wanted to add another example. Try
this

Sub Test()
Dim Msg As String
Dim strX As String
Msg = "Please select a location for the backup."
MsgBox strX
strX = GetDirectory(Msg)
MsgBox strX
End Sub



"JMB" wrote:

I've also used that code from John's site w/o any surprises. John's macro,
however, does not store the return value into a variable, it only displays a
message box

Sub Test()
Dim Msg As String
Msg = "Please select a location for the backup."
MsgBox GetDirectory(Msg)
End Sub

whereas you are assigning it to the variable strx. The issue, I'm sure, is
not w/John's code or the API, but how you declared strx - Procedure Level or
Module Level? (inside of your sub or outside of your sub - see my first post
for examples).


"Excel 009" wrote:

Funny thing is the value of the variable was still there after the sub
is terminated.

Put the code into a module (code can be found in this link)
http://j-walk.com/ss/excel/tips/tip29.htm

assign the folder value to strX

call up the dialog box and select a folder and click Ok.

Type the following into your model.

Sub Test()
MsgBox strX
End Sub

run the sub, and strX still shows up!

I guess it may have something to do with the API, but not quite sure.
If anyone has the answer, please share.

- Excel 009


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default How can I clean the buffer from the folder picker?

Thanks J.

This is the format I have:

Book1
===================
Dim strX As String

Sub Test()
strX = GetDirectory(Msg)
End Sub


Sub Test_2()
MsgBox strX
End Sub
===================

Book2
===================
Sub Text _3()
Msgbox "Hi"
End Sub

After I ran Test(), I ran Sub Text _3() in workbook 2, then I came back
to workbook 1, ran Sub Test_2(), and the value stored in StrX is still
there. May be my real question is - how the value is preserved in a
way that when you leave the current workbook and come back, it is still
in the memory?

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default How can I clean the buffer from the folder picker?

Thanks J.

This is the format I have:

Book1
===================
Dim strX As String

Sub Test()
strX = GetDirectory(Msg)
End Sub


Sub Test_2()
MsgBox strX
End Sub
===================

Book2
===================
Sub Text _3()
Msgbox "Hi"
End Sub

After I ran Test(), I ran Sub Text _3() in workbook 2, then I came back
to workbook 1, ran Sub Test_2(), and the value stored in StrX is still
there. May be my real question is - how the value is preserved in a
way that when you leave the current workbook and come back, it is still
in the memory?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Keyboard Buffer ? Gary''s Student Excel Programming 2 September 7th 06 03:42 AM
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
buffer overflow Jeff Sward Excel Programming 0 January 7th 04 07:46 PM
Folder picker default - second attempt... pk Excel Programming 4 October 13th 03 05:42 PM
Folder picker: default to network share? pk Excel Programming 0 October 11th 03 04:48 PM


All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"