Results 1 to 5 of 5
  1. #1
    Kel is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    May 2017
    Posts
    3

    How to call a procedure from within a function [decodebase64]

    I was given the code below and with a few simple modifications almost all works well. The process takes a template csv file, converts the file to base64 (this is required by the recipient server) and uploads via a soap call. The response is then returned in an xml file in base64. There is a base64decode function but I don't know how to invoke this code and create a comma delimited file I can work with.

    Public Function CSVRate()
    Dim sUrl As String
    Dim sEnv As String
    Dim xmlhtp As New MSXML2.xmlhttp
    Dim xmlElement As MSXML2.IXMLDOMElement
    Dim XDoc As MSXML2.DOMDocument
    Dim xmlDoc As New DOMDocument
    Dim myFile As String
    Dim strData As String
    Dim ResponseText As String

    'read file as binary. Need to retain the linefeed carriage return characters
    Text = bin2var("C:\Users\K\Desktop\LTLRSRequest.csv")
    'Call encode procedure
    strData = encodeBase64(StrConv(Text, vbFromUnicode))

    Debug.Print strData

    sUrl = "https://applications.smc3.com/AdminManager/services/RateWareXL"

    sEnv = "<?xml version='1.0' encoding='utf-8'?>"
    sEnv = sEnv & "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:web='http://webservices.smc.com'>"
    sEnv = sEnv & " <soapenv:Header>"
    sEnv = sEnv & " <web:AuthenticationToken>"
    sEnv = sEnv & " <web:licenseKey>redacted</web:licenseKey>"
    sEnv = sEnv & " <webassword>redacted</webassword>"
    sEnv = sEnv & " <web:username>redacted</web:username>"
    sEnv = sEnv & " </web:AuthenticationToken>"
    sEnv = sEnv & " </soapenv:Header>"
    sEnv = sEnv & " <soapenv:Body>"
    sEnv = sEnv & " <web:LTLRateShipmentMultipleOpt>"
    sEnv = sEnv & " <web:LTLRateShipmentMultipleOptDelimitedRequest> " & strData & "</web:LTLRateShipmentMultipleOptDelimitedRequest>"
    sEnv = sEnv & " </web:LTLRateShipmentMultipleOpt>"
    sEnv = sEnv & " </soapenv:Body>"
    sEnv = sEnv & "</soapenv:Envelope>"


    With xmlhtp
    .Open "post", sUrl, False

    .setRequestHeader "Host", "http://demo.smc3.com/AdminManager/services/RateWareXL"
    .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    .setRequestHeader "soapAction", "http://webservices.smc.com/RateWareXLPortType/LTLRateShipmentMultipleOptRequest"


    .send sEnv


    xmlDoc.LoadXML .ResponseText


    'Save response to xml file for importing or whatever
    xmlDoc.Save "C:\Users\K\Desktop\LTLRSResponse.xml"




    End With
    End Function

    Function bin2var(filename As String) As String
    Dim f As Integer
    f = FreeFile()
    Open filename For Binary Access Read Lock Write As #f
    bin2var = Space(FileLen(filename))
    Get #f, , bin2var
    Close #f
    End Function

    Public Function encodeBase64(ByRef arrData() As Byte) As String

    Dim objXML As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMElement

    ' help from MSXML
    Set objXML = New MSXML2.DOMDocument

    ' byte array to base64
    Set objNode = objXML.createElement("b64")

    objNode.DataType = "bin.base64"
    objNode.nodeTypedValue = arrData
    Debug.Print objNode.nodeValue
    Debug.Print objNode.BaseName
    Debug.Print objNode.DataType
    Debug.Print objNode.Text
    Debug.Print objNode.nodeTypedValue
    Debug.Print objNode.nodeName
    Debug.Print objNode.nodeTypeString
    Debug.Print objNode.nodeValue



    encodeBase64 = objNode.Text
    'optional to replace line breaks
    encodeBase64 = Replace(objNode.Text, vbLf, "")

    Set objNode = Nothing
    Set objXML = Nothing

    End Function

    Public Function decodeBase64(ByVal strData As String) As Byte()
    Dim objXML As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMElement

    Set objXML = New MSXML2.DOMDocument
    Set objNode = objXML.createElement("b64")
    objNode.DataType = "bin.base64"
    objNode.Text = arrData
    decodeBase64 = objNode.Text

    Set objNode = Nothing
    Set objXML = Nothing
    End Function

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    A Function is normally used when you want to return a single result. A Sub does something but does not return a result. A function can be called and the code executed without having to return a result, however, the two procedures are called differently. I think your CSVRate Function should be a Sub instead. Then can call it from a button Click event.

    You should post code between CODE tags for easier readability.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Kel is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    May 2017
    Posts
    3
    Thanks for the input, unfortunately, I don't understand VBA well enough to interpret your suggestion to my advantage.

    My possibly overly simplified way of looking at this code is to execute the decodeBase64 process similar to the execution of the EncodeBase64 process.

    What I've got so far:
    I've built a macro to create the templated csv file required by the CSVRate process.
    CSVRate is invoked and the csv file is converted to base64 and uploaded to the website to request freight rates and the like.
    The file is returned with requested rates and saved as an xml file on my desktop
    what I'd like, is to somehow invoke decodebase64 prior to the creation of the desktop file and have the converted comma delimited file (or any format I can easily import into Access) created on my desktop.
    Ideally, I'd love the converted response to go right into an access table but all this is beyond a complete VBA novice such as myself.
    I could really use some help modifying the three or so "functions" to produce the end result I'm looking for. I'm at zero hour with this process having tinkered with it for a week and would gladly pay for help at this point

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Copy/pasted your code into VBA module. Had to add reference library 'Microsoft XML, v6.0'. Then had to modify some lines to append '60':

    Code:
     Dim xmlhtp As New MSXML2.XMLHTTP60
     Dim XDoc As MSXML2.DOMDocument60
     Dim xmlDoc As New DOMDocument60
    It all compiles except for Function decodeBase64 on line:
    objNode.Text = arrData

    The decodeBase64 function is declared with strData as argument, should that be arrData()?

    arrData is not declared anywhere nor is it populated anywhere.

    arrData() is passed to encodeBase64 function ByRef and is referenced once in each of the __codeBase64 functions - so where is the arrData() populated?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Kel is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    May 2017
    Posts
    3
    This may help to explain the current state of the module.

    I received modified and tested a module containing CSVRate, bin2var and encodeBase64.

    DecodeBase64 is code I found on the web and have been trying to integrate into the module since then.

    Best I can answer your question "where is the arrData() populated" is, as its written into the encodeBase64 function, I'm assuming it represents the template csv file after being formatted by bin2var???

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Invalid procedure call
    By RonL in forum Queries
    Replies: 0
    Last Post: 05-16-2016, 02:19 PM
  2. Invalid Procedure Call or Argument
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-29-2012, 01:44 PM
  3. Invalid Procedure Call
    By neo651 in forum Queries
    Replies: 21
    Last Post: 09-11-2011, 12:58 PM
  4. invalid procedure call
    By johnmerlino in forum Access
    Replies: 5
    Last Post: 12-13-2010, 10:12 AM
  5. how to call a sub procedure?
    By dollygg in forum Access
    Replies: 1
    Last Post: 08-18-2009, 05:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums