Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,689 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,307 people online right now. Registration is fast and FREE... Join Now!




My first attempt at C#

 
Reply to this topicStart new topic

My first attempt at C#

Sneblot
post 26 May, 2008 - 02:38 PM
Post #1


D.I.C Head

**
Joined: 9 Feb, 2007
Posts: 240


My Contributions


This is my first attempt at C# but it was done at work on note pad so Im not sure what I really need to do next?

CODE

using System.Xml;

XmlTextReader rssReader;

XmlDocument rssDoc;

XmlNode nodeRss;

XmlNode nodeChannel;

XmlNode nodeItem;

ListViewItem rowNews;

// First clear of any previous items in ListView

lstNews.Items.Clear();

this.Cursor = Cursors.WaitCursor;

// Create a new Xml TestReader from the specified URL (RSS feed)

rssReader = new XmlTextReader (txtUrl.Text);

rssDoc = new XmlDocument();

//Load the Xml content into a XmlDocument

rssDoc.Load(rssReader);

// Loop for the <rss> tag

for (int i = 0; i < rssDoc.ChildNodes.Count; i++)

{

    // If it is the rss tag
    
    if (rssDoc.ChildNodes[i].Name == "rss")
    
    {

    // <rss> tag found

    nodeRss = rssDoc.ChileNodes[i];

    }

}

// Loop for the <channel> tag

for (int i = 0; i < nodeRss.ChildNodes.Count; i++)

{

    // If it is the channel tag
    
    if (nodeRss.ChildNodes[i].Name == "channel")
    
    {

    // <channel> tag found

    nodeChannel = nodeRss.ChildNodes[i];

    }

}

//Set the labels with information from inside the nodes

lblTitle.Text = "Title:" + nodeChannel["title"].InnerText;

lblLanguage.Text = "Language:" + nodeChannel["link].InnerText;

lblDescription.Text = "Description:" + nodeChannel["description"].InnerText;

// Loop for the <title>, <link>, <description> and all the other tags

for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)

{

    // If it is the item tag, then it has children tags which we will ad as items to the ListView

    if (nodeChannel.ChidrenNodes[i].Name == "item")

    {

    nodeItems = nodeChannel.ChildNodes[i];

    // Create a new row in the ListView containing information from inside the nodes

    rowNews = new ListViewItem();

    rowNews.Text = nodeItem["title"].InnerText;

    rowNews.SubItems.Add(nodeItem["link"].InnerText;

    lstNews.Items.Add(rowNews);

    }

}

this.Cursor = Cursors.Default;

//When an items is selected

if (lstNews.SelectedItems.Count == 1)

{

    // Loop through all the nodes uner <channel>

    for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)

    {

    // Untill you find the <item> node

    if (nodeChannel.ChildNodes[i].Name == "item")

    {

    // Store the item as a node

    nodeItem = nodebchannel.ChildNodes[i];

    // If the <title> tag matches the current selected item

    if (nodeItem["title"].InnerText == lstNews.SelectedItems[0].Text)
    
    {

    // It's the item we were looking for, get the description

    txtContent.Text = nodeItem["description"].InnerText;

    // We don't need to loop anymore

    break;

    }

    }

    }

}

// When double clicked open the web page

System.Diagnostics.Process.Start(lstNews.SelectedItems[0].SubItems[1].Text);
User is offlineProfile CardPM

Go to the top of the page

crcapps
post 27 May, 2008 - 04:39 AM
Post #2


D.I.C Head

**
Joined: 13 May, 2008
Posts: 53


My Contributions


Next you need to compile and link it.
For that, it depends on your operating system-
To compile in Windows, assuming you don't have Visual Studio, you should get Visual C# Express (probably 2008).
In Linux, it's libmono and mcs- just go ahead and get monodevelop, actually, if this is the case.

QUOTE(Sneblot @ 26 May, 2008 - 03:38 PM) *

This is my first attempt at C# but it was done at work on note pad so Im not sure what I really need to do next?

CODE

using System.Xml;

XmlTextReader rssReader;

XmlDocument rssDoc;

XmlNode nodeRss;

XmlNode nodeChannel;

XmlNode nodeItem;

ListViewItem rowNews;

// First clear of any previous items in ListView

lstNews.Items.Clear();

this.Cursor = Cursors.WaitCursor;

// Create a new Xml TestReader from the specified URL (RSS feed)

rssReader = new XmlTextReader (txtUrl.Text);

rssDoc = new XmlDocument();

//Load the Xml content into a XmlDocument

rssDoc.Load(rssReader);

// Loop for the <rss> tag

for (int i = 0; i < rssDoc.ChildNodes.Count; i++)

{

    // If it is the rss tag
    
    if (rssDoc.ChildNodes[i].Name == "rss")
    
    {

    // <rss> tag found

    nodeRss = rssDoc.ChileNodes[i];

    }

}

// Loop for the <channel> tag

for (int i = 0; i < nodeRss.ChildNodes.Count; i++)

{

    // If it is the channel tag
    
    if (nodeRss.ChildNodes[i].Name == "channel")
    
    {

    // <channel> tag found

    nodeChannel = nodeRss.ChildNodes[i];

    }

}

//Set the labels with information from inside the nodes

lblTitle.Text = "Title:" + nodeChannel["title"].InnerText;

lblLanguage.Text = "Language:" + nodeChannel["link].InnerText;

lblDescription.Text = "Description:" + nodeChannel["description"].InnerText;

// Loop for the <title>, <link>, <description> and all the other tags

for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)

