Steve N Shay

December 2, 2009

Simple Twitter DataObject in C# with LINQ to XML

Filed under: ASP.NET, Programming — Tags: , , — Steve @ 4:35 pm

Its nice to be able to pull our latest tweets from twitter and place them anywhere on our page. This quick tutorial will show you exactly what you need to do in order to do just that!

Create a new class file. I called mine twitter.cs, but you can name it whatever you want.

Next, you need to declare your usings for this class. I used LINQ for this tutorial, but you can use XML by itself (which maybe I can create another tutorial for at a later date). So you will want to use System.Data, System.Linq, and System.XML.Linq. It should look like below:

 
using System.Data;
using System.Linq;
using System.Xml.Linq;
/// <summary>
/// Twitter Feed Reader
/// </summary>

On another note, you will notice below the XML comment tags. Visual Studio fully supports XML Comments in so much that it not only uses them for comments, but also for declaring those nice little helper tips you see in the intellisense code. USE THEM! It makes your life easier. so here, you can see I declared my new class called “twitter”. This is the class which will be called in the page code if using it in code behind, or which will be used as a one way data object. Yes, this class can be used to include writing to twitter, but this is a simple and quick tutorial :)

The first part of the class is a whole mess of comments. Basically, it is a brief description of what the class does, what each parameter requires, what is returned, and any additional remarks. I wrote in remarks “Implement cache of code”. What that means to me (since I wrote it) is to implement a bit of data caching. Twitter has a max request limit. I am going to be adding in a bit of code at a later date (probably sometime next week) to control the amount of requests which the application overall sends to twitter, and which just shows my latest tweet for the period of at least 5 minutes before requesting another one.

 
public class twitter
{
    /// <summary>
    /// Retrieves a set number of tweets based on the username and tweet count requested.
    /// Each full tweet set response (all tweets requested) is separated by an "|".
    /// Each part of each tweet is separated by an ";"
    /// </summary>
    /// <param name="tweetcount">Number of tweets to return</param>
    /// <param name="username">Username of twitterer</param>
    /// <remarks>Implement cache of code</remarks>
    /// <returns>
    /// DataTable, 4 Columns:
    /// Column 1 - ID
    /// Column 2 - Tweet Date
    /// Column 3 - Tweet Text
    /// Column 4 - Where Updated From
    /// </returns>
continue with tutorial for this portion…
}

So after the comments, we have a function called getTweet() which returns itself as a DataTable. Why DataTable? Because we need a DataObject for our ObjectDataSource! By returning a DataTable, we can then convert this class into a functional business object which can be dropped into any page using a myriad of data visualizers, such as DataGrid, GridView, ListView, Repeater, etc… (PS. Also makes for easy styling in the end, and less work in the code behind!) You will also notice there are two variables needed for this class, username and tweetcount. The username is… well… the username of the twitter user you want to retrieve. The tweetcount is the number of tweets you wish to go back. 5 is usually a good number for most personal web sites, and maybe a list of the latest 20 for business sites. The max value is 2000 I believe.

 
public DataTable getTweet(string username, int tweetcount)
    {
        DataTable tweetTable = new DataTable();
        tweetTable.Columns.Add("tweetid",typeof(int));
        tweetTable.Columns[0].AutoIncrement = true;
        tweetTable.Columns[0].AutoIncrementSeed = 1;
        tweetTable.Columns[0].AutoIncrementStep = 1;
        tweetTable.Columns[0].Unique=true;
        tweetTable.Columns[0].ReadOnly = true;
        tweetTable.Columns.Add("tweetDate",typeof(string));
        tweetTable.Columns.Add("tweetText",typeof(string));
        tweetTable.Columns.Add("tweetFrom",typeof(string));

        return tweetTable;
    }

Next comes our LINQ to XML portion. It sounds more complicated than it is. There is a feature in VS which allows for intellisense in LINQ by the way, but I can never get it to work, so I test my queries the old fashioned way. On a positive note, its relatively painless to work with, and once your used to the syntax (and if your like me, you keep developer cheat sheets) its easy enough.

Now, the statusUri is a the web link to twitters user timeline. Simply put, it takes many variables, but for the sake of this tutorial, we are only supplying username and tweetcount.

Declare your xdocument with whatever name you wish as a new XDocument. Then set your XDocument to load the statusUri string variable.

