Highlighted
Absent Member.
Absent Member.
830 views

VB Code To Cobol Code

Jump to solution

[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), _
RecvLen)

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

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: VB Code To Cobol Code

Jump to solution
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
                                 Sendbuff(1)
                    by value SendLen
                    by reference iorequest
                                 RecvBuff(1)
                                 RecvLen
              returning g_Retcode
           end-call
         
           set tmpStr to ""
           perform varying indx from 1 by 1
               until indx > 5
               set tmpStr to tmpStr & string::Format("{0:X2}", RecvBuff(indx))
           end-perform
           
           set p_string to tmpStr
           goback.
           
       end program Program1.

View solution in original post

0 Likes
1 Reply
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: VB Code To Cobol Code

Jump to solution
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
                                 Sendbuff(1)
                    by value SendLen
                    by reference iorequest
                                 RecvBuff(1)
                                 RecvLen
              returning g_Retcode
           end-call
         
           set tmpStr to ""
           perform varying indx from 1 by 1
               until indx > 5
               set tmpStr to tmpStr & string::Format("{0:X2}", RecvBuff(indx))
           end-perform
           
           set p_string to tmpStr
           goback.
           
       end program Program1.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.