Web Design and Development Forums

[SOLVED] [C#] Having some problems.

This is a discussion on "[SOLVED] [C#] Having some problems." within the Perl, Python, Ruby and Others section. This forum, and the thread "[SOLVED] [C#] Having some problems. are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > Perl, Python, Ruby and Others

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Nov 14th, 2007, 21:17   #1 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
[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: Select all
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: Select all
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
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


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 Nov 15th, 2007, 06:46   #2 (permalink)
 
c010depunkk's Avatar
 
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 612
Blog Entries: 2
Send a message via MSN to c010depunkk
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: Select all
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: Select all
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();
    }
}
__________________
Web design is the creation of digital environments that facilitate and encourage human activity; reflect or adapt to individual voices and content; and change gracefully over time while always retaining their identity.

~ www.c010depunkk.com ~ the hang-out of a web developer

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 Nov 15th, 2007, 07:23   #3 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
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
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


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 Nov 15th, 2007, 12:20   #4 (permalink)
 
c010depunkk's Avatar
 
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 612
Blog Entries: 2
Send a message via MSN to c010depunkk
Re: [C#] Having some problems.

Arrays are not so cool in C#. Check out ArrayLists or Lists.
__________________
Web design is the creation of digital environments that facilitate and encourage human activity; reflect or adapt to individual voices and content; and change gracefully over time while always retaining their identity.

~ www.c010depunkk.com ~ the hang-out of a web developer

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 Nov 15th, 2007, 16:32   #5 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
Re: [C#] Having some problems.

Uh what's the difference?
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


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 Nov 15th, 2007, 17:40   #6 (permalink)
 
c010depunkk's Avatar
 
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 612
Blog Entries: 2
Send a message via MSN to c010depunkk
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).
__________________
Web design is the creation of digital environments that facilitate and encourage human activity; reflect or adapt to individual voices and content; and change gracefully over time while always retaining their identity.

~ www.c010depunkk.com ~ the hang-out of a web developer

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 Nov 15th, 2007, 17:48   #7 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
Re: [SOLVED] [C#] Having some problems.

Got it working thanks to you and some other people on other forums
Thanks +rep
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


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

Thread Tools
Rate This Thread
Rate This Thread:

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 CSS Forum 13 Jan 30th, 2008 13:45
[SOLVED] Problems with arrays Scream JavaScript Forum 2 Jan 10th, 2008 16:15
[SOLVED] Problems with centering in CSS. mcdanielnc89 HTML Forum 26 Nov 1st, 2007 06:07
[SOLVED] Php code problems longstand PHP Forum 3 Oct 15th, 2007 10:53
[SOLVED] Haveing css problems.. mcdanielnc89 CSS Forum 8 Sep 21st, 2007 00:28



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:04.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59