Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Formatting Credit Number in Textbox Control
#2
Well, it took me some time to figure this one out, as I was having the same problems as you, but apparently the correct "Format String", is:

{0:0000 0000 0000 0000}

Interesting..

Anyway, I have created a class that will do the formatting thing for you! It's pretty easy to understand!
[code2=vbnet]Public Class CardFormatter
Private cardDictionary As Dictionary(Of String, String)

Public Sub New()
'Now, we need to create the dictionary
cardDictionary = New Dictionary(Of String, String)

'Add the contents
cardDictionary.Add("American Express", "{0:0000 000000 00000}")
cardDictionary.Add("Visa", "{0:0000 0000 0000 0000}")
cardDictionary.Add("Mastercard", "{0:0000 0000 0000 0000}")
cardDictionary.Add("Discover", "{0:0000 0000 0000 0000}")
cardDictionary.Add("Isracard", "{0:0000 0000}")
cardDictionary.Add("Diners Club", "{0:0000 000000 0000}")
End Sub

Public Function GetCardNames() As List(Of String)
Return New List(Of String)(cardDictionary.Keys)
End Function

Public Function GetFormattedString(ByVal cardName As String, ByVal cardNumber As String) As String
Dim formatString As String = cardDictionary.Item(cardName)
Return String.Format(formatString, Long.Parse(cardNumber))
End Function
End Class[/code2]

First, put something like this at the top of your form class code:
[code2=vbnet]Private CF As New CardFormatter[/code2]

Now all you need to do is add a combobox and textbox to your form, and when the form loads:
[code2=vbnet]ComboBox1.Items.AddRange(CF.GetCardNames.ToArray)[/code2]

Then, when the user submits the text box:
[code2=vbnet]MsgBox("Credit Card Number: " & CF.GetFormattedString(ComboBox1.Text, TextBox1.Text))[/code2]
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Re: Help Formatting Credit Number in Textbox Control - by brandonio21_phpbb3_import2 - 08-24-2012, 04:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Custom tab control help and making controls Derek275 4 21,172 11-16-2012, 09:51 AM
Last Post: Snake_eyes
  Winsock Control Covert2String 7 25,266 11-27-2011, 08:57 PM
Last Post: brandonio21
  Custom Tab Control xolara 5 20,382 04-24-2011, 07:12 PM
Last Post: xolara

Forum Jump:


Users browsing this thread: 1 Guest(s)