VB Code To Cobol Code

[Migrated content. Thread originally posted on 09 May 2011]

Hi All,

Can any one advise on how to convert the following code:-

*> start define working storage
Private Shared G_hContext As Integer
Private Shared G_retCode As Integer
Private Shared Protocol As Integer
Private Shared SendBuff(262) As Byte
Private Shared RecvBuff(262) As Byte
Private Shared SendLen As Integer
Private Shared RecvLen As Integer
Private Shared hCard As Integer
Private Shared ioRequest As SCARD_IO_REQUEST
*> end define working storage

*> Start define SCARD_IO_REQUEST
Public Structure SCARD_IO_REQUEST
Public dwProtocol As Integer
Public cbPciLength As Integer
End Structure
*> End define SCARD_IO_REQUEST

*> Start VB code section
SendBuff(0) = 128
SendBuff(1) = 20
SendBuff(2) = 0
SendBuff(3) = 0
SendBuff(4) = 6
SendLen = 5
RecvLen = 14

G_retCode = ModWinsCard.SCardTransmit(hCard, _ *> this calls "Start DLL read"
ioRequest, _
SendBuff(0), _
SendLen, _
ioRequest, _
RecvBuff(0), _

tmpStr = ""
For indx = 0 To 5

tmpStr = tmpStr & String.Format("{0:X2}", (RecvBuff(indx)))

Next indx
p_string = tmpStr *>p_string ends up with serial number of card in reader
*> end VB code section

*> Start DLL read
Public Declare Function SCardTransmit Lib "Winscard.dll" (ByVal hCard As Integer, _
ByRef pioSendRequest As SCARD_IO_REQUEST, _
ByRef SendBuff As Byte, _
ByVal SendBuffLen As Integer, _
ByRef pioRecvRequest As SCARD_IO_REQUEST, _
ByRef RecvBuff As Byte, _
ByRef RecvBuffLen As Integer) As Integer
*> end DLL read

  • Verified Answer

    In Visual COBOL this would look something like the following:

          $set ilpinvoke"Winscard.dll"
           program-id. Program1 as "testcard.Program1".

           data division.
           working-storage section.
           01 G_hContext binary-long.
           01 G_retCode  binary-long.
           01 Protocol   binary-long.
           01 SendBuff   pic x occurs 262 times.
           01 RecvBuff   pic x occurs 262 times.
           01 SendLen    binary-long.
           01 RecvLen    binary-long.
           01 hCard      binary-long.
           01 ioRequest.
              05 dwProtocol  binary-long.
              05 cbPciLength binary-long.
           01 tmpStr     string.
           01 indx       binary-long.
           01 p_string   string.
           procedure division.

               move 128 to SendBuff(1)
               move 20 to SendBuff(2)
               move 0 to SendBuff(3)
               move 0 to SendBuff(4)
               move 6 to SendBuff(5)
               move 5 to SendLen
               move 14 to RecvLen
               call "SCardTransmit"
                  using by value hCard
                        by reference iorequest
                        by value SendLen
                        by reference iorequest
                  returning g_Retcode
               set tmpStr to ""
               perform varying indx from 1 by 1
                   until indx > 5
                   set tmpStr to tmpStr & string::Format("{0:X2}", RecvBuff(indx))
               set p_string to tmpStr
           end program Program1.