Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2007, 09:32 AM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Running a class function c#

Hi

I am having a problem running a function i have created in a class file. Each time I run the page using the function it comes up with the error: CS0103: The name 'Mid' does not exist in the current context

Here is how I have done it:
1. I created a new class file, which is residing in App_code folder
code as follows:
----------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Mid
/// </summary>
   public class Mid
    {
        public string Mid(string textString, int Start, int Length)
        {
            if (Start <= 0) { return null; }
            if (Length > textString.Length - Start) { return textString; }

            textString = textString.Substring(Start - 1, Length);
            return textString;
        }
    }
--------------
But when I run the page which is using this function it gives me that error.

I ll appreciate any help.

 
Old September 13th, 2007, 11:16 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to look at some example classes. You want a different name for the class and the function ideally.
If you make the method static you can call it with Mid.Mid(), otherwise you need
Code:
Mid myMid = new Mid(); myMid.Mid();

--

Joe (Microsoft MVP - XML)
 
Old September 13th, 2007, 11:19 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The error is being thrown from your calling page, not the above class. Most likely, you are trying to use the class but have not declared it in your calling page.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
The DBNull Class and IsDBNull Function dschnedar BOOK: Professional Visual Basic 2008 ISBN: 978-0-470-19136-1 1 September 27th, 2008 09:13 AM
return collection by function in class jimusa Visual Basic 2005 Basics 1 July 30th, 2008 03:18 PM
function return collection in class by VB jimusa Visual Studio 2005 1 July 30th, 2008 03:12 PM
Running Count Function jdbash1 Access VBA 1 June 7th, 2007 11:03 AM
How do I make a function return a class? vertigo VB How-To 3 November 3rd, 2004 06:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.