Need help with coding

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
1
Location
London
XP
845
Country
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.
 

tj_cool

Site dev
Supervisor
Joined
Jan 7, 2009
Messages
10,064
Trophies
3
Location
This planet
XP
3,130
Country
Belgium
I know nothing of c# so perhaps this doesn't work, but I'll try anyway
tongue.gif


1) if (userInput.Contains("£") || userInput.Contains("%"))
2) if (userInput.Contains("$") && userInput.Contains("£"))
3) no idea
tongue.gif


someone else correct me please
smile.gif
 

Mangofett

GBAtemp Testing Area
Member
Joined
May 14, 2006
Messages
4,885
Trophies
2
Age
20
XP
1,116
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
 

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
1
Location
London
XP
845
Country
tj_cool said:
I know nothing of c# so perhaps this doesn't work, but I'll try anyway
tongue.gif


1) if (userInput.Contains("£") || userInput.Contains("%"))
2) if (userInput.Contains("$") && userInput.Contains("£"))
3) no idea
tongue.gif


someone else correct me please
smile.gif

These worked. Thanks a bunch!
happy.gif


Linkiboy said:
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
 

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
1
Location
London
XP
845
Country
Psyfira said:
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
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...
 

Mangofett

GBAtemp Testing Area
Member
Joined
May 14, 2006
Messages
4,885
Trophies
2
Age
20
XP
1,116
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;
}
}
 

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
1
Location
London
XP
845
Country
Linkiboy said:
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;
}
}
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
smile.gif
Now I get 10% of marks on my module
tongue.gif
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • SylverReZ @ SylverReZ:
    An app exists for Android called Rekado which is a payload injector for the RCM exploit to work. Don't know if it's still active.
  • Xdqwerty @ Xdqwerty:
    Brb, and if not, good night
  • MrGreenleaves @ MrGreenleaves:
    hi, i have a problem with a game in twligth menu, the game is bleach dark souls, the save get corrups allways no matter if you try with USA version or Europre version, i use my nintendo dsi and my nintendo dxi xl, i have install the lates version of twiligth menu and nds bootstap, someone can helpe me?
  • K3Nv3 @ K3Nv3:
    Why are Sherlock Holmes games so expensive
  • BigOnYa @ BigOnYa:
    That's Elementary, my dear Watson
  • K3Nv3 @ K3Nv3:
    That thing you didn't graduate from?
  • I @ imafsiry:
    Requesting access to USB device...NotFoundError: Failed to execute 'requestDevice' on 'USB': No device selecte @
  • I @ imafsiry:
    thats what shows when i plug it in
  • SylverReZ @ SylverReZ:
    @imafsiry, What method? Phone or RCM Loader?
  • RedColoredStars @ RedColoredStars:
    @imafsiry You just install Rekado to your phone and then plug your Switch into your phone when it's in RCM mode. Rekado should automatically pop up on your phone and ask which payload you want to send.
    +1
  • RedColoredStars @ RedColoredStars:
    @imafsiry You can also set it to auto launch the payload of your choice so no user input is even necessary.
    +1
  • TotalJustice @ TotalJustice:
    thats what i use also. works better if you launch hekate from rekado as you won't need to update the payload
    +1
  • TotalJustice @ TotalJustice:
    as hekate launches the latest payload on the sd card (unless the sent payload is newer)
  • JollyBaker @ JollyBaker:
    Odd seeing our 90s kid foot man with a default pfp honestly
  • SylverReZ @ SylverReZ:
    @JollyBaker, He needs to bring back his old profile pictures.
  • K3Nv3 @ K3Nv3:
    I saw gelatine bomb pops sounded nasty af
  • SylverReZ @ SylverReZ:
    Gelatin bombs? I'm confused.
  • The Real Jdbye @ The Real Jdbye:
    TIL flatulist used to be a legitimate profession
  • The Real Jdbye @ The Real Jdbye:
    i'd make a great flatulist if i lived in the middle ages
    +1
  • Xdqwerty @ Xdqwerty:
    Good morning
    Xdqwerty @ Xdqwerty: Good morning