Interested on Microsoft technologies? Read Visual Studio Dot Net

Reason of this project:
I have already explained well how to use the timer control. Now we'll try to use it in a complex (but not a lot) string problem.
The aim is to create an animation program, that reads text and make an animation by displaying the first, then the second...characters until it get the last one, then it make it again.
The speed can be also fixed. Also we'll added other settings like Mirror and Uppercase

Project details:
1- Description of the string class
2- First Step: Making a handler
3- Next Step: Making a clear plan
4- The alarm example

1- Description of the String Class:

I have explained the Timer control, you can see it just in the previous post; now I want to highlight about the String Class.
The String Class in Dot Net is different that the version 6.0 of Visual Studio. First it becomes an object, second some new features are available.
I'll highlight one: The Upper and the lower function.
This function will up case all the characters in the string or lower them.
Those function exist in VS 6.0 but I'm highlighting because we'll use them on our application.
String.length (function): return the string length as integer
String.substring (function): Retrieve a part from the string. You specify the starting and the length of this part.
Notes for integers:
n = n + 1 is the same as n += 1
n = n - 1 is the same as n -= 1
At end the string class isn't so complex or hard to use!

2- First Step: Sample aim and controls

Let's see what we need and what we won't.
The application must contain:

* A text box for the speed of the animation
* A text box for the text of the animation
* A button to start the timer
* A button to stop it (but we can also make them one button)
* A check box for Uppercase
* A check box for the mirror

Now let see what the application does.
The user type a text and set a speed. Then click Run to start the animation.
The user can choose Uppercase to make the printing results upper or to make them normal by unchecking.
If the user choose the mirror setting and the animation is running, it will stop it in order to reset the settings.
Note:
You can get many errors in this application for example if you enter a string and not an integer in the speed text box.
In this case you must use the Try Catch End Try block in order to get exceptions.
I didn't take care for this part as it isn't the subject of our work.

3- Next Step: Making a clear plan

The problem of most beginners programmers is where to start from?
They have learn a lot but they didn't know how to use their knowledge.
I'll show you how to create this project your self!
Me also I can't make such as project from the first hit (instance I mean).
I need to make parts and easier the project. I'll explain: Those are the parts that I have made before finishing my sample.

- Making an animation with a string (not variable). The project contain only a Label to show the animation. This is the most difficult part in the project and it took about 5 minutes.
- Adding the Run, Stop buttons (1 minute)
- Making the speed and the text customizable by the user (1 minute)
- Adding the Upper case check box (1 minute)
- Adding the mirror check box (2 minutes)
- Review of the project (1 minute)
- Adding comments to the code(3 minutes)

--> Total time: about 15 minutes.

It took a long time to make it! But it was finally made, because I divided my work on steps, from easier to harder and every time I make it a little bit harder.
But If you want to make it from the first time, you'll probably have errors and missed things on your application (else you are a genius).
Even with most easy case, this method is good; you learn how to organize your work.
If you are a beginner don't try to start from the last tutorial but from the first one because I'm increasing difficulty level each time.


4- Final Step: The first step

As I said in the project plan, this is the most difficult step ever.
I'll explain here only the first step, the rest you can easily understand it from the sample comment.
The aim is to have an animation that get from the first character to the last character with the help of the timer that make a time for a loop.
This is the most difficult sentence. It group all the needs; (From the first chr to the last chr) The first is always 0 and the last is always string.length.
We have only to add 1 each time the timer call the event. Plus if the n times arrived (equal) the length of the string we must reset it to 0 or stop the timer so the error don't occur.
How to get the text from the first to the last character:
result = anim.Substring(0, n)

We have to add 1 to n every time the timer call the procedure.
n += 1
If n = ln Then n = 0

But also to reset it!
See the source code for more information (read the comments).
Note: for the mirror, we'll make like we have done in the normal case but to inverse!
result = anim.Substring(n2, n)

n2 is the length (we start from the end) and decrease by 1 each time the procedure is called.

Download the source code

The Zip file contains:
-The example source code
-The readme.txt file
-The tutorial.txt file

Still have question:
If you have any problem or you found a bug, post a comment describing your problem.
If you have a general question, we highly recommend the MSDN Forums as the best Dot Net forums in the net.

Bookmark and share this tutorial
Related Ads

0 comments:

Related articles