VBScript in IBM Personal Communications, Register current date and time - date

This is a bit complicated to explain but I sure will do my best!
I want to register the current time and date "Year,Week,day + Time", in my program IBM Personal Communications (Session A). I have to use a .MAC extension for the final file in order for the program to read it.
This is the code that I have at the moment:
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
REM This line calls the macro subroutine
subSub1_
sub subSub1_()
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "151441652 " **<--This is where the date has to appear**
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
autECLSession.autECLPS.WaitForAttrib 12,1,"00","3c",3,10000
autECLSession.autECLPS.Wait 3401
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[pf12]"
end sub
autECLSession.autECLPS.SendKeys "151441652 " <--- The final values must appear here in the same order. The numbers have been entered manually by me. So what I essentially need the final program to do is to recognize the date and enter them manually.
This is what the numbers stand for:
15 = The year 2015
14 = The current week, the date right now is 02-04-2015 which is Week 14
4 = Day 4 of the week. thursday
1652 = Current time, I need the time to be a 24hour clock.

DatePart() can do all of this.
autECLSession.autECLPS.SendKeys _
Right(DatePart("yyyy", Now()), 2) & _
Right("0" & DatePart("ww", Now()), 2) & _
DatePart("w", Now()) & _
Right("0" & DatePart("h", Now()), 2) & _
Right("0" & DatePart("n", Now()), 2)
Take note of the optional FirstDayOfWeek and FirstWeekOfYear parameters, test your edge cases and set those parameters accordingly for the relevant calls.

Related

How can I enter and exit a trade at a given time?

I am trying to backtest a strategy in Tradingview on an hourly chart that goes short AUDJPY at 5am Japan time and exits with a market order at 7am on the same day. I am using the hour(time) function and the IANA timezone 'Asia/Tokyo'.
Below is the code. I verified that the variable hr picks up the right hour by plotting it in the chart. But when I run the Strategy Tester the result is "No Data" and no trades appear on the screen after I apply "Add to chart" to the script.
strategy("Foreign JPY", overlay=true, currency = currency.USD)
hr = hour(time, "Asia/Tokyo")
shortCondition = hr == 5
if (shortCondition)
strategy.entry("short", strategy.short, 100000)
exitCondition = hr == 7 and strategy.position_size < 0
if (exitCondition)
strategy.close("exit", 100000)
The exit condition in your example is executed only for entries with an "exit" id=. If you want to point to the existing short order, use its id= in the strategy.close() parameter:
if (exitCondition)
strategy.close("short", 100000)

Calculation of the number of microseconds in Ada

