<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3593543847859157882</id><updated>2012-02-16T12:28:09.085+03:00</updated><category term='C#'/><category term='AJAX'/><category term='WAP'/><category term='Expression Blend'/><category term='Physical Computing'/><category term='.net'/><category term='Microsoft'/><category term='WPF'/><category term='Tips and Tricks'/><category term='Parallel Port'/><title type='text'>AhmedGamal-NET</title><subtitle type='html'>Technical Blog.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-6124503473676310426</id><published>2009-11-16T03:03:00.001+03:00</published><updated>2009-11-16T03:03:19.837+03:00</updated><title type='text'>Introduction to Prolog</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics (Wikipedia Definition @ http://en.wikipedia.org/wiki/Prolog).&lt;/p&gt;  &lt;p&gt;Prolog, LISP and many other languages depend on logic syntax and are represented as facts and rules. If you have any experience in programming using languages such as C#, JAVA or C++, then you need to change the way that you are using to write your codes.&lt;/p&gt;  &lt;h4&gt;&lt;font color="#ff0000"&gt;How to start?&lt;/font&gt;&lt;/h4&gt;  &lt;p&gt;First of all, you need to download some tools to execute your commands; one of them is Amzi Development Environment. You can find it here: &lt;a href="http://www.amzi.com/"&gt;http://www.amzi.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;What you have to do is just to open new file and write down your commands, then from Listener-&amp;gt;Start you can start execute your code.&lt;/p&gt;  &lt;h4&gt;&lt;font color="#ff0000"&gt;Code Syntax:&lt;/font&gt;&lt;/h4&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;As we said in the beginning of this lesson, prolog depends on logical relationships, like:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a13242be-a770-4974-9683-9816c0b26d30" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;Human(Ahmed)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;Car(Toyota)&lt;/li&gt; &lt;li&gt;Human(Khaled)&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;This means that Ahmed and Khaled are humans. And Toyota is a car.&lt;/p&gt;  &lt;p&gt;Let’s test those three lines; go to Listener -&amp;gt; Start then Listener -&amp;gt; Consult. &lt;/p&gt;  &lt;p&gt;And in execution window, type the following question:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e7dc37fb-1238-4a73-ab5e-4c5ba46f6e9d" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;?- Human(V).&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here we ask to show all humans and put it in array named V, you can press enter to quit or “;” to continue.&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;*** Note: (V) must be capital. All variables in Prolog must be capital.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The second type of questions is the Yes/No questions, like this:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:aa59b700-cb49-4408-940b-bcee49344ef2" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;?- Human(Ahmed).&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And you will get the answer depending on if you have added Ahmed to humans or not.&lt;/p&gt;  &lt;h4&gt;&lt;font color="#ff0000"&gt;Relations:&lt;/font&gt;&lt;/h4&gt;  &lt;p&gt;In addition to previous, we can describe relationships between two items:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:897a7411-7a3e-4630-bbea-251585fc8448" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;father(ahmed,mohammed)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;father(ahmed,ali)&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;So if we ask the engine this question:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b22e6828-3bfd-4a43-9961-e77be09bd585" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;?- father(ahmed,U)&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;We will have all Ahmed's sons in U list.&lt;/p&gt;  &lt;h4&gt;&lt;font color="#ff0000"&gt;Rules:&lt;/font&gt;&lt;/h4&gt;  &lt;p&gt;That is the point where we will start get benefit from prolog, this is the way that human brain works when thinking. For example (all cars have a door and all planes also):&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ede29b89-3f08-4b81-824a-279d5810effa" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;car(X) :- gotadoor(X).&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;airplane(X) :- gotadoor(X).&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Then let's declare some planes and cars:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b26a4fe5-32b8-4037-9042-48473d0346b9" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;car(toyota)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;car(mazda)&lt;/li&gt; &lt;li&gt;car(jagoar)&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;airplane(ai100)&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;If we ask if mazda have a door or not, prolog engine will be smart enough to answer with yes.&lt;/p&gt;  &lt;h4&gt;&lt;font color="#ff0000"&gt;More about Prolog:&lt;/font&gt;&lt;/h4&gt;  &lt;p&gt;This is just simple introduction to Prolog. There are a lot of features in Prolog you can start with from this link:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://kti.mff.cuni.cz/~bartak/prolog/learning.html"&gt;http://kti.mff.cuni.cz/~bartak/prolog/learning.html&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;&lt;font color="#ff0000"&gt;Example:&lt;/font&gt;&lt;/h4&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Einstein Problem, one of the famous puzzles. Where the puzzle author (Einstein or anybody else) said that 98% of peoples can’t solve this problem:&lt;/p&gt;  &lt;p&gt;There are 5 houses sitting next to each other, each with a different color, occupied by 5 guys, each from a different country, and with a favorite drink, cigarette, and pet. Here are the facts:&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The Brit lives in the red house&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The Swede keeps dogs as pets.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The Dane drinks tea&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The green house is on the left of the white house&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The green house's owner drinks coffee&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The person who smokes Pall Mall rears birds&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The owner of the yellow house smokes Dunhill&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The man living in the center house drinks milk&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The Norwegian lives in the first house&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The man who smokes Blends lives next to the one who keeps cats&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The man who keeps horses lives next to the man who smokes Dunhill&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The owner who smokes Bluemaster drinks beer&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The German smokes Prince&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The Norwegian lives next to the blue house&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The man who smokes Blend has a neighbor who drinks water&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#004080"&gt;The question is: Who owns the fish?&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;If we try to translate this problem into Prolog group of facts, rules and relationships, it will be like this:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bcdb4ace-1186-4147-839c-019e8f1fa69a" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;next_to(X, Y, List) :- iright(X, Y, List).&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;next_to(X, Y, List) :- iright(Y, X, List).&lt;/li&gt; &lt;li&gt;iright(L, R, [L | [R | _]]).&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;iright(L, R, [_ | Rest]) :- iright(L, R, Rest).&lt;/li&gt; &lt;li&gt;einstein(Houses, Fish_Owner) :-&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;=(Houses, [[house, norwegian, _, _, _, _], _, [house, _, _, _, milk, _], _, _]),&lt;/li&gt; &lt;li&gt;member([house, brit, _, _, _, red], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;member([house, swede, dog, _, _, _], Houses),&lt;/li&gt; &lt;li&gt;member([house, dane, _, _, tea, _], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;iright([house, _, _, _, _, green], [house, _, _, _, _, white], Houses),&lt;/li&gt; &lt;li&gt;member([house, _, _, _, coffee, green], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;member([house, _, bird, pallmall, _, _], Houses),&lt;/li&gt; &lt;li&gt;member([house, _, _, dunhill, _, yellow], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;next_to([house, _, _, dunhill, _, _], [house, _, horse, _, _, _], Houses),&lt;/li&gt; &lt;li&gt;member([house, _, _, _, milk, _], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;next_to([house, _, _, marlboro, _, _], [house, _, cat, _, _, _], Houses),&lt;/li&gt; &lt;li&gt;next_to([house, _, _, marlboro, _, _], [house, _, _, _, water, _], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;member([house, _, _, winfield, beer, _], Houses),&lt;/li&gt; &lt;li&gt;member([house, german, _, rothmans, _, _], Houses),&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;next_to([house, norwegian, _, _, _, _], [house, _, _, _, _, blue], Houses),&lt;/li&gt; &lt;li&gt;member([house, Fish_Owner, fish, _, _, _], Houses).&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Then if you ask prolog this question:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8995a16e-c4c0-4d1f-befc-bc1f4e54ecdd" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;?- einstein(Houses, Fish_Owner).&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;You will have the right solution, try to use your mind to solve it and correct it with Prolog solution, if your answer not German, so you are Candidate to join the 98% club. It is not so bad :)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-6124503473676310426?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/6124503473676310426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/introduction-to-prolog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6124503473676310426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6124503473676310426'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/introduction-to-prolog.html' title='Introduction to Prolog'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-6402815542757796787</id><published>2009-11-01T03:21:00.002+03:00</published><updated>2009-11-01T03:29:13.722+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Physical Computing'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Parallel Port'/><title type='text'>Control Physical World Through Computer (Step by Step) - Part 3/3</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;h2&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style="color:#990000;"&gt;Second Example, Driving Remote Control Car&lt;/span&gt;&lt;/h2&gt;&lt;br&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;What we will need?&lt;/span&gt;&lt;/h3&gt;&lt;ul&gt;&lt;ol&gt;Remote Control Car.&lt;/ol&gt;&lt;ol&gt;Relay.&lt;/ol&gt;&lt;ol&gt;Transistor and Buffer (for security purpose only).&lt;/ol&gt;&lt;ol&gt;Some wires. &lt;/ol&gt;&lt;/ul&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;Start&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Again we will use the same concept; we will use Relay to control the power from the remote control.&lt;/p&gt;&lt;p&gt;If we try to open and remote, we will find this structure:&lt;br&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzUmvWirGI/AAAAAAAAAZM/XpHQnl9DadY/s1600-h/coolcode21%5B2%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="coolcode21" border="0" alt="coolcode21" src="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzUniSW-nI/AAAAAAAAAZQ/iD8uSGAG5eU/coolcode21_thumb.gif?imgmax=800" width="244" height="230" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;If terminal (1) touches up terminal (2) it will go forward, (5) for left and so one. &lt;/p&gt;&lt;p&gt;That is what we can do using Relay. See this figure: &lt;/p&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzUoxzgbYI/AAAAAAAAAZU/BFjQQurm3iI/s1600-h/coolcode22%5B2%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="coolcode22" border="0" alt="coolcode22" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzUpoY0PhI/AAAAAAAAAZY/AJ1mPp7WW2Q/coolcode22_thumb.gif?imgmax=800" width="228" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;And that is all. Now, start implementing your application to close and open pins.&lt;/p&gt;&lt;p&gt;The only new thing is if you want to use keyboard keys, make keyPreview property of form to (True).&lt;/p&gt;&lt;p&gt;And write down this code in Form_KeyDown event: &lt;/p&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;if (e.KeyValue.ToString() == "37") &lt;p&gt;// left&lt;/p&gt;&lt;p&gt;else if (e.KeyValue.ToString() == "38") &lt;/p&gt;&lt;p&gt;// up &lt;/p&gt;&lt;p&gt;else if (e.KeyValue.ToString() == "39") &lt;/p&gt;&lt;p&gt;// right &lt;/p&gt;&lt;p&gt;else if (e.KeyValue.ToString() == "40") &lt;/p&gt;&lt;p&gt;// down &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;p&gt;&lt;/p&gt;&lt;/tbody&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;There are more complex remotes which allow you to control speed, break... etc.&lt;/p&gt;&lt;p&gt;But the general idea is the same. &lt;/p&gt;&lt;h2&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style="color:#660000;"&gt;More Applications&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style="color:#660000;"&gt;&lt;/span&gt;&lt;/h2&gt;&lt;br&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;Introduction to Robots&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;In this part, we will try to explain simply what what the meaning of robot is. And how can we start implement small robot. &lt;/p&gt;&lt;p&gt;First of all, the robot is not only this kind of machine which is very similar to human body and face, the Robots is any machine with those 5 parts: &lt;/p&gt;&lt;ul&gt;&lt;ol&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;Body structure:&lt;/span&gt;&lt;/b&gt; Whatever this structure is, but it is very important because it will affect the operation that it should perform.&lt;/ol&gt;&lt;ol&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;Muscle:&lt;/span&gt;&lt;/b&gt; Motors as an example.&lt;/ol&gt;&lt;ol&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;Sensor system:&lt;/span&gt;&lt;/b&gt; Instead of eyes and ear in humans, it maybe any kind of sensors or cameras.&lt;/ol&gt;&lt;ol&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;Brain:&lt;/span&gt;&lt;/b&gt; The group of functions which will handle the robots while performing its operation, it could be Microcontroller, or for simple use it can be your computer with cables (or wireless) commands to your robot.&lt;/ol&gt;&lt;ol&gt;&lt;b&gt;&lt;span style="color:#ff0000;"&gt;Power supply:&lt;/span&gt;&lt;/b&gt; Battery instead of food or whatever in humans.&lt;/ol&gt;&lt;/ul&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;Start Work&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Our simple robot mission is to detect the blue line on the ground and move on it.&lt;/p&gt;&lt;p&gt;We can use the same RC car that we have, we can use its body and motors as our body structure, muscles. And its battery as power supply.&lt;/p&gt;&lt;p&gt;Bring any webcam and put it in the front of the car, it will be our sensor system.&lt;/p&gt;&lt;p&gt;In our application, we will have simple &lt;a href="http://www.emgu.com/wiki/index.php/Shape_(Triangle,_Rectangle,_Circle,_Line)_Detection_in_CSharp"&gt;Image Processing Code&lt;/a&gt; to read the video from webcam, read image by image from it, and detect the blue line, depends on that it will start drive right or left.&lt;/p&gt;&lt;p&gt;And that is our brain.&lt;/p&gt;&lt;p&gt;That was the simplest robot, it is good as beginning.&lt;/p&gt;&lt;p&gt;This is and advanced version, with microcontroller instead of connecting to computer, and motional camera: &lt;br&gt;&lt;a href="http://www.youtube.com/watch?v=Shkur2WrWgA"&gt;http://www.youtube.com/watch?v=Shkur2WrWgA&lt;/a&gt; &lt;/p&gt;&lt;h2&gt;&lt;span style="color:#660000;"&gt;Attached Files&lt;/span&gt;&lt;/h2&gt;&lt;ul class="download"&gt;&lt;li&gt;&lt;a href="http://www.vb4arab.com/vb/uploaded/3/01257034791.zip"&gt;Download demo project - XXX Kb &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.vb4arab.com/vb/uploaded/3/11257034791.zip"&gt;Download source - XXX Kb&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;The demo of this application is based in the application provided in this article: &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/cs/csppleds.aspx"&gt;http://www.codeproject.com/KB/cs/csppleds.aspx&lt;/a&gt; &lt;/p&gt;&lt;p&gt;But with more feature, you can open or close by the pin checkbox.&lt;/p&gt;&lt;p&gt;You can also run timer which provide different scenarios of opening/closing pins.&lt;/p&gt;&lt;p&gt;And if you have a seven segment, you can use it to count, it is contains seven segment equations.&lt;/p&gt;&lt;p&gt;And it is contains also the new inpout32.dll library. &lt;/p&gt;&lt;h2&gt;&lt;span style="color:#990000;"&gt;Conclusion&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Please if you find any mistake just inform me, and sorry for any mistake, I am not an electronic specialist.&lt;/p&gt;&lt;p&gt;Thanks. That it is all :)&lt;/p&gt;&lt;p&gt;This Article was provided before with Arabic &lt;a href="http://vb4arab.com/vb/showthread.php?t=13918"&gt;Here&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-6402815542757796787?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/6402815542757796787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/control-physical-world-through-computer_9634.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6402815542757796787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6402815542757796787'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/control-physical-world-through-computer_9634.html' title='Control Physical World Through Computer (Step by Step) - Part 3/3'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_FUmkjQ7foTw/SuzUniSW-nI/AAAAAAAAAZQ/iD8uSGAG5eU/s72-c/coolcode21_thumb.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-6043999956360827234</id><published>2009-11-01T02:55:00.002+03:00</published><updated>2009-11-01T03:30:52.510+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Physical Computing'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Parallel Port'/><title type='text'>Control Physical World Through Computer (Step by Step) - Part 2/3</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;h3&gt;&lt;span style="color: #000099"&gt;4- Tools&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;To start dealing with hardware, it is better if you have some tools to help you, such as &lt;/p&gt;  &lt;h4&gt;&lt;span style="color: #ff6600"&gt;Breadboard:&lt;/span&gt;&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzN_OrB5oI/AAAAAAAAAXk/2-DCHYKuQUQ/s1600-h/coolcode6%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode6" border="0" alt="coolcode6" src="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOAfOLmLI/AAAAAAAAAXo/xA-_nopqoiQ/coolcode6_thumb.gif?imgmax=800" width="204" height="145" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It will help you to put your wires and pins; it contains connected line (5 pins for example) with the same value so you can read it from many places. &lt;/p&gt;&lt;br&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br&gt;  &lt;h4&gt;&lt;span style="color: #ff6600"&gt;Adapter&lt;/span&gt;&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOBYVHjDI/AAAAAAAAAXs/LcSgyYsbIjA/s1600-h/coolcode7%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode7" border="0" alt="coolcode7" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzOCIeCgLI/AAAAAAAAAXw/xTEXAxm0Vzg/coolcode7_thumb.gif?imgmax=800" width="154" height="150" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As we know, any digital device will need a VCC and Ground to work, any adapter will give you this, and it will be better if it comes with voltage controller (some devices needs more or less voltage). &lt;/p&gt;  &lt;h4&gt;&lt;span style="color: #ff6600"&gt;Regulator&lt;/span&gt;&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzODClzPkI/AAAAAAAAAX0/NaaAaAgdjcY/s1600-h/coolcode8%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode8" border="0" alt="coolcode8" src="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzODx1-yqI/AAAAAAAAAX4/8BeVpcFXpL8/coolcode8_thumb.gif?imgmax=800" width="204" height="112" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It is just to keep fixed voltage even if the voltage goes up, for example you can have 5V Regulator to give you 5V even if you use 9V battery. &lt;/p&gt;  &lt;h4&gt;&lt;span style="color: #ff6600"&gt;Sample of Output Devices&lt;/span&gt;&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;&lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/Seven-segment_display"&gt;Seven Segment:&lt;/a&gt;&lt;/b&gt; Represent Numbers using 8 LEDs.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/Buzzer"&gt;Buzzer:&lt;/a&gt;&lt;/b&gt; Alarm instead of light in LED. &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/Display_device"&gt;Screen:&lt;/a&gt;&lt;/b&gt; Advanced Screens using the same concept of seven segment.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/Stepper_motors"&gt;Stepper Motors:&lt;/a&gt;&lt;/b&gt; Controlling Movement in the motor using digital signals.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;&lt;span style="color: #ff6600"&gt;Sample of Input Devices&lt;/span&gt;&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;&lt;b&gt;KeyPad:&lt;/b&gt; Convert numbers or characters to binary digits.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;b&gt;Sensors:&lt;/b&gt; Fire Sensors, light sensors, water... etc which send custom signal when some physical event happen.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;&lt;span style="color: #ff6600"&gt;Sample of Controlling Devices&lt;/span&gt;&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;&lt;b&gt;Buffer:&lt;/b&gt; Allow Signal to move whatever it is if the controller pin is equal to (One).&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/Relay"&gt;Relay:&lt;/a&gt;&lt;/b&gt; The same as buffer, but it can deal with 110/240V.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;b&gt;&lt;a href="http://en.wikipedia.org/wiki/Microcontroller"&gt;Microcontroller:&lt;/a&gt;&lt;/b&gt; Advanced Electronic Board, consists of multiple input, output and processing controls.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;&lt;span style="color: #990000"&gt;Relay and Controlling Electric Devices&lt;/span&gt;&lt;/h2&gt;  &lt;p&gt;By the end of this part, you must be able to control any electric device in your home. The general idea with any electric device is very simple, you have plugged cable to the power, if you cut the cable the device will switched off, if you reconnect it again it will work. &lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOElqeBQI/AAAAAAAAAX8/Kp7lBh7AXzk/s1600-h/coolcode11%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode11" border="0" alt="coolcode11" src="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOFYmz3dI/AAAAAAAAAYA/0dzORRn8VZg/coolcode11_thumb%5B1%5D.gif?imgmax=800" width="398" height="194" /&gt;&lt;/a&gt; &lt;/p&gt; What we will try to do is just to put some controls, which will allow electricity to move or not depends on some value we will read it from computer. This Control as we said before can be Relay.   &lt;p align="center"&gt;&lt;a href="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzOGAdhDyI/AAAAAAAAAYE/U_ABj6UHUxU/s1600-h/coolcode12%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode12" border="0" alt="coolcode12" src="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzOHA13GeI/AAAAAAAAAYI/cwpmdSFMx00/coolcode12_thumb%5B2%5D.gif?imgmax=800" width="395" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;&lt;span style="color: #000099"&gt;Example&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;There are many types of relay, each relay comes with its one datasheet, and we will choose one and explain using his datasheet. &lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzOITYc6nI/AAAAAAAAAYM/K1tUWa8Z-XY/s1600-h/coolcode13%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode13" border="0" alt="coolcode13" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzOJZ497qI/AAAAAAAAAYQ/Oy-UNCD5KYk/coolcode13_thumb%5B1%5D.gif?imgmax=800" width="415" height="247" /&gt;&lt;/a&gt; &lt;/p&gt; In our relay we have 2 pins for controlling, and 3 pins in each side, when the control is (One) it will move the power from pin (1) to (3) in each side, else it will connect pin (1) to (2). This is how it will response:   &lt;p align="center"&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOKdMbtUI/AAAAAAAAAYU/5SMxdN4ScIA/s1600-h/coolcode14%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode14" border="0" alt="coolcode14" src="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzOLLU1t-I/AAAAAAAAAYY/Gmzg2ER1V-M/coolcode14_thumb%5B1%5D.gif?imgmax=800" width="306" height="306" /&gt;&lt;/a&gt; &lt;/p&gt; There are some other types. This is one sample of it:   &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzOLpflp8I/AAAAAAAAAYc/5QydttduGgY/s1600-h/coolcode19%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode19" border="0" alt="coolcode19" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzOMbdJTyI/AAAAAAAAAYg/LlOnhdm_WRc/coolcode19_thumb.gif?imgmax=800" width="169" height="244" /&gt;&lt;/a&gt; &lt;/p&gt; Now, back again to our work, we will use the relay instead of switch, and it will take the commands from pin2 form parallel port as VCC, and any ground (pin 25 as example):   &lt;p align="center"&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzONEicaNI/AAAAAAAAAYk/LEkfP9cHR1w/s1600-h/coolcode15%5B6%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode15" border="0" alt="coolcode15" src="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzOOBSffNI/AAAAAAAAAYo/_NOosZymnG0/coolcode15_thumb%5B2%5D.gif?imgmax=800" width="395" height="273" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now try to run your application again, and enjoy. Just as a reminder again, open visual studio, import new inpout32.dll and write down this declaration:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;table border="1" width="600"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;using System.Runtime.InteropServices[DllImport(&amp;quot;inpout32.dll&amp;quot;, EntryPoint=&amp;quot;Out32&amp;quot;)]public static extern void Output(int adress, int value);&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And to open the first data pin:&lt;/p&gt;  &lt;table border="1" width="600"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;Output(888, 1);&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;For second pin type 2, third one is 4 and forth is 8 and so on. Now start implement any routine for that or for any electric device, open it through modem by calling, it is now just regular programming. &lt;/p&gt;  &lt;h3&gt;&lt;span style="color: #000099"&gt;Security&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;In the previous example, we were connecting out electric circle directly to our parallel port, which is not safe. We must use some security circle in the middle. For example, we can use buffer gate between our parallel port and electric device in this way: &lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzOO8FKWgI/AAAAAAAAAYs/P4EAlLLNVKA/s1600-h/coolcode16%5B9%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode16" border="0" alt="coolcode16" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzOPg3Y9HI/AAAAAAAAAYw/iwb4k5T2eQA/coolcode16_thumb%5B3%5D.gif?imgmax=800" width="320" height="217" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;But we will face a problem that the output ampere from buffer will not be enough to deal with the relay, so we will add transistor to pass the power, and we will take outside VCC source to the relay: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOQb2nzqI/AAAAAAAAAY0/irjgDRwXaFc/s1600-h/coolcode17%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="coolcode17" border="0" alt="coolcode17" src="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzORvdz7tI/AAAAAAAAAY4/ieOCLDrD1dM/coolcode17_thumb%5B1%5D.gif?imgmax=800" width="437" height="255" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;&lt;span style="color: #000099"&gt;Simplify&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;As we observed in the last security circle, we will have a lot of wires. And in real application, it will be very difficult to handle all of this in safe way. As a solution, electronic manufactories provide us something called (Parallel Port Interface). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzOSbQSsMI/AAAAAAAAAY8/nR-8z15t1mc/s1600-h/coolcode18%5B7%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode18" border="0" alt="coolcode18" src="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOTYRPcyI/AAAAAAAAAZA/4TqqkqUUQu4/coolcode18_thumb%5B3%5D.gif?imgmax=800" width="247" height="186" /&gt;&lt;/a&gt; &lt;/p&gt; This board consists of 8 relays with security circle, it will need only one General VCC and one Ground, and controls for each relay. It will work directly.   &lt;h3&gt;&lt;span style="color: #000099"&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style="color: #000099"&gt;Algorithms&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;Sometime we will need to deal with more than 8 devices. For that purpose and other needs, we need to start reading about other gates. In this example, we will try to Control 8 devices using only 3 pins. for this purpose we will use &lt;a href="http://en.wikipedia.org/wiki/Decoder"&gt;Decoder&lt;/a&gt;. This is chart: &lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOTyEt4YI/AAAAAAAAAZE/7a7bFf_fDu8/s1600-h/coolcode20%5B7%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="coolcode20" border="0" alt="coolcode20" src="http://lh6.ggpht.com/_FUmkjQ7foTw/SuzOVDulzcI/AAAAAAAAAZI/23iO8wb22y4/coolcode20_thumb%5B3%5D.gif?imgmax=800" width="527" height="323" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-6043999956360827234?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/6043999956360827234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/control-physical-world-through-computer_01.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6043999956360827234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6043999956360827234'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/control-physical-world-through-computer_01.html' title='Control Physical World Through Computer (Step by Step) - Part 2/3'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_FUmkjQ7foTw/SuzOAfOLmLI/AAAAAAAAAXo/xA-_nopqoiQ/s72-c/coolcode6_thumb.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-2328540431640613988</id><published>2009-11-01T02:31:00.003+03:00</published><updated>2009-11-01T03:32:29.491+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Physical Computing'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Parallel Port'/><title type='text'>Control Physical World Through Computer (Step by Step) - Part 1/3</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;h2&gt;&lt;span style="color:#cc0000;"&gt;Introduction&lt;/span&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style="color:#cc0000;"&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2 align="center"&gt;&lt;a href="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzIlRTZQWI/AAAAAAAAAW8/BT4p7YPeJso/s1600-h/coolcode1%5B3%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title="coolcode1" border="0" alt="coolcode1" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzIoPGODCI/AAAAAAAAAXA/mZV6NVMCu_k/coolcode1_thumb%5B1%5D.gif?imgmax=800" width="403" height="308" /&gt;&lt;/a&gt;&lt;/h2&gt;&lt;h2&gt;&lt;/h2&gt;&lt;p&gt;In this article, we will take the first step inside physical computing world.&lt;/p&gt;&lt;p&gt;Physical Computing, in the broadest sense, means building interactive physical systems by the use of software and hardware that can sense and respond to the analog world. In physical computing, we take the human body as a given, and attempt to design within the limits of its expression. (&lt;a href="http://en.wikipedia.org/wiki/Physical_computing"&gt;Wikipedia Definition&lt;/a&gt;) &lt;/p&gt;&lt;h2&gt;&lt;span style="color:#cc0000;"&gt;Background&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;To be able to understand this article, those things must be clear for you: &lt;/p&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;1- Binary System&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;As we all know, the only understandable commands for any computer is the (On/Off) power commands which represented as 0 and 1.&lt;/p&gt;&lt;p&gt;And for those two commands, we have only three logical operators. They are (AND, OR and NOT). &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;And: 1 AND 1 is 1, anything else is equal to Zero. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;OR: 0 OR 0 is 0, anything else is equal to One. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Not: Not 1 is Zero, Not 0 is One.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Those three operators are implemented using &lt;a href="http://en.wikipedia.org/wiki/Transistor"&gt;transistors&lt;/a&gt; so they will be able to deal with electricity and give the result.&lt;/p&gt;&lt;p&gt;After that, we have started implementing many functions using those three operators. And collecting them in some electric circles called gates, using those only we are able to build what we call as &lt;a href="http://en.wikipedia.org/wiki/Integrated_circuit"&gt;IC&lt;/a&gt; which can perform more complex operations to the data, and for storage also using the concept of &lt;a href="http://en.wikipedia.org/wiki/Flip-flop_(electronics)"&gt;flip flops&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;You don't need to understand all of this, but at least you must understand the general points of how we can build computer using only (0 and 1). &lt;/p&gt;&lt;br&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;2- Numerical System&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;As we said in previous section, we must represent our data using 0 and 1. We called it binary system.&lt;/p&gt;&lt;p&gt;So everything later must be converted to 0 and 1. Let us see how to represent our numbers (decimal number system), characters and symbols using this system.&lt;/p&gt;&lt;p&gt;For Example, this number (110101):&lt;/p&gt;&lt;p&gt;when we try to extract it to our decimal system, we can say it is:&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;(2^0*1)+(2^1*0)+(2^2*1)+(2^3*0)+(2^4*1)+(2^5*1) = 1+0+4+0+16+32=53.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;For letters and symbols will find some encoding system such as &lt;a href="http://en.wikipedia.org/wiki/ASCII"&gt;ASCII&lt;/a&gt; which represent any single characters in 8 bit, for example it represent number (2) in this way (011 0010), (A) is (100 0001) and (/) is (010 1111). &lt;/p&gt;&lt;h3&gt;&lt;span style="color:#000099;"&gt;3- Computer Ports&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;To start dealing with any external device, you must use one of computer ports to send your signals. &lt;/p&gt;&lt;p&gt;Here are examples of computer ports: &lt;/p&gt;&lt;h4&gt;&lt;span style="color:#ff6600;"&gt;Serial Port&lt;/span&gt;&lt;/h4&gt;&lt;p&gt; &lt;a href="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzIpCAW_pI/AAAAAAAAAXE/xACbW02qOaQ/s1600-h/coolcode2%5B2%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="coolcode2" border="0" alt="coolcode2" src="http://lh4.ggpht.com/_FUmkjQ7foTw/SuzIp25sEZI/AAAAAAAAAXI/L7oQnBWqECA/coolcode2_thumb.gif?imgmax=800" width="204" height="107" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;One of the oldest computer ports. It was used to connect external modem to the computer. It is sending 1 byte (8 bit) in each time. &lt;/p&gt;&lt;h4&gt;&lt;span style="color:#ff6600;"&gt;USB Port&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzIqk9qwDI/AAAAAAAAAXM/BrXnrvKRm6A/s1600-h/coolcode3%5B2%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="coolcode3" border="0" alt="coolcode3" src="http://lh3.ggpht.com/_FUmkjQ7foTw/SuzIrLXCcVI/AAAAAAAAAXQ/Jrd2YKRAlKM/coolcode3_thumb.gif?imgmax=800" width="204" height="95" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;The most famous computer port. Most of new devices now are coming with USB port support.&lt;/p&gt;&lt;p&gt;With &lt;a href="http://en.wikipedia.org/wiki/USB"&gt;USB&lt;/a&gt; you can connect up to 127 device, you will have hot-swappable property so you will be able to have (Plug-in and Play). And with up to 480 MB/second speed in USB 2.0.&lt;/p&gt;&lt;p&gt;USB comes with only 4 wires, two for VCC/Ground, and the others for sending/receiving data. &lt;/p&gt;&lt;h4&gt;&lt;span style="color:#ff6600;"&gt;Parallel Port&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzIsHF0NhI/AAAAAAAAAXU/DvTXng-aiCs/s1600-h/coolcode4%5B2%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="coolcode4" border="0" alt="coolcode4" src="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzIszs1UuI/AAAAAAAAAXY/c5ppCP0rIh0/coolcode4_thumb.gif?imgmax=800" width="204" height="154" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;This is the port that we will use it in our examples, because it is the easiest one to deal with for the beginners.&lt;/p&gt;&lt;p&gt;You can find a very good article about it written by &lt;a href="http://www.codeproject.com/Members/Levent-Saltuklaroglu"&gt;Levent Saltuklaroglu&lt;/a&gt;: &lt;a href="http://www.codeproject.com/KB/cs/csppleds.aspx"&gt;http://www.codeproject.com/KB/cs/csppleds.aspx&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Anyway, we will try to explain it one time again here.&lt;/p&gt;&lt;p&gt;Parallel port consists of 25 visible pens: &lt;/p&gt;&lt;p align="center"&gt; &lt;a href="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzIuNWYIrI/AAAAAAAAAXc/PLvKyARhUsE/s1600-h/coolcode5%5B3%5D.gif"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="coolcode5" border="0" alt="coolcode5" src="http://lh5.ggpht.com/_FUmkjQ7foTw/SuzIvPzEiuI/AAAAAAAAAXg/ssIRmQkgQOw/coolcode5_thumb%5B1%5D.gif?imgmax=800" width="475" height="255" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#ff0000;"&gt;1, 14, 16 and 17: Control Pins, you can use them for both input and output. &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#ff0000;"&gt;2-9: Data Pins, you can use them to send data outside (output). &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#ff0000;"&gt;10-13 and 15: Status Pins, used for reading data (Input). &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#ff0000;"&gt;18-25: Ground Pins.&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;To start sending data through Parallel Port, you must have:&lt;br /&gt;&lt;ul&gt;&lt;ol&gt;&lt;span style="color:#ff0000;"&gt;Kernel Mode Driver: such as inpout32.dll for windows users. &lt;/span&gt;&lt;/ol&gt;&lt;ol&gt;&lt;span style="color:#ff0000;"&gt;We will select C# as a programming language. You can select any.&lt;/span&gt;&lt;/ol&gt;&lt;ol&gt;&lt;span style="color:#ff0000;"&gt;Any device which we can show some data through, the simplest one is &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/LED"&gt;&lt;span style="color:#ff0000;"&gt;LED&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#ff0000;"&gt; &lt;/span&gt;&lt;/ol&gt;&lt;/ul&gt;Now just take one LED, connect its positive pin to port number 2, and its negative one to any ground, and then open your visual studio any version, import inpout32.dll in this way:&lt;br /&gt;&lt;br /&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;[DllImport("inpout32.dll", EntryPoint="Out32")] &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Then declare this function:&lt;br /&gt;&lt;br /&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;public static extern void Output(int adress, int value);&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;Finally, write some code like this in any button to open first pin: &lt;/p&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Output(888, 1);&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;*** Hint:&lt;/b&gt; (888) is the Parallel Port Number, you can make sure from Device Manager-&amp;gt;COM Ports-&amp;gt;Parallel Port -&amp;gt;Resources-Resources Setting, may you will find it as &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Hexadecimal"&gt;&lt;span style="color:#ff0000;"&gt;hexadecimal&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#ff0000;"&gt;, just convert it using your windows calculator. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;*** &lt;/b&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;Another Hint:&lt;/b&gt; Some time your inpout32.dll will gives you an error, use the one in the example.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-2328540431640613988?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/2328540431640613988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/control-physical-world-through-computer.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/2328540431640613988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/2328540431640613988'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/11/control-physical-world-through-computer.html' title='Control Physical World Through Computer (Step by Step) - Part 1/3'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_FUmkjQ7foTw/SuzIoPGODCI/AAAAAAAAAXA/mZV6NVMCu_k/s72-c/coolcode1_thumb%5B1%5D.gif?imgmax=800' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-2834309860431661239</id><published>2009-10-31T20:14:00.007+03:00</published><updated>2009-11-01T01:59:44.340+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips and Tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>StringBuilder</title><content type='html'>&lt;br&gt;&lt;br&gt;Most of us when we concat any strings, we are using (+) operator (or &amp;amp; in vb.net) this way:&lt;br /&gt;&lt;br /&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;// C#&lt;br /&gt;Label1.Text = Text1.Text + "@hotmail.com";&lt;br /&gt;// Vb.net&lt;br /&gt;Label1.Text = Text1.Text &amp;amp; "@hotmail.com"&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;But .net framework provides us another way to concat strings, using StringBuilder which is under System.Text name space, this is how to use:&lt;br /&gt;&lt;br /&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;//C#:&lt;br /&gt;System.Text.StringBuilder mail = New System.Text.StringBuilder(Text1.Text);&lt;br /&gt;mail.Append("@hotmail.com");&lt;br /&gt;'VB.net:&lt;br /&gt;Dim mail As New System.Text.StringBuilder(Text1.Text)&lt;br /&gt;mail.Append("@hotmail.com")&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#cc0000;"&gt;What is the difference?&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;When using (+,&amp;amp;), new object will initialized every time we use this operator. But with StringBuilder, we will use the same object.&lt;br /&gt;&lt;br /&gt;From Net Gotachas book, the auther(&lt;em&gt;&lt;span style="color:#009900;"&gt;Venka&lt;/span&gt;&lt;/em&gt;) assume simple concat operations within loop. And he run the loop using different maximum values of loops. This is snap shoot from the book representing the execution time:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 276px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5398814178419036242" border="0" alt="" src="http://1.bp.blogspot.com/_FUmkjQ7foTw/Suxw5CECUFI/AAAAAAAAAWk/OaYPKQiyXmY/s400/01202903132.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;3562.933 second is equal to 59.4 minutes. So will you still use (+,&amp;amp;)?&lt;br /&gt;&lt;br /&gt;Finaly, StringBuilder gives us another operations such as Replace, Insert and Remove, you can find all about it with a graphs represent the diferent from this article in CodeProject:&lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/cs/StringBuilder_vs_String.aspx"&gt;http://www.codeproject.com/KB/cs/StringBuilder_vs_String.aspx&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-2834309860431661239?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/2834309860431661239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/10/stringbuilder.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/2834309860431661239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/2834309860431661239'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/10/stringbuilder.html' title='StringBuilder'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_FUmkjQ7foTw/Suxw5CECUFI/AAAAAAAAAWk/OaYPKQiyXmY/s72-c/01202903132.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-5616243624882698781</id><published>2009-10-31T19:30:00.003+03:00</published><updated>2009-11-01T02:00:16.615+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips and Tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Different Between Const and static readonly</title><content type='html'>&lt;br&gt;&lt;br&gt;Declaring with const or static readonly will give the same result, we will have uneditable variable.&lt;br /&gt;&lt;br /&gt;The only one difference is that (const) must take its value at compile time, but (static readonly) will take its value in run time.&lt;br /&gt;&lt;br /&gt;so we can get more benefit from static readonly by declare it in static constructor:&lt;br /&gt;&lt;br /&gt;&lt;table border="1" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt;public static readonly Test test = new Test();&lt;br /&gt;&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;test.Name = "Program";&lt;br /&gt;}&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-5616243624882698781?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/5616243624882698781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/10/different-between-const-and-static.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/5616243624882698781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/5616243624882698781'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2009/10/different-between-const-and-static.html' title='Different Between Const and static readonly'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-7632876896181759942</id><published>2008-08-25T17:42:00.011+03:00</published><updated>2009-11-01T02:00:41.249+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.net'/><category scheme='http://www.blogger.com/atom/ns#' term='WAP'/><title type='text'>Introduction To WAP</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Introduction:&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;Through this topic we will work together to understand Technology of Wireless Application Protocol (WAP), also we will take a fast tour about developing WAP Applications using ASP.net.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Technology Description:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Mobile Application :&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;When First Mobile arrived, it was only smart way for sending and receiving voice calls and after sometime for sending and receiving text messages. But now, it is become the most growing market for services and recreational purposes. It is also being used for accessing internet and multimedia world.&lt;/p&gt;&lt;p&gt;For this reason, a lot of developing and programming concepts changed to become compatible with mobile world, one of these concepts was WAP as a mobile alternative of WEB concepts for regular computers.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is WAP ؟ &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;From Wikipedia, WAP is an open international standard for application layer network communications in a wireless communication environment. Its main use is to enable access to the Internet (HTTP) from a mobile phone or PDA. &lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;How it Work ؟ &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The Biggest different between WAP and WEB is that WAP able to work through less capabilities and slow speed in comapre with the configuration of regular computers.&lt;/p&gt;&lt;p&gt;WAP starts since an order come from mobile customer, it is convert HTML page to WML pages that is able to browsing through mobiles.&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;What is WML ؟&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;It is description language very similar to HTML tags, it have only some few different:&lt;/p&gt;&lt;p&gt;- The main Tag is &amp;lt;wml&amp;gt; instead of &amp;lt;html&amp;gt;.&lt;/p&gt;&lt;p&gt;- Documents splits to &amp;lt;card&amp;gt;&amp;lt;/cards&amp;gt;. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Introduction To WML:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;This is sample from Wiki about WML document:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN"&lt;br /&gt;"&lt;a href="http://www.phone.com/dtd/wml11.dtd"&gt;http://www.phone.com/dtd/wml11.dtd"&lt;/a&gt; &amp;gt;&lt;br /&gt;&amp;lt;wml&amp;gt;&lt;br /&gt;&amp;lt;card id="main" title="First Card"&amp;gt;&lt;br /&gt;&amp;lt;p mode="wrap"&amp;gt;This is a sample WML page.&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/card&amp;gt;&lt;br /&gt;&amp;lt;/wml&amp;gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Reading and Writing Variables in WML:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;setvar name="First_Name" value="Ahmed"/&amp;gt;&lt;br /&gt;&amp;lt;setvar name="Age" value="21"/&amp;gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Later you can display it like that:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;p&amp;gt;First Name: $(First_Name)&amp;lt;/p&amp;gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You can also read textbox value with the same way:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;card id="card1" title="Tutorial"&amp;gt;&lt;br /&gt;&amp;lt;do type="accept" label="Answer"&amp;gt;&lt;br /&gt;&amp;lt;go href="#card2"/&amp;gt;&lt;br /&gt;&amp;lt;/do&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;&amp;lt;select name="name"&amp;gt;&lt;br /&gt;&amp;lt;option value="HTML"&amp;gt;HTML Tutorial&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="XML"&amp;gt;XML Tutorial&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;option value="WAP"&amp;gt;WAP Tutorial&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/select&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/card&amp;gt;&lt;br /&gt;&amp;lt;card id="card2" title="Answer"&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;You selected: $(name)&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/card&amp;gt;&lt;br /&gt;&amp;lt;/wml&amp;gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;ASP.net Application using WAP:&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Do you remember our first WAP Application in this topic?&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN"&lt;br /&gt;"&lt;a href="http://www.phone.com/dtd/wml11.dtd"&gt;http://www.phone.com/dtd/wml11.dtd"&lt;/a&gt; &amp;gt;&lt;br /&gt;&amp;lt;wml&amp;gt;&lt;br /&gt;&amp;lt;card id="main" title="First Card"&amp;gt;&lt;br /&gt;&amp;lt;p mode="wrap"&amp;gt;This is a sample WML page.&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/card&amp;gt;&lt;br /&gt;&amp;lt;/wml&amp;gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you want to use it through ASP.net, you have to convert it to something like that:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %&amp;gt;&lt;br /&gt;&amp;lt;%@ Register TagPrefix="mobile" Namespace="System.Mobile.UI" %&amp;gt;&lt;br /&gt;&amp;lt;mobile:Form runat="server"&amp;gt;&lt;br /&gt;&amp;lt;mobile:Label runat="server"&amp;gt;&lt;br /&gt;This is a sample WML page.&lt;br /&gt;&amp;lt;/mobile:Label&amp;gt;&lt;br /&gt;&amp;lt;/Mobile:Form&amp;gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you want to work through VB.net instead of C#, just modify the first line like that:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&amp;lt;%@ Page Inherits="System.Mobile.UI.MobilePage" Language="C#" %&amp;gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;br /&gt;And now, if your web site ordered from PC, the response will contain HTML tags, if it is ordered from Mobile, the response will contains WML tags.&lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-7632876896181759942?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/7632876896181759942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/08/introduction-to-wap_25.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/7632876896181759942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/7632876896181759942'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/08/introduction-to-wap_25.html' title='Introduction To WAP'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-7456551318526617114</id><published>2008-08-24T01:32:00.003+03:00</published><updated>2009-11-01T02:01:16.701+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WPF'/><category scheme='http://www.blogger.com/atom/ns#' term='Expression Blend'/><title type='text'>Expression Blend</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;When WPF - the new .net technology- arrived, Microsoft try to provide some tools makes life easy to WPF Developers, one of this tools was Expression Blend, we will try to show some features about it in this topic.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Try to download it form Microsoft web site, then run it and choose new Project - WPF Application (*.exe):&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/01214832040.jpg" width="414" height="275" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;You can now choose your name, folder and .net language you want.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;Click View-Active Document View then click split view to show both code and design view:&lt;/span&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/11214832040.jpg" width="410" height="258" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;In the left side, you will find all tools you need for your design including painting tools such as brushs and pens. You can find also .net components such as commandbuttons. You can also click the link to more item to show all tools:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/21214832040.jpg" width="419" height="233" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;While you are painting, you will find additional properties for each tool in the right side:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/31214832040.jpg" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Example:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Add new &amp;lt;canvas&amp;gt;, this will the container of our picture for this example:&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas&amp;gt;&lt;br /&gt;&amp;lt;Canvas x:Name="MainImageCanvas" Canvas.Left="40" Canvas.Top="120"&amp;gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Add new MediaElement to add a picture:&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;MediaElement x:Name="MainImage" Source="c:/example/futex.jpg" Width="300" Height="300" &amp;gt;&amp;lt;/MediaElement&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Now we will apply some effects through properties, this is an example of code results from some operations:&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="417"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="413"&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas.RenderTransform&amp;gt;&amp;lt;TransformGroup&amp;gt;&lt;br /&gt;&amp;lt;SkewTransform x:Name="MainSkewTransform" AngleY="-19" AngleX="0" CenterX="0" CenterY="0"/&amp;gt; &amp;lt;ScaleTransform x:Name="MainScaleTransform" ScaleY="1" ScaleX = "1" CenterX="0" CenterY="0"/&amp;gt;&amp;lt;/TransformGroup&amp;gt; &amp;lt;/Canvas.RenderTransform&amp;gt;&amp;lt;/Canvas&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Press F5 now, this is a snap shot of expected results:&lt;/span&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/41214832040.jpg" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;Now we will try to apply some shadow to the picture, so we will add &amp;lt;canvas&amp;gt; for a new picture object refer to the same file with new transformation parameters to make the second picture seems to be a shadow:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas x:Name="ReflectionImageCanvas" Canvas.Left="260" Canvas.Top="640"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg" Width="300" Height="300" Volume="0"&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/MediaElement&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas.RenderTransform&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;TransformGroup&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;SkewTransform x:Name="ReflectionSkewTransform" AngleY="19" AngleX="-41" CenterX="0" CenterY="0" /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1" ScaleX="1" CenterX="0" CenterY="0" /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/TransformGroup&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/Canvas.RenderTransform&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/Canvas&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Previous Code Result:&lt;/span&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/51214832040.jpg" width="402" height="465" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;Last topic in this lesson is to add some transparent to the shadow of picture through opacity property, the result XAML maybe like that:&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas x:Name="ReflectionImageCanvas" Canvas.Left="260" Canvas.Top="640"&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg" Width="300" Height="300" Volume="0"&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/MediaElement&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas.RenderTransform&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;TransformGroup&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;SkewTransform x:Name="ReflectionSkewTransform" AngleY="19" AngleX="-41" CenterX="0" CenterY="0" /&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1" ScaleX="1" CenterX="0" CenterY="0" /&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/TransformGroup&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/Canvas.RenderTransform&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas.OpacityMask&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;LinearGradientBrush StartPoint="0.5,0.0" EndPoint="0.5,1.0"&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;GradientStop Offset="0.345" Color="#00000000" x:Name="ReflGradientStop1" /&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;GradientStop Offset="1.0" Color="#CC000000" x:Name="ReflGradientStop2" /&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/LinearGradientBrush&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/Canvas.OpacityMask&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;/Canvas&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Now, you have to try to edit the position of shadow by changing top and left manually, the result must be something like that:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="center"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/01214832482.jpg" width="406" height="479" /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;Full XAML Code:&lt;/span&gt;&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody dir="ltr"&gt;&lt;tr&gt;&lt;td valign="top" width="396"&gt;&lt;span style="font-family:time;font-size:100%;"&gt;&amp;lt;Canvas&amp;gt;&lt;br /&gt;            &amp;lt;Canvas x:Name="MainImageCanvas" Canvas.Left="40" Canvas.Top="120"&amp;gt;&lt;br /&gt;&lt;br /&gt;                &amp;lt;MediaElement x:Name="MainImage" Source="c:/example/FUTEX.JPG" Width="300" Height="300" &amp;gt;&lt;br /&gt;                &amp;lt;/MediaElement&amp;gt;&lt;br /&gt;                &amp;lt;Canvas.RenderTransform&amp;gt;&lt;br /&gt;                    &amp;lt;TransformGroup&amp;gt;&lt;br /&gt;                        &amp;lt;SkewTransform x:Name="MainSkewTransform" AngleY="-19" AngleX="0" CenterX="0" CenterY="0"/&amp;gt;&lt;br /&gt;                        &amp;lt;ScaleTransform x:Name="MainScaleTransform" ScaleY="1" ScaleX = "1" CenterX="0" CenterY="0"/&amp;gt;&lt;br /&gt;                    &amp;lt;/TransformGroup&amp;gt;&lt;br /&gt;                &amp;lt;/Canvas.RenderTransform&amp;gt;&lt;br /&gt;            &amp;lt;/Canvas&amp;gt;&lt;br /&gt;            &amp;lt;Canvas x:Name="ReflectionImageCanvas" Canvas.Left="267" Canvas.Top="645"&amp;gt;&lt;br /&gt;                &amp;lt;MediaElement x:Name="ReflImage" Source="c:/example/futex.jpg" Width="300" Height="300" Volume="0"&amp;gt;&lt;br /&gt;                &amp;lt;/MediaElement&amp;gt;&lt;br /&gt;                &amp;lt;Canvas.RenderTransform&amp;gt;&lt;br /&gt;                    &amp;lt;TransformGroup&amp;gt;&lt;br /&gt;                        &amp;lt;SkewTransform x:Name="ReflectionSkewTransform" AngleY="19" AngleX="-41" CenterX="0" CenterY="0" /&amp;gt;&lt;br /&gt;                        &amp;lt;ScaleTransform x:Name="ReflectionScaleTransform" ScaleY="-1" ScaleX="1" CenterX="0" CenterY="0" /&amp;gt;&lt;br /&gt;                    &amp;lt;/TransformGroup&amp;gt;&lt;br /&gt;                &amp;lt;/Canvas.RenderTransform&amp;gt;&lt;br /&gt;                &amp;lt;Canvas.OpacityMask&amp;gt;&lt;br /&gt;                    &amp;lt;LinearGradientBrush StartPoint="0.5,0.0" EndPoint="0.5,1.0"&amp;gt;&lt;br /&gt;                        &amp;lt;GradientStop Offset="0.345" Color="#00000000" x:Name="ReflGradientStop1" /&amp;gt;&lt;br /&gt;                        &amp;lt;GradientStop Offset="1.0" Color="#CC000000" x:Name="ReflGradientStop2" /&amp;gt;&lt;br /&gt;                    &amp;lt;/LinearGradientBrush&amp;gt;&lt;br /&gt;                &amp;lt;/Canvas.OpacityMask&amp;gt;&lt;br /&gt;            &amp;lt;/Canvas&amp;gt;&lt;br /&gt;        &amp;lt;/Canvas&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;  &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;Don't forget that MediaElement can accept any type of media, try to attach video and see the result.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:time;font-size:100%;"&gt;Anyway, you can copy this XAML code to a WPF .net solution and the same result will apply to your form.&lt;/span&gt;&lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-7456551318526617114?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/7456551318526617114/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/08/expression-blend_6643.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/7456551318526617114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/7456551318526617114'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/08/expression-blend_6643.html' title='Expression Blend'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-8816207493323869085</id><published>2008-06-17T22:02:00.005+03:00</published><updated>2009-11-01T02:01:38.976+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tips and Tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>IComparable Interface.</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;p&gt;From The name, this Interface used for comparison. This is the implementation of this interface: &lt;/p&gt;&lt;p&gt;C#: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;public interface IComparable&lt;br /&gt;{&lt;br /&gt;int CompareTo(object o);&lt;br /&gt;} &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;vb.net: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;Public Interface IComparable&lt;br /&gt;Function CompareTo(ByVal o As Object) As Integer&lt;br /&gt;End Interface &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The result of this function is Integer; it returns 0 in similarity, -1 when the first one is smaller and 1 when larger . &lt;/p&gt;&lt;p&gt;Now we don't need to know who is larger, let’s assume that we have car class, something like that: &lt;/p&gt;&lt;p&gt;C#: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;&lt;p&gt;class Car&lt;br /&gt;{ &lt;/p&gt;&lt;p&gt;string Name;&lt;br /&gt;int year;&lt;br /&gt;} &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;vb.net: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;Class Car&lt;br /&gt;Private Name As String&lt;br /&gt;Private year As Integer&lt;br /&gt;End Class &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now we need to sort the cars depends on the creation year, our first step it to implement IComparable interface. &lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;C#:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;&lt;p&gt;class Car:IComparable&lt;br /&gt;{ &lt;/p&gt;&lt;p&gt;string Name;&lt;br /&gt;int year;&lt;br /&gt;} &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;br /&gt;vb.net: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;&lt;p&gt;class Car:IComparable&lt;br /&gt;{ &lt;/p&gt;&lt;p&gt;string Name;&lt;br /&gt;int year;&lt;br /&gt;} &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, we should write an implementation to CompareTo function, something like that: &lt;/p&gt;&lt;p&gt;c#: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;int IComparable.CompareTo(object obj)&lt;br /&gt;{&lt;br /&gt;Car temp = (Car)obj;&lt;br /&gt;if(this.year &amp;gt; temp.year)&lt;br /&gt;return 1;&lt;br /&gt;if(this.year &amp;lt; temp.year)&lt;br /&gt;return -1;&lt;br /&gt;else&lt;br /&gt;return 0;&lt;br /&gt;} &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;vb.net: &lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;Private Function CompareTo(ByVal obj As Object) As&lt;br /&gt;Integer Implements IComparable.CompareTo&lt;br /&gt;Dim temp As Car = DirectCast(obj, Car)&lt;br /&gt;If Me.year &amp;gt; temp.year Then&lt;br /&gt;Return 1&lt;br /&gt;End If&lt;br /&gt;If Me.year &amp;lt; temp.year Then&lt;br /&gt;Return -1&lt;br /&gt;Else&lt;br /&gt;Return 0&lt;br /&gt;End If&lt;br /&gt;End Function&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Anyway, -1 is equals to -100 in return value, this function work with any negative number referring to smaller, any positive number also is accepted instead of 1. &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Sort Function:&lt;/span&gt; &lt;/p&gt;&lt;p&gt;Assume we have array of numbers, in this case some code like that is applicable. &lt;/p&gt;&lt;p&gt;c#:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;Array.Sort(myNumbers); &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;vb.net:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;Array.Sort(myNumbers) &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;But if we have array of cars, this will cause error, except if we implementing IComparable interface. in this case the array.sort() will use CompareTo function to sort all array elements. This is better solution than using another function for check and sorting. It is also more readable for people who work with you or read your code. &lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-8816207493323869085?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/8816207493323869085/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/06/icomparable-interface_17.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/8816207493323869085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/8816207493323869085'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/06/icomparable-interface_17.html' title='IComparable Interface.'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-6563815948164796061</id><published>2008-06-05T15:16:00.004+03:00</published><updated>2009-11-01T02:02:03.831+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>FileSystemWatcher</title><content type='html'>&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;FileSystemWatcher Class is very benefit when trying to monitor some files and inform user or program when any change occurs, all events are listed in NotifyFilters enum, this is the list of events can be handled by this:&lt;/p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;public enum NotifyFilters {&lt;br /&gt;Attributes, CreationTime, DirectoryName, FileName, LastAccess, LastWrite, Security, Size,&lt;br /&gt;}&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;pre&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now we need to declare functions to be called when some event occurred, this function will run through this delegate:&lt;/p&gt;&lt;p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;void MyNotificationHandler(object source, FileSystemEventArgs e)&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Only rename event will run through this delegate:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;void MyNotificationHandler(object source, RenamedEventArgs e)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;Now we will start console application to monitor files, this application will run till user press q, this program will monitor all *.txt files in c:\ folder:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;C#:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;FileSystemWatcher watcher = new FileSystemWatcher();&lt;br /&gt;&lt;br /&gt;// monitor files at:&lt;br /&gt;watcher.Path = @"c:\";&lt;br /&gt;&lt;br /&gt;// monitor files when&lt;br /&gt;watcher.NotifyFilter = NotifyFilters.LastAccess NotifyFilters.LastWrite NotifyFilters.FileName NotifyFilters.DirectoryName;&lt;br /&gt;&lt;br /&gt;// watch files of type&lt;br /&gt;watcher.Filter = "*.txt";&lt;br /&gt;&lt;br /&gt;// watch events:&lt;br /&gt;watcher.Created += new FileSystemEventHandler(OnChanged);&lt;br /&gt;watcher.Deleted += new FileSystemEventHandler(OnChanged);&lt;br /&gt;&lt;br /&gt;watcher.EnableRaisingEventys = true;&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Press 'q' to quit app.");&lt;br /&gt;&lt;br /&gt;while (Console.Read() != 'q') ;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;vb.net:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;&lt;p&gt;Dim watcher As New FileSystemWatcher() &lt;/p&gt;&lt;p&gt;&lt;br /&gt;' monitor files at:&lt;br /&gt;watcher.Path = "c:\"&lt;br /&gt;&lt;br /&gt;' monitor files when&lt;br /&gt;watcher.NotifyFilter = NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName&lt;br /&gt;&lt;br /&gt;' watch files of type&lt;br /&gt;watcher.Filter = "*.txt"&lt;br /&gt;&lt;br /&gt;' watch events:&lt;br /&gt;AddHandler watcher.Created, AddressOf OnChanged&lt;br /&gt;AddHandler watcher.Deleted, AddressOf OnChanged&lt;br /&gt;&lt;br /&gt;watcher.EnableRaisingEvents = True&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Press 'q' to quit app.")&lt;br /&gt;&lt;br /&gt;While Console.Read() &amp;lt;&amp;gt; "q"C&lt;br /&gt;&lt;br /&gt;End While &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;As you seen, we call OnChanged function every event occurs, so we can implement this function to print this event and its time like that:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;C#:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;static void OnChanged(object source, FileSystemEventArgs e)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("File Changed, File Path: {0} , Change: {1}, DateTime: {2}", e.FullPath, e.ChangeType,DateTime.Now.ToString());&lt;br /&gt;&lt;br /&gt;}&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;vb.net:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;table border="2" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign="top" width="600"&gt;Private Shared Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)&lt;br /&gt;&lt;br /&gt;Console.WriteLine("File Changed, File Path: {0} , Change: {1}, DateTime: {2}", e.FullPath, e.ChangeType, DateTime.Now.ToString())&lt;br /&gt;&lt;br /&gt;End Sub&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now, this is screen shot of application when delete .txt file and create it again.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img border="0" alt="" src="http://vb4arab.com/vb/uploaded/3/01212665607.jpg" width="400" /&gt;&lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-6563815948164796061?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/6563815948164796061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/06/filesystemwatcher_05.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6563815948164796061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/6563815948164796061'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2008/06/filesystemwatcher_05.html' title='FileSystemWatcher'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3593543847859157882.post-9068711540263438606</id><published>2007-09-14T02:29:00.004+03:00</published><updated>2009-11-01T02:02:33.345+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><category scheme='http://www.blogger.com/atom/ns#' term='Microsoft'/><title type='text'>Introduction to AJAX in .net Applications</title><content type='html'>&lt;br&gt;&lt;br&gt;In the name of Allah.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc0000;"&gt;&lt;strong&gt;&lt;span style="font-size:180%;"&gt;Introduction to AJAX in .net Applications&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;strong&gt;&lt;span style="color:#000066;"&gt;Fast tour in Microsoft Ajax Toolkit&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;In this lesson we will take a fast tour in Microsoft Ajax world. First we have to know what the meaning of AJAX is.&lt;br /&gt;&lt;br /&gt;AJAX or Asynchronous JavaScript and XML is a term describing a web development technique for creating interactive web applications using a combination of: HTML (or XHTML) and Cascading Style Sheets (CSS) for presenting information* Document Object Model, JavaScript to dynamically display and interact with the information presented* XML, XSLT and the XMLHttpRequest object to interchange and manipulate data asynchronously with the web server (although AJAX applications can use other technologies.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;*** Wikipedia definition for AJAX at link:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/AJAX"&gt;http://en.wikipedia.org/wiki/AJAX&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Anyway it is a type of programming made popular with since 2005 by Google. It is not a new programming language but it is depends on good connection and using of existing resources to establish an interactive web-based application. Basically, it depends on divide web page into separate parts all of them can be re- loaded alone without interference with other parts.&lt;br /&gt;&lt;br /&gt;One of the most famous Ajax-enabled web application is Google service. Also new mail service from yahoo and hotmail also supported with Ajax concepts.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;&lt;strong&gt;How can I start working with Ajax through asp.net?&lt;/strong&gt; &lt;/span&gt;&lt;span style="color:#990000;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;span style="color:#990000;"&gt;&lt;/span&gt;&lt;p align="center"&gt;&lt;a href="http://www.discountasp.net/images/logo_aspnet_ajaxhosting.gif"&gt;&lt;img style="MARGIN: 0px 10px 10px 0px; WIDTH: 132px; FLOAT: left; HEIGHT: 49px; CURSOR: hand" border="0" alt="" src="http://www.discountasp.net/images/logo_aspnet_ajaxhosting.gif" height="85" /&gt;&lt;/a&gt;&lt;/p&gt;Microsoft publishes Microsoft Ajax Toolkit to provide a simple tool can be used to benefit from Ajax technology; you can start by downloading tools through this link: &lt;a href="http://www.asp.net/ajax/"&gt;http://www.asp.net/ajax/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Or you can trace large amount of controls live through this link:&lt;br /&gt;&lt;a href="http://www.asp.net/ajax/control-%20toolkit/live/"&gt;http://www.asp.net/ajax/control-%20toolkit/live/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you search for some useful tutorials about asp.net in general you can visit this link:&lt;br /&gt;&lt;a href="http://www.asp.net/learn/default.aspx?tabid=63"&gt;http://www.asp.net/learn/default.aspx?tabid=63&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And especially with Ajax you can find video tutorials here:&lt;br /&gt;&lt;a href="http://www.asp.net/learn/ajax-videos/"&gt;http://www.asp.net/learn/ajax-videos/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;you can have a fast start with Ajax using this video:&lt;br /&gt;&lt;a href="http://www.asp.net/learn/ajax-%20videos/video-75.aspx"&gt;http://www.asp.net/learn/ajax-%20videos/video-75.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;And this video for Microsoft Ajax Tools:&lt;br /&gt;&lt;a href="http://www.asp.net/learn/ajax-%20videos/video-76.aspx"&gt;http://www.asp.net/learn/ajax-%20videos/video-76.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Finally, you can still build your own Ajax work from scratch using HTML (or XHTML) with JavaScript or by using old Microsoft technology (Atlas) which support partial processing for WebPages, you can find more about Atlas in this video:&lt;br /&gt;&lt;a href="http://download.microsoft.com/download%20/0/f/6/0f651a0f-6f2b-4497-b061-%20e1b2825e22e0/MSAJAX-ToDoList-Video.zip"&gt;http://download.microsoft.com/download%20/0/f/6/0f651a0f-6f2b-4497-b061-%20e1b2825e22e0/MSAJAX-ToDoList-Video.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;This article written by Arabic in:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://www.vb4arab.com/vb/showthread.php?t=15"&gt;http://www.vb4arab.com/vb/showthread.php?t=15&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Thanks.&lt;br&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3593543847859157882-9068711540263438606?l=ahmedgamal-net.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ahmedgamal-net.blogspot.com/feeds/9068711540263438606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ahmedgamal-net.blogspot.com/2007/09/introduction-to-ajax-in-net_13.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/9068711540263438606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3593543847859157882/posts/default/9068711540263438606'/><link rel='alternate' type='text/html' href='http://ahmedgamal-net.blogspot.com/2007/09/introduction-to-ajax-in-net_13.html' title='Introduction to AJAX in .net Applications'/><author><name>Ahmed Gamal</name><uri>http://www.blogger.com/profile/00041272746702272043</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://bp1.blogger.com/_FUmkjQ7foTw/R5d30ba3E8I/AAAAAAAAAA4/iAQ8vlerwYE/S220/ahmed.jpg'/></author><thr:total>0</thr:total></entry></feed>
