Link to home
Start Free TrialLog in
Avatar of 1jaws
1jawsFlag for United States of America

asked on

combine creditcard fields

I have a textbox textcreditcardnum  dropdown expiration month, dropdown expiration year  and textbox creditID
I want to combine those values in one label  by showing last four digits of the txtcreditcardnum and the rest of them..how can I do that?
Avatar of RobertNZana
RobertNZana
Flag of United States of America image

:      I have a textbox textcreditcardnum  dropdown expiration month, dropdown expiration year  and textbox creditID
I want to combine those values in one label  by showing last four digits of the txtcreditcardnum and the rest of them..how can I do that?

Something like this...
mylabel.text = Microsoft.VisualBasic.Right(textcreditcardnum.text, 4) & expirationmonth.selecteditem.text & " " & expirationyear & " " & creditID.text
or...

mylabel.text = textcreditcardnum.text.Substring(textcreditcardnum.text.Length - 4) & expirationmonth.selecteditem.text & " " & expirationyear & " " & creditID.text
finally...

mylabel.text = textcreditcardnum.text.Substring(textcreditcardnum.text.Length - 4) & expirationmonth.selecteditem.text & " " & expirationyear.selecteditem.text & " " & creditID.text
Avatar of 1jaws

ASKER

yes, I need this in C# and i need xxx fields untill last four in creditcard number
Try this....

You will have to adjust the control names...

mylabel.text == textcreditcardnum.text.Substring(textcreditcardnum.text.Length - 4) + expirationmonth.selecteditem.text + " " + expirationyear.selecteditem.text + " " + creditID.text

Open in new window

with a semicolon at the end :)
You may wish to use this which is in C#
string ccnum = textcreditcardnum.Text.Substring(textcreditcardnum.Text-4);
txtResult.Text = ccnum.PadLeft(textcreditcardnum.Length, 'X') + " " + ddExpirationMonth.SelectedItem.Text + " " + ddExpirationYear.SelectedItem.Year + " " txtCreditID.Text;
// where ddExpirationMonth is the control ID of the dropdown expiration month and ddExpirationYear is the control ID of the dropdown expiration year and txtCreditID is the ID of the Credit ID textbox

Open in new window

Oops correction please.
string ccnum = textcreditcardnum.Text.Substring(textcreditcardnum.Text.Length-4);
txtResult.Text = ccnum.PadLeft(textcreditcardnum.Text.Length, 'X') + " " + ddExpirationMonth.SelectedItem.Text + " " + ddExpirationYear.SelectedItem.Text + " " txtCreditID.Text;
// where ddExpirationMonth is the control ID of the dropdown expiration month and ddExpirationYear is the control ID of the dropdown expiration year and txtCreditID is the ID of the Credit ID textbox and you may assign this to a text box txtResult or to a variable.

Open in new window

Avatar of 1jaws

ASKER

it is exaclty what I was looking for but giving me error on the highliging txtCardID as a expecting ; it says
=ccnum.PadLeft(txtCreditCard.Text.Length, 'X') + " " + ddExpirationMonth.SelectedItem.Text + " " + ddExpirationYear.SelectedItem.Text + " " txtCardID.Text;
you missed a +.  i have modified your code as below.  Please note that, the control IDs that I have specified are sample and you need to replace them with the actual Control IDs.
ccnum.PadLeft(txtCreditCard.Text.Length, 'X') + " " + ddExpirationMonth.SelectedItem.Text + " " + ddExpirationYear.SelectedItem.Text + " " + txtCardID.Text;

Open in new window

Avatar of 1jaws

ASKER

string ccnum = txtCreditCard.Text.Substring(txtCreditCard.Text-4); on there I get error operator - cannot  apply string and int it says
Avatar of 1jaws

ASKER

i added like this
txtCreditCard.Text.Trim().Substring(txtCreditCard.Text.Length - 4);
is it correct?
yes. sorry for that as i have once again posted the correct code above, just next to the incorrect one.  You can refer to that above.
Avatar of 1jaws

ASKER

perfect it works, only thing there are so close to each other  I need to something maybe "/" to seperate values from each other ?
Yes you may separate each value by replacing the below
      " "
with
     " / "
Avatar of 1jaws

ASKER

I put those didnt look good, can we put like this to the string. is this correct way?

 ccnum.PadLeft(txtCreditCard.Text.Length, 'X') + " Exp Date: " + ddExpirationMonth.SelectedItem.Text + " " + ddExpirationYear.SelectedItem.Text + " Card ID: " + txtCardID.Text;

 
ASKER CERTIFIED SOLUTION
Avatar of CB_Thirumalai
CB_Thirumalai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1jaws

ASKER

thank you soo much!!!!