November 22, 2006
C# Programming For A Beginner
At work, I have been using a tool called AutoHotKey which can record repetitive tasks as well as is a comprehensive scripting/macro language. As I got more familiar with it, I started using it for more complex tasks.
One such tasks was simple in concept, I wanted a way to capture user input and run batch files against it. This could be done just in batch, but I wanted a fancy UI for it. As I delved into building Windows Forms in AutoHotKey, I happened to be talking to our resident programmer. When he got a sense of how cumbersome this tool as for designing the actual UI, he suggested I try C#. Basically, it would be easier to do the UI work, and not much harder to do the logic in the background, plus it was a language that would be more useful down the road.
Let me just interject at this moment that as far as programming goes, batch is as far as I had ever learned. I can do some pretty good stuff in batch (with Google’s help of course), but I really had no knowledge of basic programming concepts.
So I delved into Visual Studio 2003 (which we have a license for here at work)… only to find out it does not work with Vista. Well, it may work if you follow a million work arounds, but I was not about to. So I moved to Visual Studio 2005. Painting the screen was easy enough, I discovered how to hide and show buttons and things pretty easily. Once I had the UI doing what I want, it was time to start taking the little bits of data entered by the user and working with it. This is where I stumbled.
I had a listbox and a textbox. I wanted to send the data entered/selected in those two fields to a batch file. Try as I might, I got no where. Google searches were no help, because my request was far too basic, and all replies were far over my head. I finally found bits of info on MSDN that gave me some ideas, but I kept getting stuck with an error about trying to turn an object into a string.
After another chat with our programmer, who set me straight (and showed me just how close I had gotten, which was nice), I was well on my way. I figured out how to set strings, and how to combine strings. I even figured out how to put a space character between two strings. Finally, with Google’s help, I found how to call a batch file. After some last bits of tweaking, I had an EXE that took user input, and launched a batch file to do some tasks for me.
My code may be ugly, and I may be doing things wrong, but it works, and I am sure proud of building my first C# application. Hopefully I can find the time to expand on it. I know I need to validate the data entered (spaces could cause big problems), and I would like to pull a list of servers from a text file rather then hard coding them.
But first I think I need to use this small bit of success as motivation to go through one of those “Teach Yourself C#” books. As if I did not have a million other things to do with my time!








