Results 1 to 4 of 4

Thread: Function Error -C#

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    Function Error -C#

    Hello Everybody:
    I am trying to develop a function to concate three strings . When I compile it gives me a runtime error .Can anyone tell me whats wrong?

    The error is :

    public string Variable(string UserName, string PhoneNumber, string RemoteYN)

    {
    txtUserName.Text=UserName ;
    txtPhoneNumber.Text=PhoneNumber;
    txtRemoteString.Text=RemoteYN ;

    // Variable;
    return Variable(UserName,PhoneNumber,RemoteYN);


    }



    private void cmdOutPut_Click(object sender, System.EventArgs e)


    { txtOutput.Text= Variable(UserName,PhoneNumber,RemoteYN);
    txtOutput.Text = txtUserName.Text + " " + txtPhoneNumber.Text + " " + txtRemoteString.Text;


    }


    The run time error is : System.StackOverflowException' occurred in system.windows.forms.dll


    Pls guide...

    Rahil

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    looks like you need to be using a void not a string for Variable , eg:
    VB Code:
    1. public void Variable(string UserName, string PhoneNumber, string RemoteYN)
    2.  
    3. {
    4.     string strResult = string.Empty; // initialize the string
    5.  
    6.     strResult +=UserName + " " ;
    7.     strResult +=PhoneNumber + " ";
    8.     strResult +=RemoteYN ;
    9.    
    10.     txtOutput.Text = strResult;
    11. }
    12.  
    13. private void cmdOutPut_Click(object sender, System.EventArgs e)
    14. {
    15.     Variable(txtUserName.Text,txtPhoneNumber.Text,txtRemoteString.Text);
    16. }
    this line ...
    return Variable(UserName,PhoneNumber,RemoteYN);
    will be causing the error , because you are trying to return part of the calling string.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Try using the StringBuilder class, because everytime you concatenate strings it is creating a new instance of the string.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    why not
    Code:
    return string1 + string2 + string3;
    or
    Code:
    string s = "";
    s += string1;
    s += string2;
    s += string3;
    return s;
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width