Solved

VB code question

Posted on 2011-03-18
7
376 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now