Carrying on from the previous blog, the user of iterators in .Net and especially .Net on COBOL can be very useful.
When CLR v2.0 was introduced a few new methods in System.IO.File for block reading/writing files were introduced, these works on arrays aka “OCCURS ANY” fields. Using these APIs instead of using traditional line sequentials is a breath of fresh air, especially if you just want to do some code something quickly without the need of records/group items.
So lets.. have a little play around, lets read a “MonthNames” from the CLR, write them to disk, read them back, reverse and sort it, while display them…
01 Months-Array type "System.Array".
01 Months string occurs 12.
01 Month string.
*> Note: the MonthsNames has 13 elements and the last element is ""
*> and I'm not interested it it so I'll drop it by doing a "ConstrainedCopy"
*> with just elements I'm interested in.
*> http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.monthnames.aspx
set Months-Array to type "System.Globalization.DateTimeFormatInfo"::"CurrentInfo"::"MonthNames"
invoke type "System.Array"::"ConstrainedCopy"(Months-Array, 0, Months, 0, Months::"Length")
display Months::"Length"
perform varying Month through Months
display "Normal -> " Month
end-perform
*> Write the array to disk
invoke type "System.IO.File"::"WriteAllLines"("MyMonths.txt", Months)
set Months to null
*> Read it back
set Months to type "System.IO.File"::"ReadAllLines"("MyMonths.txt")
*> Reverse it
invoke type "System.Array"::"Reverse"(Months as Type "System.Array")
*> Display it
perform varying Month through Months
display "Reverse -> " Month
end-perform
*> Sort it
invoke type "System.Array"::"Sort"(Months as type "System.Array")
*> Display it
perform varying Month through Months
display "Sorted -> " Month
end-perform
Which when executed gives us:
12
Normal -> January
Normal -> February
Normal -> March
Normal -> April
Normal -> May
Normal -> June
Normal -> July
Normal -> August
Normal -> September
Normal -> October
Normal -> November
Normal -> December
Reverse -> December
Reverse -> November
Reverse -> October
Reverse -> September
Reverse -> August
Reverse -> July
Reverse -> June
Reverse -> May
Reverse -> April
Reverse -> March
Reverse -> February
Reverse -> January
Sorted -> April
Sorted -> August
Sorted -> December
Sorted -> February
Sorted -> January
Sorted -> July
Sorted -> June
Sorted -> March
Sorted -> May
Sorted -> November
Sorted -> October
Sorted -> September
That was pretty easy… and the code looks okay too… can’t be bad…
References : System.Globalization.DatetimeFormat
In truth, immediately i didn’t understand the essence. But after re-reading all at once became clear.
cheap clomid
I glad it made sense after you re-read it… I will sincerly try to explain more as I go… I am just a “junior” blogger… sort of learning on my feet..
Interesting and informative. But will you write about this one more?
I intend to write more stuff, do you have any specific area’s of interest?