The more pain in the rear part is the actual linq below. This is a simple example, but it can be a lot more complex.

 
string statusUri = "http://twitter.com/statuses/user_timeline.xml?screen_name=" + username + "&count=" + tweetcount;
XDocument tdoc = new XDocument();
tdoc = XDocument.Load(statusUri);

var statuses = from status in tdoc.Descendants("status")
               select new
               {
                   tweetDate = status.Element("created_at").Value,
                   tweetText = status.Element("text").Value,
                   tweetFrom = status.Element("source").Value
               };

Lastly, do a for each loop for each status within the statuses from the XML file retrieved and parsed via LINQ and add it to the datatable as a new row! Its that simple.

 
foreach (var status in statuses)
        {
            DataRow dr = tweetTable.NewRow();
            dr.SetField(1, status.tweetDate);
            dr.SetField(2, status.tweetText);
            dr.SetField(3, status.tweetFrom);
            tweetTable.Rows.Add(dr);
        }
Lastly, here is the entire code block for the object rolled up into one nice neat package :) 
using System.Data;
using System.Linq;
using System.Xml.Linq;

/// <summary>
/// Twitter Feed Reader
/// </summary>
public class twitter
{
    /// <summary>
    /// Retrieves a set number of tweets based on the username and tweet count requested.
    /// Each full tweet set response (all tweets requested) is separated by an "|".
    /// Each part of each tweet is separated by an ";"
    /// </summary>
    /// <param name="tweetcount">Number of tweets to return</param>
    /// <param name="username">Username of twitterer</param>
    /// <remarks>Implement cache of code</remarks>
    /// <returns>
    /// DataTable, 4 Columns:
    /// Column 1 - ID
    /// Column 2 - Tweet Date
    /// Column 3 - Tweet Text
    /// Column 4 - Where Updated From
    /// </returns>
    public DataTable getTweet(string username, int tweetcount)
    {

        string statusUri = "http://twitter.com/statuses/user_timeline.xml?screen_name=" + username + "&count=" + tweetcount;
        XDocument doc = new XDocument();
        doc = XDocument.Load(statusUri);
        var statuses = from status in doc.Descendants("status")
                       select new
                       {
                           tweetDate = status.Element("created_at").Value,
                           tweetText = status.Element("text").Value,
                           tweetFrom = status.Element("source").Value
                       };

        DataTable tweetTable = new DataTable();
        tweetTable.Columns.Add("tweetid",typeof(int));
        tweetTable.Columns[0].AutoIncrement = true;
        tweetTable.Columns[0].AutoIncrementSeed = 1;
        tweetTable.Columns[0].AutoIncrementStep = 1;
        tweetTable.Columns[0].Unique=true;
        tweetTable.Columns[0].ReadOnly = true;
        tweetTable.Columns.Add("tweetDate",typeof(string));
        tweetTable.Columns.Add("tweetText",typeof(string));
        tweetTable.Columns.Add("tweetFrom",typeof(string));

        foreach (var status in statuses)
        {
            DataRow dr = tweetTable.NewRow();
            dr.SetField(1, status.tweetDate);
            dr.SetField(2, status.tweetText);
            dr.SetField(3, status.tweetFrom);
            tweetTable.Rows.Add(dr);
        }

        return tweetTable;
    }
}

I hope you enjoyed this tutorial and you find it useful for creating any xml based business object.

Technorati Tags: ,,,

June 25, 2009

Baby Loves Daddy!

Filed under: Life — Tags: , , — Steve @ 9:44 pm

So, I was playing with Lizzy (for those of you who don’t know, we are having a girl, and her name is Elizabeth Sophia Melendez) this evening and the sweetest thing happened. Some background first. Lizzy hates daddy… or so I thought. Every time I would touch the belly, she would stop moving/kicking and pretty much ignore me. Well, turns out she would just go to sleep.
Today, I was talking to the belly, really close. I am sure she could hear my voice. Every time I spoke, she would move about, and even kicked (or punched) my face. It was so adorable. Shay felt her gravitate towards my voice. Then, she calmed down when I put my hand down on the belly and was still. I continued to speak while resting my hand and she laid calmly.
Now, that alone isn’t proof of her love for my voice and hand at least, however, when I removed myself, she went nuts. Then I went back and started talking with my palm rested over the belly and she calmed again. As soon as I removed myself, she went nuts. I did this about 4 times, and each time, the same result. Ta-Da! Scientific method worked.
So I conclude that “Yes!” my soon to be here daughter loves the sound of my voice and the heat that emanates from my hand. I am officially in love. :)

May 21, 2009

Cake Program!