{

    // If it is the item tag, then it has children tags which we will ad as items to the ListView

    if (nodeChannel.ChidrenNodes[i].Name == "item")

    {

    nodeItems = nodeChannel.ChildNodes[i];

    // Create a new row in the ListView containing information from inside the nodes

    rowNews = new ListViewItem();

    rowNews.Text = nodeItem["title"].InnerText;

    rowNews.SubItems.Add(nodeItem["link"].InnerText;

    lstNews.Items.Add(rowNews);

    }

}

this.Cursor = Cursors.Default;

//When an items is selected

if (lstNews.SelectedItems.Count == 1)

{

    // Loop through all the nodes uner <channel>

    for (int i = 0; i < nodeChannel.ChildNodes.Count; i++)

    {

    // Untill you find the <item> node

    if (nodeChannel.ChildNodes[i].Name == "item")

    {

    // Store the item as a node

    nodeItem = nodebchannel.ChildNodes[i];

    // If the <title> tag matches the current selected item

    if (nodeItem["title"].InnerText == lstNews.SelectedItems[0].Text)
    
    {

    // It's the item we were looking for, get the description

    txtContent.Text = nodeItem["description"].InnerText;

    // We don't need to loop anymore

    break;

    }

    }

    }

}

// When double clicked open the web page

System.Diagnostics.Process.Start(lstNews.SelectedItems[0].SubItems[1].Text);


User is offlineProfile CardPM

Go to the top of the page

Sneblot
post 27 May, 2008 - 05:07 AM
Post #3


D.I.C Head

**
Joined: 9 Feb, 2007
Posts: 240


My Contributions


Ok got that but how do I make the end users window Im really stuck HTML and CSS you just type it and jobs a done, with this though??
User is offlineProfile CardPM

Go to the top of the page

crcapps
post 27 May, 2008 - 07:06 AM
Post #4


D.I.C Head

**
Joined: 13 May, 2008
Posts: 53


My Contributions


Right. Those aren't programming languages. One is a markup language, the other is a style definition language.
A program needs to be compiled, or, at least interpreted. (.Net is a little of each, sort of).

Compiling and linking is done by clicking the "Build Solution" button. This will, by default, make a debug build of your program. Then click the "Run" button, which will execute your debug binary.

Now, to get a user's window, you are going to have to add those labels and text boxes to a window, which you create by adding one to your project. Somewhere there should be an example project you could find that could give you an idea... it looks like you are on the right track, so I believe you could figure it out. Unfortunately, the only examples of a GUI project I have here at work are GTK, not Windows Forms.

Another good thing to check out is the Foreach loop. It might be better than using a plain for loop on whatever.Count, with an an increment.

QUOTE(Sneblot @ 27 May, 2008 - 06:07 AM) *

Ok got that but how do I make the end users window Im really stuck HTML and CSS you just type it and jobs a done, with this though??

User is offlineProfile CardPM

Go to the top of the page

Sneblot
post 27 May, 2008 - 11:59 AM
Post #5


D.I.C Head

**
Joined: 9 Feb, 2007
Posts: 240


My Contributions


QUOTE(crcapps @ 27 May, 2008 - 08:06 AM) *

Right. Those aren't programming languages. One is a markup language, the other is a style definition language.
A program needs to be compiled, or, at least interpreted. (.Net is a little of each, sort of).



Thats all im used to I know its not programming I just really put it in for an exampe wink2.gif. I'll look at how to convert code to the finished programme as I have coded a few things in the last two days but as of yet dont know how to get to he finished artical will look it up on google when I get home. Cheers for every ones help.

This post has been edited by Sneblot: 27 May, 2008 - 12:00 PM
User is offlineProfile CardPM

Go to the top of the page

crcapps
post 27 May, 2008 - 12:29 PM
Post #6


D.I.C Head

**
Joined: 13 May, 2008
Posts: 53


My Contributions


Getting to the finished product entails adding your files to a visual studio or monodevelop project. I am guessing you're on windows using visual studio, so what you need to do is create a new project, right click on the project name in the solution explorer pane, and click Add files...
There will be a file chooser dialog in which you can select them, and, when you do, copy or move them, don't just leave them linked.
At this point, you will need to add the code to add the controls to a window after the part where you create them (best actually to create the dropdown in designer mode, then use the code to add the items to it, like you did).

Then, hit "Build Solution," this will make an exe for you to run. It will be in the bin\debug\ directory or something like that by default, but, you don't have to navigate to it, you can just click the "Run" button.

That's how you get the finished product out there.

tl;dr:
1) Make a new visual studio project
2) Add your source to it.
3) Hit the "Build Solution" button.
4) ??
5) profit

QUOTE(Sneblot @ 27 May, 2008 - 12:59 PM) *

QUOTE(crcapps @ 27 May, 2008 - 08:06 AM) *

Right. Those aren't programming languages. One is a markup language, the other is a style definition language.
A program needs to be compiled, or, at least interpreted. (.Net is a little of each, sort of).



Thats all im used to I know its not programming I just really put it in for an exampe wink2.gif. I'll look at how to convert code to the finished programme as I have coded a few things in the last two days but as of yet dont know how to get to he finished artical will look it up on google when I get home. Cheers for every ones help.

User is offlineProfile CardPM

Go to the top of the page

Sneblot
post 27 May, 2008 - 03:07 PM
Post #7


D.I.C Head

**
Joined: 9 Feb, 2007
Posts: 240


My Contributions


Cheers dude thank you for all the help I will build this and one other thing I built tonight.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:33AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month