How to save file in vbscript with previous date - vbscript

I am trying to save excel file with previous date in vbscript.
Fill has been save but date format not like 5-Jun-2019.
Please help me..
MyDateFormat = Year(now) & Right("0" & Month(Now), 2) & Right("0" & Day(now)-1, 2)
wbm.SaveAs "C:\report " & MyDateFormat & ".xlsx"
Expected Actual Result like:5-Jun-2019

date-1 gives yesterday "05.06.2019" in my case, this will not let you encounter day = 00, rest should be done by formatting

Related

SSRS: Month Date Expression in Header Text Box

I have the following Expression in the Header of a report and while the report is working fine, the expression returns #ERROR... 'Argument Month is not a valid value.'
= IIF
(
Month(Today) = 1,
"December, " & Year(Today) -1,
MonthName(Month(Today) -1) & ", " & Year(Today)
)
In January, I want the Text Box to display "December" & the Previous Year.
For all other months, I want to display the current Month Name and the current Year.
I would appreciate any help or pointers.
Thanks!!
I probably should have worked harder before posting my question but it was urgent and I wasn't sure I'd be able to find an answer.
This is how I was able to solve the problem:
= IIF
(
Month(Today) = 1,
MonthName(Month(DateAdd("M",-1,Today))) & " " & Today.AddYears(-1).Year,
MonthName(Month(DateAdd("M",-1,Today))) & " " & Today.AddYears(0).Year
)
Thanks!
You were close, I think this should work
=IIF(Month(Today) = 1, "December, " & Year(Today) -1, MonthName(Month(Today)) & ", " & Year(Today))

Label Expression Frustration

I have a two label fields, [field1] & [field2] I want to display on my map.
I want them to be on two separate lines with the bottom one in bold and in a different color and adding mg/L after the value. The bottom label also needs to all fit on one line despite it being too long, arcmap is currently separating them. I have only written this much:
"" & [field1] & "" & vbnewline & "" & FormatNumber(Round( [field2] , 0),0) & " mg/L" & ""
When I add more I cant seem to get it right and lots of errors come up.
Sorry for late reply, Try to put your field2 text in these tags in label expression it will change the color and will bold your text
"<BOL>"& "<CLR red= '100'>" & [field2] & "</CLR>"&"</BOL>"
something like:
"" & [field1] & "" & vbnewline & "<BOL>"&"<CLR red= '100'>" & FormatNumber(Round( [field2] , 0),0) & " mg/L" & "</CLR>"&"</BOL>"

Having the day value of date start with 0

I am editing a VBScript so it will take yesterdays date add a string to the front off it and search for that file before moving it to a folder.
sDate = day(date)-1
sName= "Blaa" & "_" & sDate
Using the above bits of code I would get a result - Blaa_10 or Blaa_9
The issue is the files, I want it to search for when under 10 would be named as Blaa_09.
Is there anyway I can format the value day so when it is under 10 it starts with 0? Think I could write an If statement to do this but was hoping there is another way.
The canonical way to left-pad a day of month with a zero in VBScript looks like this:
Right("0" & Day(Date), 2)
Just went with
sDay = day(date) -1
IF sDay < 10 Then
sDate = "0"& sDay & monthname(month(DateAdd("m",-1,Date)), True) & year(date)
WScript.Echo "Date = " & sDate
This worked fine, if anyone has an easier way please feel free to share.

Time in 24 hour format in VBScript

I am trying to get the system time in 24 hour format using VBScript. I had gone through the documents and found nothing. I need to compare the system date and time with my data and need to check the differences.
WScript.Echo right("0" & hour(time),2) & ":" & right("0" & minute(time),2)
WScript.Echo FormatDateTime(time, vbShortTime)
VBScript's Date datatype is format-agnostic. You can calculate the difference between the system time and some other timestamp using the DateDiff function, as long as VBScript recognizes the format of the other timestamp. Example (calculating the difference in seconds):
>>> systime = Now
>>> WScript.Echo systime
26.11.2013 12:48:52
>>> WScript.Echo DateDiff("s", systime, "11/25/2013 23:16:52")
-48720
>>> WScript.Echo DateDiff("s", systime, "25.11.2013 23:16:52")
-48720

VB6 comma separating CSV file

I am trying to separate a comma delimited file and for some reason I seem to not be getting the output that I was expecting to get.
Here is the code:
strCSVPath = "E:\cfaApp\tester.csv"
int77 = FreeFile
Open strCSVPath For Input As #int77
Do Until EOF(int77)
Input #int77, strName, intHours, strMon, strTue, strWed, strThu, strFri, strSat
Debug.Print strName & vbCr & intHours
'Debug.Print strName & vbCr & intHours & vbCr & strMon & vbCr & strTue & vbCr & strWed & vbCr & strThu & vbCr & strFri & vbCr & strSat & vbCr
Loop
The output looks like this:
1.0-Store Manager (1 Employee)
11:00 AM-8:30 PM
10:00 AM-7:30 PM
1.1-Assistant Managers
Wood, Chris
Above output is wrong. This is the CSV file (some of it, not all of it)
1.0-Store Manager (1 Employee),,,,,,,,
"Pro, Bob",1.0-Store Manager,47.5,5:30 AM-3:00 PM,5:30 AM-3:00 PM,11:00 AM-8:30 PM,11:00 AM-8:30 PM,9:00 AM-6:30 PM,OFF
1.1-Assistant Managers (3 Employees),,,,,,,,
"Crow, Billy",1.1-Assistant Managers,47.5,10:00 AM-7:30 PM,5:30 AM-3:00 PM,5:30 AM-3:00 PM,5:30 AM-3:00 PM,OFF,11:00 AM-8:30 PM
"Ras, Pat",1.1-Assistant Managers,47.5,5:30 AM-3:00 PM,9:00 AM-6:30 PM,10:00 AM-7:30 PM,,11:00 AM-8:30 PM,9:00 AM-6:30 PM
"Wood, Chris",1.1-Assistant Managers,47.5,,11:00 AM-8:00 PM,8:30 AM-6:30 PM,10:00 AM-7:30 PM,5:30 AM-3:00 PM,5:30 AM-3:00 PM
1.2- Supervisors (7 Employees),,,,,,,,
As you can see, the output does skips Pro, Bob altogether. And then skips Crow and Ras before displaying Wood.
I also get an error of
Input past end of file
In short, Input # is not designed to read CSV. See http://msdn.microsoft.com/en-us/library/aa243386(v=VS.60).aspx
There may be an external CSV parser you could use from VB6 but I don't know of one offhand. You could write a CSV parser fairly easily that gets one character at a time and uses a finite state machine.
It's been a while since I have used VB6, but I happened to remember that it is possible to use the ADODB.Recordset object to query the CSV file like a SQL database.
Here is Microsoft documentation, including how to read CSV files without header rows.
Try using a other separator like ; or Pipe.
Then see if the output is okay.
If YES try to quote the commas in the name or set the name in other quotes like '
Have Fun,
John

Resources