Solved

VB code question

Posted on 2011-03-18
7
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Independent Software Vendors: 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

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

740 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