Hola:
¿En qué archivo está su código fuente? Gracias.
#include "FiveWin.ch"
Static oWnd
//----------------------------------------------------------------------------//
Function Main()
DEFINE WINDOW oWnd TITLE "Validacion de tarjetas de credito" ;
MENU BuildMenu() MDI
ACTIVATE WINDOW oWnd
Return NIL
//----------------------------------------------------------------------------//
function BuildMenu()
local oMenu
MENU oMenu
MENUITEM "Test" ACTION TestCard()
MENUITEM "Exit" ACTION oWnd:End()
ENDMENU
Return oMenu
//----------------------------------------------------------------------------//
Static Function TestCard()
Local cNumber := Space(20)
Local cCard
If MsgGet( "Validacion de Tarjeta de Credito",;
"Número de tarjeta:",;
@cNumber )
If ValidCard( cNumber, @cCard )
MsgInfo( "Tarjeta válida ingresada es " + cCard )
Else
MsgInfo( "Número de tarjeta erroneo!" )
EndIf
EndIf
Return NIL
//----------------------------------------------------------------------------//
Function ValidCard( cNumber, cCard )
Local nID
Local nLen
Local nValidLen
cNumber := AllTrim( StrTran( cNumber, "-", "" ) )
nLen := Len( cNumber )
nID := Val( Left( cNumber, 4 ) )
If Empty( nID )
Return .F.
EndIf
Do Case
Case ( nID >= 3000 .AND. nID <= 3059 ) .OR.;
( nID >= 3600 .AND. nID <= 3699 ) .OR.;
( nID >= 3800 .AND. nID <= 3889 )
cCard := "Diners Club"
nValidLen := 14
Case ( nID >= 3400 .AND. nID <= 3499 ) .OR.;
( nID >= 3700 .AND. nID <= 3799 )
cCard := "American Express"
nValidLen := 15
Case nID >= 4000 .AND. nID <= 4999
cCard := "Visa"
Do Case
Case nLen > 14
nValidLen := 16
Case nLen < 14
nValidLen := 13
OtherWise
Return .F.
EndCase
Case nID >= 5100 .AND. nID <= 5599
cCard := "MasterCard"
nValidLen := 16
OtherWise
Return .F.
EndCase
If nLen <> nValidLen
Return .F.
EndIf
If Mod10( cNumber )
Return .T.
EndIf
Return .F.
//----------------------------------------------------------------------------//
Static Function Mod10( cNumber )
Local nLen := Len( cNumber )
Local Location
Local Digit
Local Checksum := 0
For Location := 2 - Mod( nLen, 2 ) To nLen Step 2
Checksum := Val( SubStr( cNumber, Location, 1 ) ) + Checksum
Next
For Location := ( Mod( nLen, 2 ) + 1 ) To nLen Step 2
Digit := Val( SubStr( cNumber, Location, 1 ) ) * 2
If Digit < 10
Checksum := Digit + Checksum
Else
Checksum := Digit - 9 + Checksum
EndIf
Next
If Mod( Checksum, 10 ) = 0
Return .T.
EndIf
Return .F.
//----------------------------------------------------------------------------//
#include "FiveWin.ch"
REQUEST HB_LANG_PT
REQUEST HB_CODEPAGE_PT850
STATIC oWnd
FUNCTION Main()
HB_LANGSELECT( 'PT' ) // Default language is now Portuguese
HB_SETCODEPAGE( "PT850" )
// 1 English, 2 Spanish, 3 French, 4 Portugese, 5 German, 6 Italian
FWSetLanguage( 4 ) // Passar para portugues do Brasil.
DEFINE WINDOW oWnd TITLE "Validacion de tarjetas de credito" ;
MENU BuildMenu() MDI
ACTIVATE WINDOW oWnd CENTERED
RETURN NIL
FUNCTION BuildMenu()
LOCAL oMenu
MENU oMenu
MENUITEM "Teste" ACTION( TestCard() )
MENUITEM "Salida" ACTION( oWnd:End() )
ENDMENU
RETURN oMenu
STATIC FUNCTION TestCard()
LOCAL cNumber := Space( 20 )
LOCAL cCard
IF MsgGet( "Validacion de Tarjeta de Credito", ;
"Número de tarjeta:", ;
@cNumber )
IF ValidCard( cNumber, @cCard )
MsgInfo( "Tarjeta válida ingresada es " + cCard )
ELSE
MsgInfo( "Número de tarjeta erroneo!" )
ENDIF
ENDIF
RETURN NIL
FUNCTION ValidCard( cNumber, cCard )
LOCAL nID
LOCAL nLen
LOCAL nValidLen
cNumber := AllTrim( StrTran( cNumber, "-", "" ) )
nLen := Len( cNumber )
nID := Val( Left( cNumber, 4 ) )
IF Empty( nID )
RETURN .F.
ENDIF
DO CASE
CASE ( nID >= 3000 .AND. nID <= 3059 ) .OR. ;
( nID >= 3600 .AND. nID <= 3699 ) .OR. ;
( nID >= 3800 .AND. nID <= 3889 )
cCard := "Diners Club"
nValidLen := 14
CASE ( nID >= 3400 .AND. nID <= 3499 ) .OR. ;
( nID >= 3700 .AND. nID <= 3799 )
cCard := "American Express"
nValidLen := 15
CASE nID >= 4000 .AND. nID <= 4999
cCard := "Visa"
DO CASE
CASE nLen > 14
nValidLen := 16
CASE nLen < 14
nValidLen := 13
OTHERWISE
RETURN .F.
ENDCASE
CASE nID >= 5100 .AND. nID <= 5599
cCard := "MasterCard"
nValidLen := 16
OTHERWISE
RETURN .F.
ENDCASE
IF nLen <> nValidLen
RETURN .F.
ENDIF
IF Mod10( cNumber )
RETURN .T.
ENDIF
RETURN .F.
STATIC FUNCTION Mod10( cNumber )
LOCAL nLen := Len( cNumber )
LOCAL Location
LOCAL Digit
LOCAL Checksum := 0
FOR Location := 2 - Mod( nLen, 2 ) TO nLen STEP 2
Checksum := Val( SubStr( cNumber, Location, 1 ) ) + Checksum
NEXT
FOR Location := ( Mod( nLen, 2 ) + 1 ) TO nLen STEP 2
Digit := Val( SubStr( cNumber, Location, 1 ) ) * 2
IF Digit < 10
Checksum := Digit + Checksum
ELSE
Checksum := Digit - 9 + Checksum
ENDIF
NEXT
IF Mod( Checksum, 10 ) = 0
RETURN .T.
ENDIF
RETURN .F.
//-> FIN - THE END - FIM
nageswaragunupudi wrote:Source code is not available.
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 15 guests