Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. if statements

if statements

Scheduled Pinned Locked Moved C#
question
16 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T TWatson47

    when I set the values to 0 or 1, it is like I am forcing the statement to be true or false. Like if there is no joint member, I would like it to be false and use the else statement. If there is a joint member I would like it to be true and use the if statement. How should write the code to allow the selection to come from when they input the criteria. Thanks so much for your help and speedy response

    E Offline
    E Offline
    Ennis Ray Lynch Jr
    wrote on last edited by
    #4

    I still have no idea what you are asking.

    On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage

    T 1 Reply Last reply
    0
    • T TWatson47

      I am trying to right an if statement for a project that pulls data from a table. like for instancte I have int Mem = 0; if (Mem ==1)//for true { lbMember.text = applicant.getfname() +" "+ applicant.getlname(); lbAdd.Text = address.getAddress(); } else lbMember.text = "not selected"; } when I use int Mem = 0; I will get the else statement when I use int Mem = 1; then I get the if selection how do I get it to make the selection of choice from where the data is put in. Thanks in advance

      S Offline
      S Offline
      Sean Michael Murphy
      wrote on last edited by
      #5

      TWatson47 wrote:

      int Mem = 0; if (Mem ==1)//for true

      Not trying to second guess your logic, but why wouldn't you want to use a bool type variable to do this?

      bool mem = false;
         
      // Some code that modifies the state of "mem"
         
      if (mem) {
         lbMember.text = applicant.getfname() +" "+ applicant.getlname();
         lbAdd.Text = address.getAddress();
      } else {
         // mem == false
         lbMember.text = "not selected";
      }

      Why co-opt an int? That's a retro, "C"-type thing to do... Just wondering. Sean

      T 1 Reply Last reply
      0
      • T TWatson47

        I am trying to right an if statement for a project that pulls data from a table. like for instancte I have int Mem = 0; if (Mem ==1)//for true { lbMember.text = applicant.getfname() +" "+ applicant.getlname(); lbAdd.Text = address.getAddress(); } else lbMember.text = "not selected"; } when I use int Mem = 0; I will get the else statement when I use int Mem = 1; then I get the if selection how do I get it to make the selection of choice from where the data is put in. Thanks in advance

        E Offline
        E Offline
        eggsovereasy
        wrote on last edited by
        #6

        Are you saying you want to base your if/else on user input? If so you can add a radio button with yes and no and do something like this if (rbMember.SelectedItem.Text == Yes) {    // blah blah } else {    // blah blah }

        1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          I still have no idea what you are asking.

          On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage

          T Offline
          T Offline
          TWatson47
          wrote on last edited by
          #7

          ok, I will try to explain a little better. I have created some forms that say for instance a new member comes into a bank and want a loan. When the Agent puts there info into a build it is then saved to a server(database). The Idea is to have there info pull up with the selected loan form that they are wanting. Say for instance a auto loan. I have been able to pull the form with there info on it fine. However, I wanted to add some logic in place that looks to see if there is a joint member. If there is then hit all the tables requesting the joint information and load to the form. My problem is that when I set the variable, say for instance Jmem = 0, even if there is a joint member it comes up as false, and gives the else statement. My question is what do I need to add to the previous if statement that will except the joint member as true. The same if for beneficiary also. I hope this helps in understanding Thanks

          E 1 Reply Last reply
          0
          • T TWatson47

            ok, I will try to explain a little better. I have created some forms that say for instance a new member comes into a bank and want a loan. When the Agent puts there info into a build it is then saved to a server(database). The Idea is to have there info pull up with the selected loan form that they are wanting. Say for instance a auto loan. I have been able to pull the form with there info on it fine. However, I wanted to add some logic in place that looks to see if there is a joint member. If there is then hit all the tables requesting the joint information and load to the form. My problem is that when I set the variable, say for instance Jmem = 0, even if there is a joint member it comes up as false, and gives the else statement. My question is what do I need to add to the previous if statement that will except the joint member as true. The same if for beneficiary also. I hope this helps in understanding Thanks

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #8

            If that is the case consider using booleans. Also from what I can gather it entirely possible that your value is not being set correctly if the if statement is not evaluating. Try setting a break on the if and checking the value of the variables. There are a lot of particular scenarios that can be causing your problem but the code

            int mem = 0;
            ..some code that may reset me
            if(mem == 1){
            ...
            }
            else{
            ...
            }

            is valid.


            On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage

            T 1 Reply Last reply
            0
            • S Sean Michael Murphy

              TWatson47 wrote:

              int Mem = 0; if (Mem ==1)//for true

              Not trying to second guess your logic, but why wouldn't you want to use a bool type variable to do this?

              bool mem = false;
                 
              // Some code that modifies the state of "mem"
                 
              if (mem) {
                 lbMember.text = applicant.getfname() +" "+ applicant.getlname();
                 lbAdd.Text = address.getAddress();
              } else {
                 // mem == false
                 lbMember.text = "not selected";
              }

              Why co-opt an int? That's a retro, "C"-type thing to do... Just wondering. Sean

              T Offline
              T Offline
              TWatson47
              wrote on last edited by
              #9

              I am new to C# I use to write in C++. Your idea looked good, however, I am still having the same problem. I am still get a false reaction even though it is true. I am getting a read out of "not selected" when it should be the members info. Any suggestions, it looked like you where on the right path. Thanks for the help

              1 Reply Last reply
              0
              • E Ennis Ray Lynch Jr

                If that is the case consider using booleans. Also from what I can gather it entirely possible that your value is not being set correctly if the if statement is not evaluating. Try setting a break on the if and checking the value of the variables. There are a lot of particular scenarios that can be causing your problem but the code

                int mem = 0;
                ..some code that may reset me
                if(mem == 1){
                ...
                }
                else{
                ...
                }

                is valid.


                On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage

                T Offline
                T Offline
                TWatson47
                wrote on last edited by
                #10

                Thanks for you help. That is excactly how I had it coded, I just wasn't sure why I was having the problems. I even tried using bool mem = false; if(mem) {... } else {... } and it did the same thing.

                E 1 Reply Last reply
                0
                • T TWatson47

                  I am trying to right an if statement for a project that pulls data from a table. like for instancte I have int Mem = 0; if (Mem ==1)//for true { lbMember.text = applicant.getfname() +" "+ applicant.getlname(); lbAdd.Text = address.getAddress(); } else lbMember.text = "not selected"; } when I use int Mem = 0; I will get the else statement when I use int Mem = 1; then I get the if selection how do I get it to make the selection of choice from where the data is put in. Thanks in advance

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #11

                  TWatson47 wrote:

                  how do I get it to make the selection of choice from where the data is put in.

                  I'm not sure what you mean ? If you mean the UI provides the case, use a checkbox.

                  Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  1 Reply Last reply
                  0
                  • T TWatson47

                    I am trying to right an if statement for a project that pulls data from a table. like for instancte I have int Mem = 0; if (Mem ==1)//for true { lbMember.text = applicant.getfname() +" "+ applicant.getlname(); lbAdd.Text = address.getAddress(); } else lbMember.text = "not selected"; } when I use int Mem = 0; I will get the else statement when I use int Mem = 1; then I get the if selection how do I get it to make the selection of choice from where the data is put in. Thanks in advance

                    G Offline
                    G Offline
                    Guffa
                    wrote on last edited by
                    #12

                    The code that you are showing is perfectly valid, and will never have the problems that you are talking about. Therefore: :: Your code is different in some way from the code that you have shown. :: Either the variable doesn't contain what you think it does, or you are doing the comparison wrong.

                    --- b { font-weight: normal; }

                    1 Reply Last reply
                    0
                    • T TWatson47

                      Thanks for you help. That is excactly how I had it coded, I just wasn't sure why I was having the problems. I even tried using bool mem = false; if(mem) {... } else {... } and it did the same thing.

                      E Offline
                      E Offline
                      Ennis Ray Lynch Jr
                      wrote on last edited by
                      #13

                      Is your project building? If you have an incorrect version the debugger will still step but perform strange actions. Very confusing but it happens.


                      On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage

                      1 Reply Last reply
                      0
                      • T TWatson47

                        I am trying to right an if statement for a project that pulls data from a table. like for instancte I have int Mem = 0; if (Mem ==1)//for true { lbMember.text = applicant.getfname() +" "+ applicant.getlname(); lbAdd.Text = address.getAddress(); } else lbMember.text = "not selected"; } when I use int Mem = 0; I will get the else statement when I use int Mem = 1; then I get the if selection how do I get it to make the selection of choice from where the data is put in. Thanks in advance

                        K Offline
                        K Offline
                        KevinMac
                        wrote on last edited by
                        #14

                        Your question interests me. What value are you storing in the database to indicate it is a joint or individual loan?

                        T 1 Reply Last reply
                        0
                        • K KevinMac

                          Your question interests me. What value are you storing in the database to indicate it is a joint or individual loan?

                          T Offline
                          T Offline
                          Tyrus182
                          wrote on last edited by
                          #15

                          okay what it sounds like is that you are trying to get data from a database and use that value to do a specific action you obviosly need someway of obtaining that data from the database i don't know how you have this information stored but if its in some sort of class then you would do something like if(Loan.JointAccount == "MyWife") { do logic here } else { do non joint logic here }

                          1 Reply Last reply
                          0
                          • T TWatson47

                            I am trying to right an if statement for a project that pulls data from a table. like for instancte I have int Mem = 0; if (Mem ==1)//for true { lbMember.text = applicant.getfname() +" "+ applicant.getlname(); lbAdd.Text = address.getAddress(); } else lbMember.text = "not selected"; } when I use int Mem = 0; I will get the else statement when I use int Mem = 1; then I get the if selection how do I get it to make the selection of choice from where the data is put in. Thanks in advance

                            C Offline
                            C Offline
                            Coding C
                            wrote on last edited by
                            #16

                            Hi, i think i got ur question. wat about adding a checkbox to your form. when it is selected you can set the value to true and take steps accordingly. and if its not selected ie. false and you can perform the steps for false value. hope this works. Nitin...

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups