|
Answer» So I am trying to rewrite one of my batch scripts in vbs to learn, and I have run into a problem. I don't know how to write this section in a different color (other than black). I tried wscript.font.color(0,255,0) which I found somewhere, but It didn't work. Any advice would be great.
Code: [Select]dim m(2),TODAY,dow,wim,mNAME,Mend(2),Dayy dim cd cd = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
today=day(date) dayy=day(date) m(0)=month(date)-1 m(1)=month(date) m(2)=month(date)+1 mNAME=MonthName(m(1)) dow=weekday(date)
if m(0) = 1 then Mend(0)=31 if m(0) = 2 then Mend(0)=28 if m(0) = 3 then Mend(0)=31 if m(0) = 4 then Mend(0)=30 if m(0) = 5 then Mend(0)=31 if m(0) = 6 then Mend(0)=30 if m(0) = 7 then Mend(0)=31 if m(0) = 8 then Mend(0)=31 if m(0) = 9 then Mend(0)=30 if m(0) = 10 then Mend(0)=31 if m(0) = 11 then Mend(0)=30 if m(0) = 12 then Mend(0)=31
if m(2) = 1 then Mend(2)=31 if m(2) = 2 then Mend(2)=28 if m(2) = 3 then Mend(2)=31 if m(2) = 4 then Mend(2)=30 if m(2) = 5 then Mend(2)=31 if m(2) = 6 then Mend(2)=30 if m(2) = 7 then Mend(2)=31 if m(2) = 8 then Mend(2)=31 if m(2) = 9 then Mend(2)=30 if m(2) = 10 then Mend(2)=31 if m(2) = 11 then Mend(2)=30 if m(2) = 12 then Mend(2)=31
Do Until dayy=1 If dow = 1 Then Do Until dow=1 dayy=dayy-1 dow=dow-1 Loop Else dayy=dayy-1 dow=7 End If Loop
Do Until dayy=Mend ' Read File h.txt To Find Holiday Date Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(cd & "\h.txt", 1) dim working Do Until objFile.AtEndOfStream working = objFile.ReadLine a = Split("" & working & "", ":",-1,1) wscript.echo(a(0) & "," & a(1) & "," & a(2)) '* This is the LINE I want to color. Loop objFile.Close ' READ.END
'''MORE CODE TO COME''' Loop You cannot colorize the console with native VBScript code. A messy workaround would be to launch your VBScript from a batch file and use the color command to colorize the console WINDOW. Only scripts using the CScript engine have access to the console (STDIN, STDERR, STDOUT).
If you have any of the Microsoft Office programs installed, you can put your output in say, an Excel worksheet or a Word document where you can change fonts and colors using the Excel or Word builtin methods and/or properties.
HTML Applications (VBScript wrapped with HTML) would work but they are designed to create their own window where your output would go. HTML Applications (HTA file extension) have no access to the console.
If you have the time and the patience, you can use Powershell. The Write-Host cmdlet (used for output to the console) has both foreground and BACKGROUND color parameters.
|