Filed under: Uncategorized — Tags: , — Steve @ 10:53 am

Hi Everyone! Today, I have a nice image I made for a t-shirt I want to create:

copyright©2009 Steven K Melendez

copyright©2009 Steven K Melendez

By the way, you cannot use this image for profit. Other than that, enjoy it.

May 13, 2009

Possibly a definitive??? I think not!

Filed under: Life — Tags: , , — Steve @ 9:36 pm

Hello to all my readers (there aren’t many of you yet, but hopefully there will be more). I had a wonderful discussion this evening with my wife in regards to the possible and the definitive. Here is the basis of the argument, as read to me by my wife from some website (I can’t locate it at the moment, but I am sure I can edit it in tomorrow when I get the link from my wife):

a) If God possibly exists, then God necessarily exists
b) God possibly exists
c) therefore God necessarily exists

Now, my wife does not believe this statement is evidence of God’s existence, but she chose to use this side of the argument and play devil’s advocate (pardon the pun) for the sake of a rousing discussion (which in fact, it was!). Here is what that statement boils down to:

a)If God possibly exists, then God necessarily exists ->
While the first part can be true, it is not necessarily. It is stating a logical possibility. It can/should be reworded to “It is possible God exists” just for clarity sake. Let’s go on that assumption that Yes! it is possible God exists, because quite frankly, we do not know it as a fact that he doesn’t. Science has never proven a lack of existence, and religion has never proven an existence, so the possibility is either way.

What about part 2 of that statement? This is a blanket phrase which was given. It is basically saying to take this statement as fact because of a possibility. There is no logical way that 2nd part can be factual or construed from the first part. The only thing proved by the possibility of God’s existence is the possibility of God’s existence, not the definitive of God’s existence… Why? Because there is no evidence to support that statement. Here is an example of what I mean:

If 1+1 possibly equals 3, then 1+1 does equal 3. WHAT THE HECK! No way! If 1+1 possibly equals 3, 1+1 does not suddenly equal 3 just because I said so. Where is the evidence to support said statement? Now, if I can prove to you 1+1 can actually equal 3, then part 2 of my statement, “1+1 does equal 3″ is a fact. However, if I cannot prove that 1+1 does equal 3, then I have not stated a fact, rather I have stated an illogical fallacy based on non-evidence, but blanket approval of a statement. So therefore, part 2 of the my statement is false because it states a fact without evidence to support the fact. I can prove to anyone that 100% of the time 1+1 will equal 2, yet I still could not use the following argument and be correct: If 1+1 possibly equals 2, then 1+1 necessarily equals 2, because there is no evidence in the statement to prove that.

However, If 1+1 possibly equals 2 because of x, then 1+1 necessarily equals 2. However, the reverse may not apply in that situation due to logic. If all a = b and some b = c, all c = a is false because some c may not be equal to b, therefore not all c are equal to a. So… If 1 + 1 can possibly equal 2, yet I can prove it also equals 3 (keyword is prove here), that does not prove that all 2 or 3 is necessarily equal to 1+1, unless the opposite is proven. Now funny enough, my argument can be proven in reverse of 1+1 equaling 2, however, that is not the point.

So, back to the point…

This proves that the possibility of God alone does not prove the existence of God because of yet again, lack of evidence to give ground (Funny enough, I believe in the existence of God.), so let us now re-examine the statement:

a) If God possibly exists, then God possibly exists, because a possibility does not create a fact without evidence to support it as such

b) God possibly exists

c) Therefore, God possibly exists

That is the only logical way to approach it. As I said, I am a believer in God, but I do not give it a religion due to my beliefs in religious hypocrisy (don’t tell me it doesn’t exist, I can give a million examples per religion). But, on a logical level, God cannot be proven. That is why it requires “Faith”. The only ground any religion has to stand on is faith, as there is no physical evidence to the contrary.  A common example of evidence that I hear of is the Bible. That is a book. Books are written by man. Man are inspired by a multitude of things. Not one person can factually say a man wrote that book because he was directed by God to do so. You may believe that to be the case, but you have no evidence to support it. Remember, when you make a statement as fact, it is your responsibility to back that statement up with evidence, not the other way around, because the other person made no such claim so they hold no responsibility to explain lack of your evidence or existence of your evidence.

Discuss Away!

-Steve

May 12, 2009

Currently working on Tutorial #2

Filed under: ASP.NET, Programming, Technology, VB.NET — Tags: , , — Steve @ 10:15 am

