Visual Basic, Visual C Component calls
N Visual Basic calls Visual Basic Components
N Visual C calls Visual Basic components
N Visual Basic calls Visual C components
N Visual C calls Visual C components
N Write Visual Basic Components
n Component Function: Complete the legality check of three types of credit card numbers
N write steps:
1. New project, engineering type selection ActiveX DLL, change the project name by default to ValidateCardServer, and change the default class module Class1 to IvalIDateCard, and finally knock into the following code in this class.
Option expedition
Public Function Fnvalidatecreditcard (byval strccnumber as string) AS Boolean
Dim bvalid as boolean
Strcctype = trim (strcctype)
SELECT CASE UCASE (STRCCTYPE)
Case "VISA"
Strcctype = "v"
Case "Master"
Strcctype = "m"
Case "american"
Strcctype = "a"
End SELECT
IF Fnprefixcheck (StrccNumber, Strcctype) and fnlength, strcctype and fnluhncheck (strccnumber, strcctype) THEN
Bvalid = TRUE
Else
BVALID = FALSE
END IF
Fnvalidatecreditcard = BVALID
END FUNCTION
Private function Fnprefixcheck (StrccNumber As String, Strcctype As String) AS Boolean
Dim Bvalidprefix as Boolean
SELECT CASE UCASE (STRCCTYPE)
Case "V"
IF INSTR (1, StrccNumber, "4") = 1 THEN
Bvalidprefix = true
END IF
Case "M"
IF INSTR (1, StrccNumber, "51") = 1 OR_
INSTR (1, StrccNumber, "52") = 1 or _
INSTR (1, StrccNumber, "53") = 1 or _
INSTR (1, StrccNumber, "54") = 1 OR_
INSTR (1, StrccNumber, "55") = 1 THEN
Bvalidprefix = true
END IF
Case "a"
IF INSTR (1, StrccNumber, "34") = 1 OR_
INSTR (1, StrccNumber, "37") THEN
Bvalidprefix = trueend IF
End SELECT
Fnprefixcheck = BVALIDPREFIX
END FUNCTION
Private function fnlengthchcheck (strccnumber as string) as boolean
Dim Bvalidlength as Boolean
SELECT CASE UCASE (STRCCTYPE)
Case "V" 'a Visa Card Has A 13 Digit OR 16 Digit Number
IF len (strccnumber) = 13 or len (strccnumber) = 16 THEN
BVALIDLENGTH = TRUE
END IF
Case "M" 'a Mastercard Has A 16 Digit Number
IF len (strccnumber) = 16 THEN
BVALIDLENGTH = TRUE
END IF
Case "a" 'American Express Has A 15 Digit Number
IF len (strccnumber) = 15 THEN
BVALIDLENGTH = TRUE
END IF
End SELECT
Fnlengthcheck = BVALIDLENGTH
END FUNCTION
Private function fnluhncheck (strccnumber as string) AS Boolean
Dim bvalidluhn as boolean
DIM STRREV AS STRING
DIM STRCH AS STRING
DIM INTNUMBER AS INTEGER
DIM STRNUMBERFINAL AS STRING
DIM INTSUM AS INTEGER
DIM INTTEMP AS INTEGER
Strrev = strreverse (StrccNumber)
For IntTemp = 1 to Len (Strrev)
StrCh = MID (Strrev, IntTemp, 1)
INTNUMBER = CINT (STRCH)
IF INTTEMP MOD 2 = 0 THEN
INTNUMBER = INTNUMBER * 2
IF INTNUMBER> 9 THEN
INTNUMBER = INTNUMBER - 9
END IF
END IF
Strnumberfinal = StrnumberFinal & INTNumber
Next INTTEMP
For IntTemp = 1 to Len (StrnumberFinal)
INTSUM = INTSUM MID (StrnumberFinal, IntTemp, 1)
Next INTTEMP
IF INTSUM MOD 10 = 0 THEN
Bvalidluhn = True
Else
Bvalidluhn = false
END IF
Fnluhncheck = Bvalidluhn
END FUNCTION
2. Cut the component. Select Make ValidateCardServer. DLL from the File menu ...
N Visual Basic calls Visual Basic Components
N write steps:
1. Creating a new standard engineering, the engineering name is set to vbtestvbcomproj; introduce components, select menu Project-> References ..., click Browse, select C: / VBCOM / VALIDATECardServer.dll; knock into the following form code. Private submmand1_click ()
DIM COMOBJ As New ValidateCardServer.IvalidateCard
If Comobj.fnValidatecreditcard (Text1.Text, Text2.Text) = True Then
Msgbox "Valid Card"
Else
MSGBOX "Invalid Card"
END IF
End Sub
2. Cut the run test procedure.
n Code Test: Enter 4567890123456783 in the credit card number, enter VISA in the credit card type, click OK, pop up the "Valid Card" prompt box; enter 4567890123456789 in the credit card number, enter VISA in the credit card type, click OK button, pop up " Invalid Card prompt box.
Author Blog:
http://blog.9cbs.net/callzjy/