Solved

VB code question

Posted on 2011-03-18
7
381 Views
Last Modified: 2012-05-11
My OS is windows 7 and I use Outlook 2007.
in a macro I have the following code :
Const st_TEMPFILE As String = "C:\MyBlockList.txt"
I would like the "MyBlockList" to also have a date and time imprint to it.
How does one assign a date and time to a string, and then concaternate it with MyBlocklist.
OR just one string with file name _ date + time.
Thank u.
0
Comment
Question by:jegajothy
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:GundogTrainer
ID: 35165077
you can use now()
edpending on your date format that will retuen smething like:
18/03/2011 12:49:54

if you use replace for the /  and : like this
 replace(replace(now(),"/","-"),":"," ")
18-03-2011 12 50 56
so you could then use
Const st_TEMPFILE = & "C:\MyBlockList " & replace(replace(now(),"/","-"),":"," ") & ".txt"

0
 

Author Comment

by:jegajothy
ID: 35167491
in response to GundogTrainer, I get a compile error for replace(etc etc)
How do I fix this.  
I tried the following syntax, but got a compile error for Now
Const st_TEMPFILE As String = "C:\MyBlockList " & Now() & ".txt"
I am no vb expert, so hope u could fix this for me. thanks.
0
 
LVL 8

Expert Comment

by:GundogTrainer
ID: 35168804
Could you confirm what flavor of vb you are using please,
I assumed this was in a stand alone vbs script but the syntax is different if its in say an excel vba macro. Or vb2008 Etc.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jegajothy
ID: 35168955
in response to FundogTrainer, I am using the vb script in Microsoft Outlook 2007.
0
 
LVL 8

Accepted Solution

by:
GundogTrainer earned 500 total points
ID: 35169479
Can you try the following code please, in VBA (Visual Basic for Applications) it is slightly different than clasic VBScript - but no great issue. I have not used the CONST declaration as you can not modify a constant once it has been created.

strLogfile = "C:\MyBlockList_ "
strLogfile = strLogfile & datetime.date$ & "_"
strLogfile = strLogfile & replace(datetime.time$,":","-")
strLogfile = strLogfile & ".txt"
msgbox strLogfile

0
 

Author Comment

by:jegajothy
ID: 35169761
To Gundog Trainer, your code worked,.  A very big thank u.  U are a genius, thanks again.
0
 

Author Closing Comment

by:jegajothy
ID: 35183309
your code worked, thank u.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question