Need help with coding

Discussion in 'General Off-Topic Chat' started by R2DJ, Nov 11, 2009.

Nov 11, 2009

Need help with coding by R2DJ at 8:11 PM (808 Views / 0 Likes) 9 replies

  1. R2DJ
    OP

    Member R2DJ GBAtemp Advanced Maniac

    Joined:
    Jan 30, 2008
    Messages:
    1,900
    Location:
    London
    Country:
    United Kingdom
    I'm doing a C sharp homework which is due tomorrow and I can't seem to get things right. Please help!

    CODE
    private void button1_Click(object sender, EventArgs e)
    {
    string userInput;
    userInput = this.textBox1.Text;

    if (userInput.Contains("$"))
    {
    this.lblOutput.Text = "Thank you";
    this.lblOutput.ForeColor = Color.Green;
    }
    else
    {
    this.lblOutput.Text = "Error";
    this.lblOutput.ForeColor = Color.Red;
    }
    }



    This code is embedded in a button in the form I made. This code means that if "$" is entered in the text box when the button is pressed, it will display the message "Thank You". Otherwise, it will say "Error".

    Now what I need to do is to change the code so "Thank You" will be displayed when a character between 0-9 is entered. Can anyone help me?

    I would appreciate the help! Also, if you got a very reliable source for learning C# and stuff, please give them to me.
     
  2. tj_cool

    Supervisor tj_cool Stuff

    Joined:
    Jan 7, 2009
    Messages:
    9,941
    Location:
    This planet
    Country:
    Belgium
    I know nothing of c# so perhaps this doesn't work, but I'll try anyway [​IMG]

    1) if (userInput.Contains("£") || userInput.Contains("%"))
    2) if (userInput.Contains("$") && userInput.Contains("£"))
    3) no idea [​IMG]

    someone else correct me please [​IMG]
     
  3. Linkiboy

    Member Linkiboy GBAtemp Testing Area

    Joined:
    May 14, 2006
    Messages:
    4,888
    Country:
    United States
    Okay, I don't know C# either but here is how it would happen for #3 in Java(pseudocode):

    x =scanner.nextint (this gets an integer value)
    if (x>=0 && x
     
  4. R2DJ
    OP

    Member R2DJ GBAtemp Advanced Maniac

    Joined:
    Jan 30, 2008
    Messages:
    1,900
    Location:
    London
    Country:
    United Kingdom
     
  5. R2DJ
    OP

    Member R2DJ GBAtemp Advanced Maniac

    Joined:
    Jan 30, 2008
    Messages:
    1,900
    Location:
    London
    Country:
    United Kingdom
    BUMP
     
  6. Psyfira

    Member Psyfira Credit: 0ml. Insert tea to continue

    Joined:
    Dec 31, 2003
    Messages:
    3,887
    Location:
    England
    Country:
    United Kingdom
    Userinput is being pulled in as a string. You may need to convert it to a number datatype before the comparisons will work.
    Converting strings to numbers
     
  7. R2DJ
    OP

    Member R2DJ GBAtemp Advanced Maniac

    Joined:
    Jan 30, 2008
    Messages:
    1,900
    Location:
    London
    Country:
    United Kingdom
    I don't get it...

    I'm a complete noob in programming. I have only learned basic stuff like designing forms. Not into deep coding and stuff yet so I'm not really familiar with most of the codes.

    Something tells me that I just need to do a slight change in that line I highlighted in bold to get it working but...
     
  8. Linkiboy

    Member Linkiboy GBAtemp Testing Area

    Joined:
    May 14, 2006
    Messages:
    4,888
    Country:
    United States
    What I got from that page (no way to test it but it looks right)
    CODEprivate void button1_Click(object sender, EventArgs e)
    {
    string userInput;
    double tempnumber;
    userInput = this.textBox1.Text;
    tempnumber = Convert.ToDouble(userInput);

    if ((tempnumber=0))
    {
    this.lblOutput.Text = "Thank you";
    this.lblOutput.ForeColor = Color.Green;
    }
    else
    {
    this.lblOutput.Text = "Error";
    this.lblOutput.ForeColor = Color.Red;
    }
    }
     
  9. R2DJ
    OP

    Member R2DJ GBAtemp Advanced Maniac

    Joined:
    Jan 30, 2008
    Messages:
    1,900
    Location:
    London
    Country:
    United Kingdom
    This only allows me to enter one character and it has to be a number. Oh well, this will do..

    Thanks for all the help guys [​IMG] Now I get 10% of marks on my module [​IMG]
     
  10. Linkiboy

    Member Linkiboy GBAtemp Testing Area

    Joined:
    May 14, 2006
    Messages:
    4,888
    Country:
    United States
    What else were you expecting it to do...?

    If you want error checking or whatever else, write it yourself.
     

Share This Page