Click here to Skip to main content
15,889,839 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to make the value of my textbox to be either SAVINGS, CURRENTS or OTHERS if the value supplied meets the following conditions
SAVINGS is from number 101 to 165
CURRENT is from number 1 to 17
others is from number 331 to 345

i.e (For example)
C#
if led_code returns 6, txtAcccountType.Text  should be "CURRENT"
if led_code returns 102 , txtAccountType.Text should be "SAVINGS"
if led_code returns 335, txtAccountType.Text should be "OTHERS"


i honestly dont know how to go about it.

i know the code below is very very wrong but i just want to show it all the same.

What I have tried:

C#
protected void btnGetAcctDetails_Click(object sender, EventArgs e)
    {

        
        bankacct = new unityws();
        try
        {
            lblMessage.Text = "";
            Ac = new AcctInfo.AccountInfo();// web service that returns the led_code
            Ac = bankacct.AccountInformation(txtAccountNumber.Text);
            if (Ac.ResponseCode == "00")
            {
                txtClientType.Text = Ac.AcctType.ToString();
                if (txtClientType.Text == "1")
                {
                    txtClientType.Text = "INDV";
                }
                else
                {
                    txtClientType.Text = "CORP";
                }
                txtBranchName.Text = Ac.Branch.ToString();
                txtFullname.Text = Ac.Name.ToString();
                txtAcccountType.Text = Ac.AcctDesc.ToString();

                AcctType = Ac.led_code.ToString(); //it passes the value into AcctType
                if (AcctType == "1" || "2")// 
                {
                    txtAcccountType.Text = "CURRENT";
                }
                else if (AcctType == "101" || "165")
                {
                    txtAcccountType.Text = "SAVINGS";
                }
                else if (AcctType == "331" || "345")
                {
                    txtAcccountType.Text = "OTHERS";
                }
            }
            else
            {
                lblMessage.CssClass = "alert-warning";
                lblMessage.Text = "You have entered an Invalid Account Number";
            }
            
        }
        catch
        {

        }
       

        
    }
Posted
Updated 30-Aug-16 23:16pm
v2

1 solution

First ranges work on numbers not strings so you need to convert text/strings to number with int.Parse():
C#
int num = int.Parse("101"); // string input


Second you need to implement if correctly :
C#
if(num > 101 && num < 165) 
{
   // if evaluates to true
}
 
Share this answer
 
Comments
Emmablakes 31-Aug-16 5:28am    
Thank you....solved my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900