Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > Other Languages

Reply
 
LinkBack Thread Tools
Old November 14th, 2007, 05:17 PM   #1
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
[SOLVED] [C#] Having some problems.

Creating a web application that finds some tags and displays them
I've run into some errors and I'm completely stuck!

Here is my code:
Code:
using System;
using System.Text.RegularExpressions;

struct info
{
    public string output;
    public Match header;
    public Match title;
    public string URL;
    public void results()
    {
        Console.WriteLine("-=-RESULTS-=-");
        Console.WriteLine("Website Page Title (title): {0}", title);
        Console.WriteLine("Website header (h1): {0}", header);
    }
    public static Match find(string reg) {
        Regex r = new Regex(reg);
        Match m = r.Match(output);
        return m;
    }
}

class WebApp
{
    public static void Main()
    {
        info web;
        System.Console.Write("Enter a URL to analyze then press enter.\n e.g. http://www.alexgeek.co.uk \n >");
        string input = System.Console.ReadLine();
        if (input == null)
        {
            web.URL = "http://www.alexgeek.co.uk";
        }
        else
        {
            web.URL = input;
        }
        web.output = new System.Net.WebClient().DownloadString(web.URL);
        web.header = web.find(@"<h1>(.)+</h1>");
        web.results();
    }
}
And the errors:
Code:
fileWrite.cs(19,27): error CS0120: An object reference is required for the
        nonstatic field, method, or property 'info.output'
fileWrite.cs(7,19): (Location of symbol related to previous error)
fileWrite.cs(40,22): error CS0176: Static member 'info.find(string)' cannot be
        accessed with an instance reference; qualify it with a type name instead
fileWrite.cs(17,25): (Location of symbol related to previous error)
I've not a clue what do! Please help
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 15th, 2007, 02:46 AM   #2
Highly Reputable Member
 

Join Date: Apr 2007
Location: Willich, Germany
Age: 22
Posts: 592
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough
Re: [C#] Having some problems.

You've got a couple of problems.

1. You didn't instantiate your "web" variable. You have to say:
Code:
info web=new info();
2. If you want to call a function using an instance of your struct (web.find("//")) then the function can't be static.


That's all the errors I could find, but while I'm at it thought I'd also drop a few comments about your programming logic (I'm feeling a bit patronizing this morning....).

If I was you I wouldn't have "info" be a struct, a class would make more sense. I would then make the "find" function private and the class would then find and store the page elements. Elements would be written into private string variables using functions and then use getters/setters to make then visible (read-only). Output would then be done in the main program, not the in the class.

I haven't tested this, but it does compile....:
Code:
class info {
    private string h1;
    public string H1 {
        get {
            return h1;
        }
    }
    public void findH1() {
        h1=find(@"<h1>(.)+</h1>");
    }

    private string find(string reg) {
        Regex r=new Regex(reg);
        Match m=r.Match(output);
        return m.ToString();
    }
}
c010depunkk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 15th, 2007, 03:23 AM   #3
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: [C#] Having some problems.

I've got it fixed thanks I may try your method if I have chance! thanks.
needed to instantiate it and remove static from function.
Do you know how I could put all the matches of <h2>(.)+</h2> into an array (public header2)?
I'm pretty stumped
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 15th, 2007, 08:20 AM   #4
Highly Reputable Member
 

Join Date: Apr 2007
Location: Willich, Germany
Age: 22
Posts: 592
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough
Re: [C#] Having some problems.

Arrays are not so cool in C#. Check out ArrayLists or Lists.
c010depunkk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 15th, 2007, 12:32 PM   #5
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: [C#] Having some problems.

Uh what's the difference?
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 15th, 2007, 01:40 PM   #6
Highly Reputable Member
 

Join Date: Apr 2007
Location: Willich, Germany
Age: 22
Posts: 592
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough
Re: [C#] Having some problems.

ArrayLists are dynamic collections of objects. You can add and remove elements on the fly. Arrays have a set size that can't be changed once they've been initialized. A List is like an ArrayList but it has a Type (string, int, double).
c010depunkk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 15th, 2007, 01:48 PM   #7
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: [SOLVED] [C#] Having some problems.

Got it working thanks to you and some other people on other forums
Thanks +rep
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Fly-out menu problems karinne HTML, XHTML and CSS 13 January 30th, 2008 09:45 AM
[SOLVED] Problems with arrays Scream JavaScript 2 January 10th, 2008 12:15 PM
[SOLVED] Problems with centering in CSS. mcdanielnc89 HTML, XHTML and CSS 26 November 1st, 2007 03:07 AM
[SOLVED] Php code problems longstand PHP 3 October 15th, 2007 06:53 AM
[SOLVED] Server Problems businessservicesuk The Café 11 October 8th, 2007 11:01 AM


Search Engine Optimization by vBSEO 3.2.0 RC8