Need help with coding

R2DJ

Well-Known Member
OP
Member
Joined
Jan 30, 2008
Messages
1,898
Trophies
0
Location
London
XP
815
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
2
Location
This planet
XP
3,075
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
1
Age
19
XP
1,048
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
0
Location
London
XP
815
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
0
Location
London
XP
815
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
1
Age
19
XP
1,048
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
0
Location
London
XP
815
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
  • BigOnYa @ BigOnYa:
    Steam games
  • K3N1 @ K3N1:
    Ye there's still a few repack sites out there but da temp rulez
    +1
  • BigOnYa @ BigOnYa:
    if i had a deck, i would do windows also
  • K3N1 @ K3N1:
    Configuring Controlls on windows is the only annoyance
  • BigOnYa @ BigOnYa:
    Can you use Xbox controller w it?
  • K3N1 @ K3N1:
    Why it has built in controls lol
  • BigOnYa @ BigOnYa:
    what about when hooked to tv/monitor
  • K3N1 @ K3N1:
    In dock mode with bt probably ye
  • BigOnYa @ BigOnYa:
    I've been working on making a wheel controller with arduino, 3d printed round knob, and a potientometer.to play breakout and games like that. Kinda of like the old Atari 2600 controllers.
    +1
  • BigOnYa @ BigOnYa:
    But it works on windows and retroarch.I could prob buy one, but thats no fun!
  • K3N1 @ K3N1:
    Gears irl
  • BigOnYa @ BigOnYa:
    Spam Time!
  • BigOnYa @ BigOnYa:
    I never knew they made a Maple flavor.
  • K3N1 @ K3N1:
    Sweet spam
  • D @ ds_allstars:
    Am I able to make a DS game like All-Stars SNES & Wii without any programming skills?
  • FlareReZ @ FlareReZ:
    @ds_allstars, You need programming skills to make a DS game lol.
    +1
  • BigOnYa @ BigOnYa:
    @FlareReZ what language would you reccomend to start with, to learn DS coding? Just curious
  • FlareReZ @ FlareReZ:
    devkitPro by defaults use C and C++. So I suppose you start off with C first and then move onto C++.
    +1
  • FlareReZ @ FlareReZ:
    Because C++ is more complex than C.
    +1
  • BigOnYa @ BigOnYa:
    Ive dabbled a little with C (i think) using arduinos, but yea way beyond me!
    +1
  • The Real Jdbye @ The Real Jdbye:
    @BigOnYa i wouldn't start with DS (or C for that matter)
    +1
  • D @ ds_allstars:
    It feels hard so I'll try to make a remake of NSMB2 on DS
  • D @ ds_allstars:
    And how do I make the semi-solid platforms?
  • D @ ds_allstars:
    Like the platforms in 2-5 and SKJmin's NSMB3 DS
    D @ ds_allstars: Like the platforms in 2-5 and SKJmin's NSMB3 DS