Hi everyone, I am currently working on my second tutorial for asp.net with vb.net. It is about controls (still sticking with the basics). It should be ready at the end of the week!

May 5, 2009

Windows 7… Finally installed!!

Filed under: Technology, Windows — Tags: — Steve @ 11:04 pm

Howdy everyone! I just finished installing most of the software I was hoping to install for Windows 7.  Let me just say, installation went without a hitch. I chose to do a fresh install so I can get a nice clean slate and a good idea of the expected performance from the new operating system. As far as a full 0-day review is concerned, I cannot offer one yet. I love the interface improvements (such as the jump-lists, online ID integration, better menus, etc), but because I am not fully  used to them yet, I am still spending some time poking under the hood more than any serious error hunting or nitpicking at this time :)

Well, at least I can say the backgrounds which come with the OS are Uber Funky… here is the one I am using:

One of many funky backgrounds for windows 7 

Anywho, it looks like MS is trying to go more ‘people’ friendly with W7… I will speak more on the OS later in the week and over the weekend. Ciao for now:)

May 4, 2009

Response to “Top 7 Reasons People Quit Linux”

Filed under: Linux, Technology, Windows — Tags: , — Steve @ 5:10 pm

Here is an article I thought both interesting, slightly uninformative, and plain pompous -Top 7 Reasons People Quit Linux. The author of course is writing for Linux World, so I understand his Pro Linux POV. However, keep in mind I consider myself more technically savvy than most, and I find his reasons people quit to be lacking. I am a Windows user. Why? For his first reason actually… that, and his last reason.

Reason #1 – Linux does not have proper App support yet. Plain and simple, I am a Web Developer, and the swath of tools available to me within Windows makes Linux not even an option. Sure, I can sit in Notepad and GIMP all day, but why deal with the hassle of downloading a sub par (think of GIMP as Photoshop lite, while it has its ups, it is not a full fledged creation tool) program and a plain text editor when I can use a full featured IDE like Visual Studio combined with Photoshop and Illustrator for my Vector stuff. Big difference here in usability. So his first point is actually correct. Stick with what you need to get your work done. However, from there he gets rather pompous and right on the ol’ Linux high horse.

Reason #2 – Hardware issues abound in Linux. It isn’t quite as simple as he states. A good portion of companies that create hardware do not have proper driver support available for Linux yet. It just doesn’t exist yet. Linux isn’t main stream enough for these companies to support Linux with drivers yet, and those that do have buggy drivers a lot of times. And while people can learn to utilize the workarounds, remember, the average person just wants to boot up and go, not deal with workarounds to get their webcam properly working.

Reason #3 – People do not like Command Lines! Look, I get what your saying here. Just learn something new, right? Well guess what, that is what is a GUI is for. Most people do not want to type in a command line. How many people do you think are afraid of screwing something up. This is the same reason why the Windows Command Prompt is barely used by most people. Almost any command which can be typed at the prompt has associated Window elements built into the GUI. Same with OS X. The OS has to cater to people, not the other way around. Don’t expect bravery from the average person on the command line front, it just wont happen.

Reason #4 – Lack of similarity to Windows/OS X. Ok, I agree here for the most part. It is a different OS, so people need to just get used to the interface if they wish to use it. However, don’t insult people with the last line “If you’re unable to adapt, it says more about you than it does about Linux.” That is plain freakin’ rude. You sound like a forum troll with that line.

Reason #5 – Linux people on the forums are mean… This is true. While the official guys are generally helpful, I find a lot of people are rude to the average person on the forums. MOST PEOPLE DO NOT KNOW HOW TO SEARCH FOR A TOPIC THAT ALREADY EXISTS BECAUSE THEY DO NOT KNOW HOW TO PROPERLY DESCRIBE THE PROBLEM!!! Be nice to newbies and they will be religious linux converts… continue being jerks, they will go right back to Windows/OS X. Don’t blame the new user for this issue. Blame usability, again. You are talking about people who are new to something and yes, they require some hand-holding. Be nice, dont be jerks.

Reason #6 – They don’t like it… And frankly, that is their right. If they do not want to learn a new Operating System, they are more than entitled to feel that way. They don’t need to give a reason which is why when they say they just don’t like it, just leave it alone. The reason’s people don’t like it are mostly stated above. So what! You don’t own them in any way, so no, they do not need to give you a reason. Stating “I Don’t Like It” is reason enough and leave it at that.

