Replace String with X's

Posted on 2006-05-11
Last Modified: 2010-04-07
This is the problem:
Normally on a receipt given back to a customer you want the first 12 numbers of the CC to read X's and only allow the last 4 digits to appear on the receipt.
I have a textbox named txtlog. It holds information passed back to it from a third party DLL for a credit card payment gateway. The CC is Dim CC as string, although the data is credit card numbers.

The sub reads:
Private Sub mnuPurchase_Click()
    LogStartFunction ("XCharge")
    If (XCTran.PromptCreditCardEntry(ccTransact.hwnd, "Credit Card Purchase Information", False, _
                False, False, Swipe, Track1, Track2, CC, CCTypeName, ExpirationMonth, _
                ExpirationYear, CardHolderName, ZIP, Address, CVV)) Then
      If (XCTran.XCPurchase(ccTransact.hwnd, txtTranFolder.Text, "Purchase", _
                chkShowStatus.Value, chkShowResult.Value, txtClerk.Text, txtRcpt.Text, CC, _
                ExpirationYear + ExpirationMonth, Swipe, txtAmt.Text, ZIP, _
                Address, CVV, ErrorMsg, ApprovalCode, AVSResult, CVVResult)) Then
            LogText ("ApprovalCode = " + ApprovalCode)
            LogText ("CC = " + CCTypeName)
            LogText ("CC = " + CC)
            LogText ("TicketID= " + txtRcpt.Text)
            LogText ("Purchase Amount= " + txtAmt.Text)
           LogText ("XCPurchase Unsuccessfull - " + ErrorMsg)
       End If
       LogText ("PromptCreditCardEntry Unsuccessfull")
   End If
    end sub
When the result of the CC purchase is successfull, the txtlog.text shows the results .

The LogText ("CC= " +CC) shows the full CC number when I print out the  printer command
Printer.Print "CCReceipt"; txtLog.Text since it prints out the txtlog.text which shows the full CC number.
What can I do so that the first 12 digits of the CC number will appear as X's?

Can anyone help me?
Question by:mindserve
    LVL 95

    Expert Comment

    by:Lee W, MVP
    Printer.Print "XXXX-XXXX-XXXX-" & Right(Trim(txtlog.text), 4)
    LVL 18

    Expert Comment

    Dim sTmp as string
    sTmp = txtLog.Text
    Mid(sTmp , 1, 12) = "XXXXXXXXXX"
    Printer.Print sTmp
    LVL 1

    Author Comment

    Maybe this will look clearer:
    This is what prints out. It is all in the txtlog.text after the user completes a CC transaction.

    CC=5499990123456781 ( this is not a valid CC number)
    Purchase Amount=8.00

    The CC is printed from the:
    LogText ("CC = " + CC)
    In the Sub MnuPurchase.
    So this is what prints out. All of it....
    All I need to do is to get the Crecit card numbers to print out only 12 X's and then the last 4 digits.
    Should this be in the print command or go back to the source which is the Sub mnupurchase where it originated?
    The second code produced just X's.

    LVL 18

    Accepted Solution

    Instead of the line:
    LogText ("CC = " + CC)
    Have these lines:
    Dim sTmp as string
    sTmp = CC
    Mid(sTmp , 1, 12) = "XXXXXXXXXX"
    LogText ("CC = " + sTmp )


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now