Solved

VB code question

Posted on 2011-03-18
7
388 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
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

691 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