February 28, 2005
C# timer
[The Code Project - High-Performance Timer in C# - C# Programming] While there is no explicit performance requirement for this lab, you may find this timer class useful in your self-assessment or improvement.
(Thanks to Doyle for the pointer to the class.)
Posted by jones at 07:25 PM | Comments (0)
February 17, 2005
Reading and writing from an Access database
For the drill core lab, you get to write you own code to connect to the database. If you are smart and lazy, you might just copy and modify the TA's code for connecting to databases. You used that code in the first two projects. Here are a few ideas for how to adapt their code for this project. Of course, you might also decide to use your own method for connecting to a database. That's fine too.
You will need to add
using System.Data.OleDb; // needed for database code
to list of "using" directives near the top of your file.
The TA's establishConnection function needs a string that gives the location of the database relative to the executable created for your program. As you may know, your executable will live in either <projectHome>/bin/debug or <projectHome>/bin/release. YOu will put your database file in the <projectHome> directory which means that you will need to use ..\\..\\core-samples.mdb as the source string parameter to establishConnection.
In the TA code for the phylogenetics project, the aptly named function "load" loads a problem from the database. You will be reading from tables that have a slightly different and simpler format than in the phylogenetics project.
Here's some more info from the good people at Microsoft. [Creating Connections to Access Databases (Visual Basic and Visual C# Concepts)]
Posted by jones at 08:09 AM
February 10, 2005
More efficient and stable for C# than for C++?
The word I am getting from people in the class is that visualStudio is much more efficent and stable for C# than C++. The interactive debugger is even fast enough to be useful with C#. That's consistent with my experience. I took a minute to reflect on my visualStudio experience and realized that I have always used it for C# programming. So that's why I was a little surprised when so many of you reported slowness and instability on the first projetc (in which we used C++ you may recall).
What has been your experience?
Posted by jones at 10:38 AM | Comments (0)
February 04, 2005
Debugging
If you can't debug, then you are probably going to struggle with the projects. If you can't see what your program is doing, then you can't debug. Here's some ideas on debugging in VisualStudio.
Keep in mind that the help functionality of VisualStudio is actually pretty good and that we have free online access to the O'Reilly books.
- First off, the interactive debug capabilities of visualStudio are pretty good. Its worth your time to learn the key shortcuts etc so you don't have to hunt and click everything. (If you know gdb really well, then you will probably find visualStudio's interface annoying. That is, until you learn it as well as you've learned gdb's interface.)
On really slow machines, interactive debugging may become annoying. Here's some more ideas.
- Write to the console. You are probably familiar with this approach in linux. In visualStudio, you use "Console.Writeline" and then its almost the same. The handling of strings, numbers etc. is a little different. See the documentation for details.
The other trick is finding the console. The console is one of the tabs on your output pane in the visualStudio cockpit. In my set up, its on the bottom left corner of the screen.
- The final method is to make your own scrolling textbox in your program and write to it. To add a scrolling text box, edit your interface, add a textbox and enable the multiline and scroll methods. Give the textbox a name and set the "TextBox.Text" member to be whatever you'd like. Note that something like
TextBox.Text = TextBox.Text + "new message";
will simulate scrolling through messages.
Post your comments, suggestions here.
Posted by jones at 12:46 PM | Comments (0)
January 13, 2005
Graph Visualization and Layout in C#
The his entry covers stuff I have looked at and tried to get graph layout and visualization to work in C# for the phylogenetics project.
The basic plan thus far is:
- Use the Adobe Acrobat Reader ActiveX control to display and PDF file in the C# windows application. The activeX control is included with version 5.0 and higher (currently 7.0)
- Make sure Adobe Acrobat Reader version 5.0 or higher is installed on the system.
- Create a new C# windows application using the Wizard.
- Open the form toolbox.
- Right click the Windows Forms toolbox entry and select Add/Remove Items...
- Click on the COM Components tab and add a check to the Adobe Acrobat x.0 Browser Dcoument com object and click OK.
- Find the newly added Adobe Acrobat x.0 Browser Dcoument componenent in your Toolbox and add it to your form.
- Double click the added object to bring up the code area and add axAcroPDF1.LoadFile("c:\\tmp\\file.pdf"); to the axAcroPDF1_Enter(...) function.
- Build and run the application
- Actually, we want to use the Adobe SVG viewer to dispay the plots because dot can output directory to svg and svgz formats.
- Download and install the Adobe SVG viewer.
- Add the new SVG Document to you Visual Studio .NET Toolbox as described above for the PDF viewer.
- Add a panel object to you form.
- Anchor the panel object on all sides so it resizes with the window.
- Add the Adobe SVG viewer to the panel.
- Dock the viewer in its properties and set it to fill; this will let it resize with the panel.
- Set the SRC property on the SVG viewer to the file you want.
- If you overwrite the file and want the viewer to update, call its reload() member function.
- Use the GraphViz dot or neato programs to generato the layout.
- Download and install GraphViz
- Add the following code attached to a button to call it from a C# windows application:
private void button2_Click(object sender, System.EventArgs e) {
string strCmdLine1 = "-Tsvg -o c:\\tmp\\foo.xml c:\\tmp\\ER.dot";
string strCmdLine2 = "-Tsvg -o c:\\tmp\\foo.xml c:\\tmp\\Heawood.dot";
System.Diagnostics.Process p = new System.Diagnostics.Process();p.StartInfo.FileName = "\"C:\\Program Files\\ATT\\Graphviz\\bin\\dot.exe\"";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
if (graphIndex == 0)
p.StartInfo.Arguments = strCmdLine2;
else
p.StartInfo.Arguments = strCmdLine1;p.Start();
p.WaitForExit();
axSVGCtl1.reload();
graphIndex = (graphIndex + 1) % 2;
}
Before we can really use this, we need to figure out if the students can install the GraphViz and SVG Viewer on the downstairs lab machines. This is going to be critical for the viewer to work. The only other choice is to try and ship the viewer as a standalone application. I am not sure, however, that we can statically link in the things we need for that.
Posted by egm at 12:30 PM | Comments (0)
January 11, 2005
Memory optimization in managed code
[Memory Lane: Rediscover the Lost Art of Memory Optimization in Your Managed Code -- MSDN Magazine, January 2005] A student in another section pointed out this article. Its an interesting read.
Posted by jones at 02:11 PM | Comments (0)
January 08, 2005
Remote desktop client for Mac
[Remote Desktop Client for Mac] If you've got a mac and a windows machine and a network connection, then you can use this program to connect to your windows machine from your mac. I use it at home all the time. rdesktop is a linux/unix/X11 version of the same thing that you might also find useful.
Posted by jones at 12:03 PM | Comments (0)
January 05, 2005
Creating a windows application with a textbox and button in C#
A few pointers for creating a windows application in C# that has a textbox and a button. Clicking the button changes the value in the textbox. This has alot of interface programming problems, but should be a nice introduction to what the tools do.
- Create a new project that is a C# windows application (its the top left selection in the C# menu pane).
- In the form1.cs[Design] view, select "View -> Toolbox" to get the drag and drop interface widgets to appear.
- In the bottom right corner of this view, you will see a "properties" box. It might be somewhere else. You can right click on a widget to bring up a menu, then click Properties. One of the properties is "Text". This, as you might be able to see, is the text on the button label or the text in the text box.
- The first line of hte properties box gives the name of the widget. This name is the name you'll use in your code to modify and use the widget.
- Double click on the button in your new form to bring up the C# method that will handle button click events for the button. This is where you will write code to do whatever you want to do when the button is clicked. (For example, you might increment a counter, compute 2 raised to that counter and write a string to the text box).
- To change the value in the textbox, note the name of the text box and set the text attribute of the textbox object to the new value (its all so object oriented!), like so,
textBox1.text = "some new text";You'll know you got the name of thte textBox1 object correct if: when you type the "." a completion window pops up to let you select the attribute you'd like to set (or read) or method you'd like to call. - These widgets do their own damage and updates automatically. Damage is when you change the value of a widget and update is when you redraw the widget with the new value. So you don't have to do damage and updates (you might not appreciate this, but you should be glad that's one less thing to worry about).
- You can declare you own variables that will be visible to all of your widget objects. One place to do this is right after the declarations of your textbox and button objects. In my version (and probably yours too because I just used the default code) that's on about line 16. For example, you might want to declare a new integer that stores the number of times a button has been clicked. You'd declare it here.
Posted by jones at 01:46 PM
December 31, 2004
How to get VisualStudio for free
[BYU CS MSDNAA] A few BYU students took the initiative to get our department into the MicroSoft Developers Network Academic Alliance (Steven Helut and McKay Salisbury among others). That means you can get a free copy of Visual Studio if you are taking at least 1 CS class. Visit the above website for details on how to do it. There is about a week of latency.
Posted by jones at 09:25 AM | Comments (0)
December 16, 2004
Setting Command Line Parameters
For many projects, you will need to pass your netID and a database filename in on the command line. Here's how to do that...
Choose "Project |
properties | Configuration properties | Debugging" Then add the arguements under "Command arguements." For most projects, add the name of the database first followed by your netid. So for the Crossing the Desert project, I have to following:
Command arguements: desert.mdb mdj
Posted by jones at 10:44 AM | Comments (0)
- Use the Adobe Acrobat Reader ActiveX control to display and PDF file in the C# windows application. The activeX control is included with version 5.0 and higher (currently 7.0)