Results 1 to 12 of 12

Thread: [RESOLVED] Returning other type of values

  1. #1

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Resolved [RESOLVED] Returning other type of values

    Hi, i created a string that returns another string based on other string but what if that string thats based on is "" (nothing) i want to return a messagebox, how can i return a messagebox instead of a string ?
    C# and WPF developer
    My Website:
    http://singlebits.com/

  2. #2
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Returning other type of values

    I think this is a very bad idea... Is there any other way you can get around this? Perhaps before calling the method see if the string is "" and then return a messagebox?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  3. #3

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: Returning other type of values

    like this ??

    Code:
    string str;
    if (str.equals(""))
    {
    messagebox.show("Error")
    }
    ?? yeah i could do that but theres no way to do it like i said ?
    C# and WPF developer
    My Website:
    http://singlebits.com/

  4. #4
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Re: Returning other type of values

    Well the only problem with that is you need a return type for your method. Since you said it otherwise returns a string im assuming the current return type for the method is string, and if you just show a messagebox your method wont return anything...
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Returning other type of values

    But, if the current return type for the method is string, then either that string will contain something or it will contain nothing.

    So, if I'm reading this correctly, it will do something if the string is not empty OR show a message box if it is, right?

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Returning other type of values

    You could always give the return type of the method as 'object' that way you can return a string or false (if the function is displaying a messagebox itself), for example.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  7. #7

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: Returning other type of values

    thanks..........i've solve my problem
    C# and WPF developer
    My Website:
    http://singlebits.com/

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Returning other type of values

    How did you solve your problem?

    Post your resolution please, as it might help others with the same or similiar problem.

    Thanks.

  9. #9

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [RESOLVED] Returning other type of values

    i thought i resolved but im wrong.
    C# and WPF developer
    My Website:
    http://singlebits.com/

  10. #10
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: [RESOLVED] Returning other type of values

    Quote Originally Posted by Pac_741
    i thought i resolved but im wrong.
    Care to elaborate?
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  11. #11

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [RESOLVED] Returning other type of values

    i got it by myself!! wuuu!

    okay here it is:
    Code:
    private string ToUpper(string Toupp)
            {
                string temp = null;
                if (Toupp.Equals(""))
                {
                    MessageBox.Show("Error");
    
                }
                else
                {
                    temp = Toupp.Substring(0, 1);
                    return temp.ToUpper() + Toupp.Remove(0, 1);
                }
                return temp;
            }
    that the code do its it turn the first character of the ToUpp string.
    C# and WPF developer
    My Website:
    http://singlebits.com/

  12. #12

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [RESOLVED] Returning other type of values

    it turns it into a capitalized leter.
    C# and WPF developer
    My Website:
    http://singlebits.com/

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