Solved

VB code question

Posted on 2011-03-18
7
379 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Plain Text Editor for iPad 6 75
Trying to write a script in Outlook that forwards emails with a new subject... 29 45
Math Equation 23 83
ASP/VB email question 4 32
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

776 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