Jump to content

Help with If statement and textboxes

Go to solution Solved by Kaine tyrie,

I had to  convert Caramel to string first so now its this:

 

Caramel = Convert.ToString(Morph_1.Text);
            if (Morph_1.Text == Caramel)
            {
                Morph_Output.Items.Add("amber");
            }

I'm trying to set up a corn snake morph calculator and I have been stopped at the first hurdle! When trying to read if the text1 is "Caramel" and then to output the result "Amber" it doesn't work but when I change it from == to != it works.

Originally I tried Comboboxes to no avail. Then I tried using different methods again to no avail.

`private void button1_Click(object sender, EventArgs e)
        {
            if (Morph_1.Text==Caramel)
            {
                Morph_Output.Items.Add("amber");
            }



        }`

When the user puts "Caramel" into the text box it should output "Amber" After I have this part fixed I want to have it so you can input two morphs and get the result E.g "Caramel + Hypomelanistic = Amber"

Any help and advice are greatly appreciated, this is my first question on here and not really sure if this is laid out correctly or not.

Link to comment
Share on other sites

Link to post
Share on other sites

Doesn't '==' set the variable? I think you might want to use just '=' for the check.

 

@Kaine tyrie

Edited by The1Dickens
Tagging OP
Spoiler

CPU: Intel i7 6850K

GPU: nVidia GTX 1080Ti (ZoTaC AMP! Extreme)

Motherboard: Gigabyte X99-UltraGaming

RAM: 16GB (2x 8GB) 3000Mhz EVGA SuperSC DDR4

Case: RaidMax Delta I

PSU: ThermalTake DPS-G 750W 80+ Gold

Monitor: Samsung 32" UJ590 UHD

Keyboard: Corsair K70

Mouse: Corsair Scimitar

Audio: Logitech Z200 (desktop); Roland RH-300 (headphones)

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, The1Dickens said:

Doesn't '==' set the variable? I think you might want to use just '=' for the check.

 

@Kaine tyrie

I'm not entirely sure why but = doesn't work either only !=

@The1Dickens

Link to comment
Share on other sites

Link to post
Share on other sites

 

12 minutes ago, Kaine tyrie said:

I'm not entirely sure why but = doesn't work either only !=

@The1Dickens

Well, != means 'not equal'. So, there must be something somewhere else in the code that is failing to set the Text variable to Caramel. It is being read as 'if Text does not equal Caramel, perform the next step'.

Spoiler

CPU: Intel i7 6850K

GPU: nVidia GTX 1080Ti (ZoTaC AMP! Extreme)

Motherboard: Gigabyte X99-UltraGaming

RAM: 16GB (2x 8GB) 3000Mhz EVGA SuperSC DDR4

Case: RaidMax Delta I

PSU: ThermalTake DPS-G 750W 80+ Gold

Monitor: Samsung 32" UJ590 UHD

Keyboard: Corsair K70

Mouse: Corsair Scimitar

Audio: Logitech Z200 (desktop); Roland RH-300 (headphones)

 

Link to comment
Share on other sites

Link to post
Share on other sites

40 minutes ago, Kaine tyrie said:

well prior to that code i have:

string Caramel;

 

@The1Dickens

Welp, I think this is beyond me, then. Sorry.

Spoiler

CPU: Intel i7 6850K

GPU: nVidia GTX 1080Ti (ZoTaC AMP! Extreme)

Motherboard: Gigabyte X99-UltraGaming

RAM: 16GB (2x 8GB) 3000Mhz EVGA SuperSC DDR4

Case: RaidMax Delta I

PSU: ThermalTake DPS-G 750W 80+ Gold

Monitor: Samsung 32" UJ590 UHD

Keyboard: Corsair K70

Mouse: Corsair Scimitar

Audio: Logitech Z200 (desktop); Roland RH-300 (headphones)

 

Link to comment
Share on other sites

Link to post
Share on other sites

im guessing you want 

 

if (Morph_1.Text=="Caramel") 

 

or whatever string comparison method your language is supposed to use

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, elpiop said:

im guessing you want 

 

if (Morph_1.Text=="Caramel") 

 

or whatever string comparison method your language is supposed to use

yep pretty much yet that doesn't work 

Link to comment
Share on other sites

Link to post
Share on other sites

Can't help you with so little code, we can't even see what "Morph_1" is and where it comes from, where the user inputs the text, what the output is...

 

Also please use code blocks.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, Kaine tyrie said:

yep pretty much yet that doesn't work 

Let me guess, you are typing : caramel and NOT Caramel

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, Sauron said:

Can't help you with so little code, we can't even see what "Morph_1" is and where it comes from, where the user inputs the text, what the output is...

 

Also please use code blocks.

image.png.640c4210ab72949c4c212ee3f1a98e31.png

 

the input is a text box, they then press the button and the output is put into the listbox to the right

Link to comment
Share on other sites

Link to post
Share on other sites

I had to  convert Caramel to string first so now its this:

 

Caramel = Convert.ToString(Morph_1.Text);
            if (Morph_1.Text == Caramel)
            {
                Morph_Output.Items.Add("amber");
            }

Link to comment
Share on other sites

Link to post
Share on other sites

43 minutes ago, Kaine tyrie said:

I had to  convert Caramel to string first so now its this:

 

Caramel = Convert.ToString(Morph_1.Text);
            if (Morph_1.Text == Caramel)
            {
                Morph_Output.Items.Add("amber");
            }

That looks like it would always be true even when the input is different

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×