in C langage we have get_usec() which gives us the number of microseconds since the start of the current second.
-Speaking of the "current second" necessarily refers to time reference which is often EpochTime.
-In Ada.Calendar package, I see Seconds or Clocks functions by example with ability to split & get the seconds.
But how to get the number of microseconds since the start of the current second, please?
Thanks
Mark
Note that Ada.Calendar is for local time, and may jump backwards. If it's available (are there any post-83 compilers that don't provide it?), you'll be better off using Ada.Real_Time ARM D.8:
Now : constant Ada.Real_Time.Time := Ada.Real_Time.Clock;
Count : Ada.Real_Time.Seconds_Count;
Sub : Ada.Real_Time.Time_Span;
...
Ada.Real_Time.Split (T => Now, SC => Count, TS => Sub);
Now Count contains the number of whole seconds since the epoch and Sub contains the fraction of a second in addition to Count. Ada.Real_Time.To_Duration converts a Time_Span to Duration, allowing you to multiply it by 1E6 to get microseconds.
The packages Ada.Calendar and Ada.Calendar.Formatting provide the information you will need.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Calendar.Formatting; use Ada.Calendar.Formatting;
procedure Main is
Now : Time := Clock;
Seconds : Second_Duration := Sub_Second (Now);
begin
Put_Line
("Sub seconds since current second: " &
Second_Duration'Image (Seconds));
end Main;
The output of one execution of this program is:
Sub seconds since current second: 0.655316600
In this execution the value indicated 655316.6 microseconds.
It can also be done (of course) without Ada.Calendar.Formatting, like this for example:
with Ada.Calendar; use Ada.Calendar;
...
type Seconds_In_Day is range 0 .. 86_400;
-- Or use Integer if it is 32 bits.
Now : constant Day_Duration := Seconds (Clock);
Subsec : Duration := Now - Day_Duration (Seconds_In_Day (Now));
...
if Subsec < 0.0 then
-- Conversion of Now rounded up instead of down.
Subsec := Subsec + 1.0;
end if;
with the result in Subsec.
But using Ada.Calendar.Formatting.Sub_Second is shorter, and may be better (faster or more accurate) for all I know; I did not compare the two methods.
Many thaks for yours answers.
Using all yours examples, i made some trials, one is below :
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Ada.Real_Time; use Ada.Real_Time;
procedure Display_Current_Year is
--need to precise the origin package Ada.Real-Time else ambiguous
Now : Ada.Calendar.Time := Clock;
Now_Year : Year_Number;
Now_Month : Month_Number;
Now_Day : Day_Number;
Now_Seconds : Day_Duration;
Current_Real_Time : Ada.Real_Time.Time;
Time_Span : Ada.Real_Time.Time_Span;
Seconds_Count : Ada.Real_Time.Seconds_Count;
Hour : float;
begin
--- Ada.Calendar
Split (Now,
Now_Year,
Now_Month,
Now_Day,
Now_Seconds);
Put_Line("Calendar : Date du jour = ");
Put_Line ("Current year is: "
& Year_Number'Image (Now_Year));
Put_Line ("Current month is: "
& Month_Number'Image (Now_Month));
Put_Line ("Current day is: "
& Day_Number'Image (Now_Day));
Put_Line ("'Current' seconde is: "
& Day_Duration'Image (Now_Seconds));
New_Line;
--Ada.Real_Time;
Current_Real_Time := Ada.Real_Time.Clock;
Ada.Real_Time.Split (T => Current_Real_Time,
Sc => Seconds_Count,
Ts => Time_Span);
Put_Line ("Real_Time : Seconds_Count = " & Seconds_Count'Img);
Hour := (float(Seconds_count) / 3600.00);
Put_Line ("Hour since seconds origin : "
& (Hour'Img));
end Display_Current_Year;
with result :
$ ./display_current_year
Calendar : Date du jour =
Current year is: 2022
Current month is: 2
Current day is: 27
'Current' seconde is: 68625.325897000
Real_Time : Seconds_Count = 30953
Hour since seconds origin : 8.59806E+00
$
-Results for calendar are OK, but why 30953 seconds !!
Where does GNAT take the Epoch, if this is, in this case, please?
Thanks
Mark
You can do a dirty trick where you define a record My_raw_duration_Type : whole_part, fraction_part, both U32. Define Unchecked_Conversion To_Raw (Ada.Real_Time.Duration, My_Raw_Duration_Type). Then take the result of that and call it My_Raw_Duration. The milliseconds result you want is integer(float(My_Raw_Duration.Fraction_Part)/float(4*1032**2) * 1000.0);

Printers object in VB 6 not returning printer with special character in name

VB6 (not VB.Net or VBScript)
I'm using the Printer object and recently found that some printers
are not being returned if the name has certain characters.
In VB6 it would be something like:
Dim pr As Printer
For Each pr In Printers
MsgBox pr.DeviceName
Next pr
I can easily rename any printer in Windows (any OS version) and
make it fail.
I suspect it's related to a UTF-8/Unicode issue, but I don't know how to resolve it.
For example, this printer name works fine: "MyPrinter 1", but this does not: "MyPrinter 1 ę".
How can I get the Printer when the name has a non-standard (for US English anyway) character?
EDIT:
I've found this code to access the printers, and it will correctly return all of them, even with special characters.
However, I don't know how to either:
1) Use the object for printing (as I would with a Printers object)
2) Or set a Printer object to the returned object from WMI
(FYI - The InkEdit control will correctly show the special characters without any Unicode wrangling - I'm using for display purposes only.)
Dim strComputer As String
Dim objWMIService As Object
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer")
Dim myPrinter As Printer
Dim junk As String
For Each objprinter In colInstalledPrinters
List1.AddItem objprinter.Name & " --- " & objprinter.ShareName & " --- " & objprinter.ServerName
InkEdit1.Text = InkEdit1.Text & objprinter.Name & " --- " & objprinter.ShareName & " --- " & objprinter.ServerName & vbNewLine
If InStr(1, objprinter.Name, "HP") > -1 Then
myPrinter = objprinter.
End If
Next

Script to add day not date to filename

I need to create a script batch, PowerShell or VB to add the day of the week to the filename.
For example, there are 4 files and all need to have MON apended to the front on Mondays, TUE on Tuesdays, WED on Wednesdays, etc.
Can anyone assist with this please?
$dow = (Get-Date -f ddd).ToUpper()
$fileName = "${dow}_your_file_name.txt "
THU_your_file_name.txt
Use the VBScript Docs or Google for details on the Weekday() and WeekdayName() functions used in:
Today = Date()
DayNum = Weekday(Today)
DayName = WeekdayName(DayNum, True)
WScript.Echo UCase(DayName) & "_" & "somefile.txt"
THU_somefile.txt
PS:
Start here: Functions (VBScript)
Well, there's an answer for powershell and one for VBScript. Here's one for Windows cmd batch.
#echo off
setlocal
for /f "tokens=5" %%I in ('find "" "%date:~0,3%" 2^>^&1') do set day=%%I
ren "oldfile.txt" "%day%_oldfile.txt"
Explanation
:: DIRECTIVE RESULT
:: --------------------------------------------------------
:: %date% Thu 02/07/2013
:: %date:~0,3% Thu
:: find "" "Thu" error stating "File not found - THU"
:: --------------------------------------------------------
Then all that remains is to redirect the error from stderr to stdout and scrape the fifth token.
(source of idea to use find to convert to upper case)
if you choose VBScript, be careful with WeekDayName function as it related to regional language settings. For example, Friday is Петък (in Bulgarian), so in my system WeekDayName with abbreviate set to True will return Пт, not Fri.
WScript.Echo WeekDayAbbrENG()
Function WeekDayAbbrENG()
Dim WDs
WDs = Split("SUN MON TUE WED THU FRI SAT")
WeekDayAbbrENG = WDs(Weekday(Now) - 1)
End Function
[EDIT] Actually, the same problem appear with Get-Date in PowerShell.

Display Superscript in SSRS reports

I m working on SSRS 2008.
i want to display date as 1st January 2011..
but "st" should be in superscipt ..
not like "1st".
is there any way to display "st", "nd","rd" and "th" in superscipt without installing any custom font type(other Font Type).
just copy and paste from the following list:
ABC⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁺ ⁻ ⁼ ⁽ ⁾
ABC₀ ₁ ₂ ₃ ₄ ₅ ₆ ₇ ₈ ₉ ₊ ₋ ₌ ₍ ₎
ABCᵃ ᵇ ᶜ ᵈ ᵉ ᶠ ᵍ ʰ ⁱ ʲ ᵏ ˡ ᵐ ⁿ ᵒ ᵖ ʳ ˢ ᵗ ᵘ ᵛ ʷ ˣ ʸ ᶻ
ABCᴬ ᴮ ᴰ ᴱ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴼ ᴾ ᴿ ᵀ ᵁ ᵂ
ABCₐ ₑ ᵢ ₒ ᵣ ᵤ ᵥ ₓ
ABC½ ¼ ¾ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ № ℠ ™ © ®
ABC^ ± ¶
Maybe...
You are limited to what can be done with String.Format. Font size and spacing also refer to the whole text box. So it isn't "native"
However, superscript is unicode so you may be able to to do it with some fancy expression that concatenate characters. I'd suggest custom code.
I haven't tried this, but these articles mention it
http://beyondrelational.com/blogs/jason/archive/2010/12/06/subscripts-and-superscripts-in-ssrs-reports.aspx
http://www.codeproject.com/KB/reporting-services/SSRSSuperscript.aspx
I am not looking for credit here as above solution has answered it for you but for beginners sake, I use a code function within my report.
So in my SQL say I have Number field, then I add a new field OrdinalNumber:
SELECT ..., Number,
CASE WHEN (Number % 100) BETWEEN 10 AND 20 THEN 4
WHEN (Number % 10) = 1 THEN 1
WHEN (Number % 10) = 2 THEN 2
WHEN (Number % 10) = 3 THEN 3
ELSE 4 END AS OrdinalNumber,
...
Then my code function:
Function OrdinalText(ByVal OrdinalNumber As Integer) As String
Dim result As String
Select Case OrdinalNumber
Case 1
result = "ˢᵗ"
Case 2
result = "ⁿᵈ"
Case 3
result = "ʳᵈ"
Case Else
result = "ᵗʰ"
End Select
Return result
End Function
Then in the report textbox I use the expression:
=CStr(Fields!Number.Value) & Code.OrdinalText(Fields!OrdinalNumber.Value)