Reason #7 – After installing Linux, everything went crazy!!! I actually have had the problem where loading up Linux, I was presented with the command line versus the GUI. You wanna know something, that shouldn’t happen. There should never be a reason to be presented with a command line at boot time. For me, for some reason, Linux worked fine and all of a sudden, GRUB stopped loading properly (or whatever it is that didn’t work right). I don’t care how to fix the problem, that shouldn’t happen. I ended up having to reinstall Linux so I can go online and find out what was causing this issue. Needless to say, that shouldn’t happen. Say whatever you want, but it plain and simple is not user friendly to have the GUI stop suddenly loading on startup and to present someone with a command line and no instructions… If there is a command line to restart the GUI, it should auto run. If there is a problem with the OS, it should ask for the disk and repair itself.

So, Keir Thomas, take some advice here. If you want to give a list of people not sticking with Linux, try understanding their Point of View before spouting the same things we have all heard a million times before. Stop blaming people for wanting an OS to be easier to work with. That is why the GUI was invented in the first place. Otherwise, we might as well have stuck with DOS and just typed documents and such like that…

Microsoft makes my day tomorrow…

Filed under: Technology — Tags: , , — Steve @ 2:22 pm

In case you haven’t heard, tomorrow MS releases Windows 7 RC1 for the general public to test (I am sure it will have limited keys like the previous betas did). Here is the awesome part. The license will be valid till June 1st 2010! WOW!!!

Talk about giving people an option to test your software out. After the Vista debacle (which seems to be pretty solid now, albeit a little slow), I think Microsoft is trying to show there is another side to the company. Who knows, but all I know is tomorrow morning at 9am, I will be downloading the new Windows 7 RC and will be using it for the next year to come.

April 28, 2009

Feel the Fear and do it Anyway! (You heard right!)

Filed under: Life, Ranting — Tags: , , — Steve @ 2:21 pm

So, the other day, I stumbled upon an interesting article aptly titled Feel the Fear and Do It Anyway (or, the Privatization of the English Language). Just go on and read it, seriously. Here is the full article if you don’t want to click through:

Feel the Fear and Do It Anyway (or, the Privatization of the English Language)

Post written by Leo Babauta. Follow me on Twitter.

Today I received an email from the lawyers of author Susan Jeffers, PhD., notifying me that I’d infringed on her trademark by inadvertently using the phrase “feel the fear and do it anyway” in my post last week, A Guide to Beating the Fears That Hold You Back.

The phrase, apparently, is the title of one of her books … a book I’d never heard of. I wasn’t referring to her book. I’m not using the phrase as a title of a book or product or to sell anything. I was just referring to something a friend said on Twitter.

Her lawyers asked me to insert the (R) symbol after the phrase, in my post, and add this sentence: “This is the registered trademark of Susan Jeffers, Ph.D. and is used with her permission.”

Yeah. I’m not gonna do that.

I find it unbelievable that a common phrase (that was used way before it was the title of any book) can be trademarked. We’re not talking about the names of products … we’re talking about the English language. You know, the words many of us use for such things as … talking, and writing, and general communication? Perhaps I’m a little behind the times, but is it really possible to claim whole chunks of the language, and force people to get permission to use the language, just in everyday speech?

What if this were taken to an extreme? What if some billionaire (say, Bill Gates) decided to start trademarking thousands and thousands of phrases, so that he could charge us for each use, or so that we’d have to link back to the Microsoft homepage with each reference? The language, in this scenario, could be entirely privatized if we allow this sort of thing.

So, while this post is probably ill-advised (and yes, I realize that I’m actually giving publicity to Ms. Jeffers), I have to object. I think we have a duty, as writers and bloggers and speakers of the English language, to defend our rights to … words. Free speech is a bit of an important concept, I think.

As an aside, I think the idea of jealously protecting copyright and trademarks, in this digital age, is outdated and ignorant. You want your ideas to spread, and you should encourage people to spread your ideas, not put up all kinds of boundaries and restrictions and obstacles to that being done. This blog, for example, is Uncopyrighted, and will always be free, because I want people to spread my posts and ideas. I think it’s actually good for me as a writer, and it’s (not insignificantly) better for the writing community in general if we can share each others’ work freely. I’m hoping that with posts like this, and the good work of thousands of other like-minded people, the old mindset of fencing off ideas and language will slowly change.

So, no, I will not be adding a Registered Trademark symbol to the previous post. And no, I won’t be adding a phrase of legalese to the post. And no, I won’t even attribute the phrase or link to her book, as I wasn’t referring to the book. And no, I won’t remove the phrase.

