Author Topic: Help With Setting Path  (Read 5886 times)

0 Members and 1 Guest are viewing this topic.

Vince

  • Newt
  • Posts: 55
Help With Setting Path
« on: August 01, 2012, 10:45:53 AM »
Hi Swamp Members,

I am trying to update a path in my VBA code. The current path is set as       Private Const fileX = "c:\Temp\MyFile.txt"     and I would like to change this to be the users Windows System Variable  %tmp%  .

Can anyone help me with this change....??  Your assistance would be appreciated.



Regards,
Vince






BlackBox

  • King Gator
  • Posts: 3770
Re: Help With Setting Path
« Reply #1 on: August 01, 2012, 06:04:39 PM »
Consider the Environ function; pseudo code (untested):

Code - vb.net: [Select]
  1. Private Const fileX = Environ("TMP") & "\" & "MyFile.txt"
  2.  
« Last Edit: August 02, 2012, 12:49:40 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

57gmc

  • Bull Frog
  • Posts: 358
Re: Help With Setting Path
« Reply #2 on: August 01, 2012, 06:25:21 PM »
You can just set your const to that string, but not all folder/path operations will evaluate that string to a valid path. So it depends on what you want to do with that const.

BlackBox

  • King Gator
  • Posts: 3770
Re: Help With Setting Path
« Reply #3 on: August 01, 2012, 06:51:42 PM »
Considering that this is presumably an internal application, where IT has deployed user profiles, it's not far fetched to use the TMP variable path.

If this is a concern, then use a simple FSO test for a valid path during initialization.
"How we think determines what we do, and what we do determines what we get."

Vince

  • Newt
  • Posts: 55
Re: Help With Setting Path
« Reply #4 on: August 02, 2012, 07:45:01 AM »
Basically I would like to save the  MyFile.txt  to the user who is logged on  temp  folder   "C:\Users\Vincent Ferrara\AppData\Local\Temp".

BlackBox

  • King Gator
  • Posts: 3770
Re: Help With Setting Path
« Reply #5 on: August 02, 2012, 09:49:16 AM »
Basically I would like to save the  MyFile.txt  to the user who is logged on  temp  folder   "C:\Users\Vincent Ferrara\AppData\Local\Temp".

Was this post of any help?
"How we think determines what we do, and what we do determines what we get."

Vince

  • Newt
  • Posts: 55
Re: Help With Setting Path
« Reply #6 on: August 02, 2012, 12:32:17 PM »
Hi RenderMan,

I get the following error when I tried your Suggestion:

Code: [Select]
Compile Error:

Method or Data Member Not Found


Regards,
Vince

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Help With Setting Path
« Reply #7 on: August 02, 2012, 12:48:20 PM »
Well, it depends on how you put the information into your app If you copied the information above, you will probably get an error because VBA is trying to interpret MyFile as an object and .txt as a method or property. The filename must be in quotes as well.

Try this ...
Code: [Select]
Private Const fileX = Environ("TMP") & "\MyFile.txt"
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Cathy

  • Guest
Re: Help With Setting Path
« Reply #8 on: August 02, 2012, 04:23:51 PM »
I didn't think you could use a function like Environ() in a constant.  Wouldn't you need to dim fileX as a string instead? 

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Help With Setting Path
« Reply #9 on: August 02, 2012, 04:31:33 PM »
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

BlackBox

  • King Gator
  • Posts: 3770
Re: Help With Setting Path
« Reply #10 on: August 02, 2012, 04:33:09 PM »
Not a VBA guy myself, I found Environ() in a Google search actually, so you may be correct.

Perhaps instead of declaring 'fileX' as a constant, it may be prudent to have a GetFilePath(FileName As String) Function, that is supplied the "MyFile.txt" file name, and Returns the "TMP" path & FileName string.

Just a thought.
"How we think determines what we do, and what we do determines what we get."

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Help With Setting Path
« Reply #11 on: August 02, 2012, 07:04:05 PM »
Ah, I didn't see it before .. the problem may be multiple things happening.

1) You cannot have a Private Const inside a declared function
2) You can't assign a value to a Private Const that uses the result of a function
3) You can't declare a variable and also assign a value to it in the same line in VBA like you can in VB6 and VB.Net

So ..
This works when used inside a function ...

Code: [Select]
    Dim FileX As String
    FileX = Environ("tmp") & "\MyFile.txt"

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie