Wednesday, July 28, 2010

Converting string value of an Enum entry to a valid instance of the Enum

"How do I convert a string value of an Enum entry to a valid instance of the Enum?"

C#

String [VariableName] = "StringValue";

[EnumType] [VariableName1] = ([EnumType])Enum.Parse(typeof([EnumType]),[VariableName]);

Example:

String ListSortDirectionString = "Ascending";

System.ComponentModel.ListSortDirection ListSortDirectionEnum = (System.ComponentModel.ListSortDirection)Enum.Parse(typeof(System.ComponentModel.ListSortDirection), ListSortDirectionString);

VB.NET (Option explicit ON, Option strict ON)

DIM [VariableName] AS String = "StringValue";

DIM [VariableName1] AS [EnumType] = CType(Enum.Parse(GetType([EnumType]), [VariableName], True), [EnumType])

Example:

Dim ListSortDirectionString As String = "Ascending"

Dim ListSortDirectionEnum As System.ComponentModel.ListSortDirection = CType([Enum].Parse(GetType(System.ComponentModel.ListSortDirection), ListSortDirectionString, True), System.ComponentModel.ListSortDirection)

Tuesday, March 30, 2010

Visual Studio - hexadecimal editor

I have a project that parses large text files from one third-party source into a bunch of small text files for another third-party printer interface.
Using Regular Expression and Hexadecimal File Editors have been a base necessity.
For example, almost none of the newer print systems use a Form Feed - character code 12 in decimal (0xC in hexadecimal) - Chr(12) -Regular Expression \f - Hexadecimal View 0C
Of course, the third-party printer interface in this scenario required the Form Feed be kept in position.

Nearly every six months, like this week, another alteration is asked for and I find myself back in the code.



Due to the infrequency of use, I find it difficult to keep the details of Regular Expression syntax in my head so I use Expresso from Ultrapico (http://www.ultrapico.com/) which does an excellent job of translating what I want into a .NET Framework Language code snippet.

For my project development I use Visual Studio 2008 SP1 which has as much of a hexadecimal editor "Binary Editor" as I need.

=============================
Visual Studio - hexadecimal editor

Go to File -> Open -> file

Select the file that you want to open, the Open button state will change to enable

Click the small drop down list at the right of the Open button and select Open With

You will get a list of additional editors, choose Binary Editor

http://francoisbeaussier.blogspot.com/2007/04/visual-studio-has-also-hexadecimal.html

Friday, March 26, 2010

Puzzle Eye

I started a puzzle long ago. I was given a block of pieces fit together forming an eye looking at me. “This piece goes just like this,” the elder said as he left me to finish the rest.

The puzzle was large and complex.

Taking my time I found other parts that that fitted together making small understandable blocks, but none fit with the eye. Over time I pieced together a border many small blocks which I had worked out fit into place within the boarder, but not the eye… Surely it would go in this space here, my reason would argue against my experience.

The eye did not fit; more of the puzzle came together; the eye did not fit…

Perhaps I have made an assumption I am not aware of… What do I know?

I know, what I know may be wrong… I carefully dismantled the eye and tested each piece.

Over and over they only came together again as an eye starting at me…

More of the puzzle came together, but as always, the eye did not fit…

Take a break; walk away; come back and try again;

More of the puzzle came together; maybe the eye was not a part of this puzzle…

But then why was it here, given and left staring at me?

Or was that an assumption too?

Then I laughed; I laughed until I was short of breath and tears stained my checks.

Oh, what Joy!

Oh, what a fool I am.

I turned the eye completely round and dropped it into place.

Wednesday, March 17, 2010

Cameelious hump Poem

Just So Stories For Little Children
By Rudyard Kipling
Published 1915
How the camel got his hump
epilogue Pg 29

The Camel’s hump is an ugly lump
     Which well you may see at the Zoo,
But uglier yet is the hump we get
     From having too little to do.

Kiddies and grown-ups too-oo-oo,
If we have n’t enough to do-oo-oo,
     We get the hump - - -
     Cameelious hump - - -
The hum that is black and blue!

We climb out of bed with a frouzly head
     And a snarly-yarly voice.
We shiver and scowl and we grunt and we growl
     At our bath and our boots and our toys;

And there ought to be a corner for me
(And I know there is one for you)
     When we get the hump - - -
     Cameelious hump - - -
The hump that is black and blue!

The cure for this ill is not to sit still,
     Or frowst with a book by the fire;
But to take a large hoe and a shovel also,
     And dig till you gently perspire.

And then you will find that the sun and the wind
And the Djinn of the Garden too,
     Have lifted the hump - - -
     The horrible hump - - -
That hump that is black and blue!

I get it as well as you-oo-oo - - -
If I have n’t enough to do-oo-oo - - -
     We all get hump - - -
     Cameelious hump - - -
Kiddies and grown ups too.

Monday, February 15, 2010

Learning Oracle Data Provider for .NET

On “Using System.Data.OracleClient”
As of June 2009 Microsoft announced its deprecation of System.Data.OracleClient, also known as Microsoft OracleClient.
Choosing to use it instead of learning how to professionally and effectively utilize ODP.NET (Oracle Data Provider for .NET) is a dead end road.
Start with ODP.NET for Microsoft OracleClient Developers; keep learning, keep refactoring; make the best product you can with the resources you are allotted.
I personally feel there is still a lot to learn on my own path of ASP.NET and Oracle development. It certainly isn't a line of development I originally planned on.
Of course, running Oracle on windows isn't a lot of fun, but it is manageable if you keep up with all the small tweaks that are needed for the two to play nice together.