I’d rather be sued.

Oh, and I’m not going to change the title of this post either. You’ll have to remove it from my cold, dead iMac.

That is the article he wrote… Interesting to see how much of a fear monger some lawyers can be, rather than going after actual thieves, they go after honest people. As for me, I will just keep typing those words in as a bit of a “try to send me a DMCA Takedown for using Free Speech”.

Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!
Feel the Fear and do it Anyway!

-Steve

April 24, 2009

ASP.NET/VB.NET Tutorial #1 – Hello World!

Filed under: ASP.NET, Programming, VB.NET — Tags: , , — Steve @ 3:45 pm

We are going to create a simple “Hello World!” script for ASP.NET. Yes, you could just put the words “Hello World!” in your page, but that wouldn’t be all that fun or dynamic… and you would be completely missing the point of this tutorial anyway. You will need an IDE (Integrated Development Environment) to follow along (for notepad enthusiasts, you do not NEED an IDE, but newer programmers may need one to assist in the development process for reasons I am sure you can understand). I personally use Visual Studio 2008 because it is an excellent IDE to work with. If you do not have an IDE to work with and wish to follow along with me, you can download Visual Web Developer Express 2008 from this link. Best part is, it is completely free to use (although, it does have some limitations).

So, open Visual Studio and start a New Web Site. Name the site whatever you choose. I am calling this project ‘TutSeries for the sake of the tutorial series. Set the language to VB and click OK to create the new site application. If your in Visual Studio, you should see a screen similar to this:

'New Web Site' defaults in Visual Studio 2008

'New Web Site' defaults in Visual Studio 2008

For simplicities sake, I want you to create the following code between the ‘<div></div>’ section of the code on the main page.

<asp:label id=’lbl_HelloWorld’ runat=’server’ />

And here is a screen capture of what it would look like in the IDE:

Adding the label for our Hello World Program...

Adding the label for our Hello World Program...

For the rest of the tutorial, we will work in the Code Behind page for this tutorial site. The Code Behind page is a .Net page which contains all of our ‘crunching code’ as I call it. It is the code which handles the website on the server side and delivers the page to the user on the client side in a particular state (more on state in later tutorials). As an example, if you were to run the web site right now, in its current form , all you would get is a blank screen, which is not what we want. We want the browser to display “Hello World!” in nice big letters, right? So ok, how do we get to the Code Behind for this page. Well it’s simple really. Take a look at the Solution Explorer. In their, you will see the file we are currently working on called “Default.aspx”. Did you notice the ‘+’ symbol to the left of the file name? Click it to expand the file and you will see there is another file associated with this file called “Default.aspx.vb”. That, is the Code Behind file we need. So go ahead and double click on it to open up the file and we can add some code to make our label say “Hello World!’.

Since I am slightly tired of screenshots, I will type out and only add one more for now :)

Here is the code that is prefilled in the page when you open Default.aspx.vb:

Partial Class _Default
Inherits System.Web.UI.Page

End Class

Each of the pieces of this are important, but they are out of the scope of this tutorial, so for now, we will skip on to creating the text for “Hello World!” in the web app. When the page loads, we want the label to say “Hello World!”, so how do we instruct the page to do so from here? Well, lets use the page load event to do this:

Sub Page_Load() Handles Me.Load

‘Our code for loading the label with text will go here…

lbl_HelloWorld.Text = “Hello World!”

End Sub

The beauty of VB over other languages, such as C# is how verbose VB really is. What you see above is actually pretty self explanatory. Like I said before, we want to contain the code for saying “Hello World!” in the code behind. When the page loads, we want to direct the text our label, name “lbl_HelloWorld” from the Default.aspx page, to say “Hello World!”. We did this quite simply by stating ‘lbl_HelloWorld.Text = “Hello World!”‘ The way this statement works is like this:

ControlName:ControlPart = WhatWeWantToPutHere

Think in the context of a text box maybe. If we named a text box “txt_FirstName” and when the page loaded, we wanted the text boxes text to read “Enter First Name Here”, we would set the Text property of the Text Box equal to the text we want appearing, right?

Go ahead and run your page. Did your browser open up with the words “Hello World!” in the top left corner (there was no html formatting, so that should be where it was located). If not, go back up and make sure you added the code I listed properly. If so…

Congratulations on your first ASP.NET with VB web app. I hope you enjoyed this tutorial and stay tuned :)

-Steve

Older Posts »

Blog at WordPress.com.