tags:

views:

176

answers:

4

Recently been given this work to do, I am new to programming so I don't really know alot about it or how to use it. I suppose it would be easier to just be given the code, but I would like to know how to do it myself to. Have tried reading up on the language and trying it myself but im just not grasping it very well. Any help is greatly appreciated. Here's the work.

Write a program in C# (Express Edition) which will:

(A) Open a text file (it should only display .txt files in the file chooser) from disk

(B) Display the contents in both text and hexadecimal form simultaneously using two text boxes on the form

(C) Allow the user to change text and to save the modified file back to the disk. If a user changes text in the text box, the hexadecimal box should update automatically

The hex display should be neatly formatted in whole columns and show the value of each character in the form '0xnn'

Ensure that the program is fully commented and that any sources of inspiration are acknowledged in an 'about' message box which can be called up from a menu item

A: 

Try here, some good learning videos and tutorials

windowsclient.net

Rigobert Song
A: 

Download WinHex.

Mau
I guess the "Ensure that the program is fully commented" part will get complicated. However, for an inspiration of what a hex editor should do, this may be useful.
OregonGhost
+10  A: 

You won't find anyone here who will write the code for you (and in all fairness you didn't ask for that), but since the .NET libraries are large and complex I'll point you in the right direction.

Pretty much everything you need is found in the System.IO namespace

a) Look at using a File Dialog to allow the user to pick from a filtered set of files

b) Once you have the filename look into filestreams and textreaders to read the file into the two formats you need.

c) If you are using WPF then bindings will allow you to keep the two text boxes in sync and a combination of a textwriter and another filestream will allow you write the altered data back out.

Good luck. Try and break the project down into smaller tasks (e.g. how do I open up a file dialog?) and if needed come back here and ask specific questions about any issues that you run into, adding the code that you already have to the question so it is easier for us to give you useful answers.

Martin Harris
+1 for good advice, +1 for no grumpiness (but I can't:()
Patrick
@Patrick: I've added my +1 for your second one :)
OregonGhost
+1 for the very helpful answer! SO need more people like you...
mhenrixon
+2  A: 

General tips for solving your problem, since it looks like homework:

  • Start off easy and break it up into smaller pieces, for example:
    • Create a text file in a known location, and try to open it with code, change it and save it again. There you have half of your program done already.
    • Output the text in a console window to see that everything works "behind the scenes".
    • Continue by creating the GUI for your application. Create empty text boxes and make the layout seem correct.
  • Then step by step, try to mix the two into a basic version of the program.
  • As you get along, you'll eventually encounter a lot of small problems which you solve as you go.
  • Expand your program until it meets all requirements.

This is how all software is built, and what a lot of people struggles with in the beginning. You cannot grasp a problem or task as one big chunk. You'll be better off by splitting it into smaller pieces. Programming is not easy in and by itself - solving problems is one of the main things you do.

And since this really looks like homework, your teacher/lecturer has probably mentioned the necessary tools to do this. Martin Harris also mentioned a few things worth looking at.

Arve Systad