Invalid procedure call or argument error in macro - vba

I have created .bat file which I like to run in vba Excel, I have a code(code1) to run the .bat file. It works fine when it alone but if run with object code(I given in below code2) it throws error.
sub batfile() '-->code1
Dim a As Integer
ChDir ("C:\Users\tshiv\source")
a = Shell("test.bat", vbNormalFocus)
end sub
sub creatbatfile()
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim TextFile As Object
Dim strtext As String
strtext = "C:\Users\tshiv\source\test.bat"
Set TextFile = FSO.CreateTextFile("C:\Users\tshiv\source\test.bat")
TextFile.Write "netsh wlan show profile | clip"
Dim a As Integer
ChDir ("C:\Users\tshiv\source")
a = Shell("test.bat", vbNormalFocus) --> shows Invalid procedure call or argument error
end sub
kindly verify

We can use measures based on EXCEPT and INTERSECT. First, we need to know what is year in the current row. We create a variable, then virtual tablevariable with SupplierID for this and prev year. Next, we can compare both.
SubInCurrAndPrevYear =
var __currYear = YEAR(SELECTEDVALUE(Sheet1[Date ]))
var __PrevYear = __currYear -1
var __SupPREV = CALCULATETABLE(VALUES(Sheet1[ SupplierID ]), year(Sheet1[Date ]) = __PrevYear)
var __SupCurr = CALCULATETABLE(VALUES(Sheet1[ SupplierID ]), year(Sheet1[Date ]) = __currYear)
return
COUNTROWS(INTERSECT(__SupCurr,__SupPREV))
SubLostThisYear =
var __currYear = YEAR(SELECTEDVALUE(Sheet1[Date ]))
var __PrevYear = __currYear -1
var __SupPREV = CALCULATETABLE(VALUES(Sheet1[ SupplierID ]), year(Sheet1[Date ]) = __PrevYear)
var __SupCurr = CALCULATETABLE(VALUES(Sheet1[ SupplierID ]), year(Sheet1[Date ]) = __currYear)
return
COUNTROWS(EXCEPT(__SupPREV, __SupCurr))
SubNewThisYear =
var __currYear = YEAR(SELECTEDVALUE(Sheet1[Date ]))
var __PrevYear = __currYear -1
var __SupPREV = CALCULATETABLE(VALUES(Sheet1[ SupplierID ]), year(Sheet1[Date ]) = __PrevYear)
var __SupCurr = CALCULATETABLE(VALUES(Sheet1[ SupplierID ]), year(Sheet1[Date ]) = __currYear)
return
COUNTROWS(EXCEPT(__SupCurr,__SupPREV))

Related

Insert into table without LOOP in VB.NET

I have
For Each itemSN As SellingDetailSNCustomer In item.listSN
Dim newItem As New TR_Selling_Customer_Product_SN
newItem.FK_Selling_Detail_Customer_ID = oNew.PK_Selling_Customer_Detail_ID
newItem.SN = itemSN.SNProduct
newItem.CreatedDate = Now.ToString("yyyy-MM-dd")
newItem.CreatedBy = "system"
newItem.LastUpdateDate = Now.ToString("yyyy-MM-dd")
newItem.LastUpdateBy = "system"
newItem.Active = True
objdb.Entry(newItem).State = Entity.EntityState.Added
Dim obUpdateBookedSN As MS_Product_Serial_Number = (From x In objdb.Product_Serial_Number Where x.FK_Product_ID = item.FK_Product_ID And x.Serial_Number = itemSN.SNProduct Select x).FirstOrDefault
If obUpdateBookedSN IsNot Nothing Then
obUpdateBookedSN.Booked_Serial_Number = True
obUpdateBookedSN.LastUpdateDate = Now.ToString("yyyy-MM-dd")
obUpdateBookedSN.LastUpdateBy = "system"
objdb.Entry(obUpdateBookedSN).State = Entity.EntityState.Modified
End If
Next
objdb.SaveChanges()
When I have more than thousand serial number, this looping become very slow processing time.
I want to changes this code without looping.
How do I figure that out?

Populate a structure

I have a structure containing 47 fields.I also have a string that contains "|" delimited value . I want to populate the structure with the values in the string. The only solution that I can think of is below.However this involves hardcoding. Is there a better way to achieve the same via a loop or anything else
Dim lobjStructData As New SUB_PNDGORDR_QRY_RESP
Dim lstrarrStream As String() = pstrStream.Split(CChar("|"))
lobjStructData.ClientId = CType(lstrarrStream(0), Char())
lobjStructData.PortfolioId = CShort(lstrarrStream(1))
lobjStructData.Currency = CType(lstrarrStream(2), Char())
lobjStructData.ProductId = CType(lstrarrStream(3), Char())
lobjStructData.InstrumentClass = CShort(lstrarrStream(4))
lobjStructData.OrderSymbol = CType(lstrarrStream(5), Char())
lobjStructData.Qty = CDbl(lstrarrStream(6))
lobjStructData.QtyRemaining = CDbl(lstrarrStream(7))
lobjStructData.OrderPrice = CDbl(lstrarrStream(8))
lobjStructData.TriggerPrice = CDbl(lstrarrStream(9))
lobjStructData.Remarks = CType(lstrarrStream(10), Char())
lobjStructData.QtyDiscRem = CDbl(lstrarrStream(11))
lobjStructData.OrderDateTime = CInt(lstrarrStream(12))
lobjStructData.IntOrderNo = CDbl(lstrarrStream(13))
lobjStructData.OrderStat = CType(lstrarrStream(14), Char())
lobjStructData.DiscQty = CDbl(lstrarrStream(15))
lobjStructData.SerialNo = CInt(lstrarrStream(16))
lobjStructData.OpenCloseFlg = CInt(lstrarrStream(17))
lobjStructData.InstrumentId = CInt(lstrarrStream(18))
lobjStructData.ContractSeriesId = CInt(lstrarrStream(19))
lobjStructData.InstrumentType = CShort(lstrarrStream(20))
lobjStructData.BuySellInd = CShort(lstrarrStream(21))
lobjStructData.MinFillQty = CDbl(lstrarrStream(22))
lobjStructData.ExchId = CInt(lstrarrStream(23))
lobjStructData.OrderTyp = CShort(lstrarrStream(24))
lobjStructData.ValidityCond = CDbl(lstrarrStream(25))
lobjStructData.ExchTrdNo = CType(lstrarrStream(26), Char())
lobjStructData.IntTranscode = CShort(lstrarrStream(27))
lobjStructData.ValidityAttr = CInt(lstrarrStream(28))
lobjStructData.BosRefId = CInt(lstrarrStream(29))
lobjStructData.OriginatorId = CType(lstrarrStream(30), Char())
lobjStructData.Commision = CDbl(lstrarrStream(31))
lobjStructData.SolicitedFlg = CType(lstrarrStream(32), Char())
lobjStructData.OrderFamily = CType(lstrarrStream(33), Char())
lobjStructData.ReceiptTime = CInt(lstrarrStream(34))
lobjStructData.ExchShortSellFlag = CType(lstrarrStream(35), Char())
lobjStructData.cSourceFlag = CChar(lstrarrStream(36))
lobjStructData.extnno = CInt(lstrarrStream(37))
lobjStructData.sReceiptMode = CType(lstrarrStream(38), Char())
lobjStructData.sErrorMsg = CType(lstrarrStream(39), Char())
lobjStructData.cCoverUncover = CChar(lstrarrStream(40))
lobjStructData.fATOrderNo = CDbl(lstrarrStream(41))
lobjStructData.iQtyCond = CShort(lstrarrStream(42))
lobjStructData.iReserve2 = CChar(lstrarrStream(43))
lobjStructData.fInternalRefId = CDbl(lstrarrStream(44))
Well, you have a few redundancies here:
the data type you convert to (which is probably the same as the data type of the field),
the position in the array (which is the same as the order in which you write the statement),
the name of the result variable,
the name of the stream.
Let's try to get rid of them. We will remove (1) with method overloads, (2) with an auto-incremented position variable, (3) with a shorter variable name and (4) by extracting the conversion code into a method.
The following code is untested, but the idea should be obvious:
Public Function ParseStream(pstrStream As String) As SUB_PNDGORDR_QRY_RESP
Dim p As New Parser(pstrStream)
Dim r As New SUB_PNDGORDR_QRY_RESP()
With r
p.ParseField(.ClientId)
p.ParseField(.PortfolioId)
p.ParseField(.Currency)
...
End With
Return r
End Function
Private Class Parser
Public Sub New(pstrStream As String)
Me.lstrarrStream = pstrStream.Split("|"c)
End Sub
Private pos As Integer = 0
Private lstrarrStream As String()
Public Sub ParseField(ByRef field As Char())
field = CType(lstrarrStream(pos), Char())
pos += 1
End Sub
Public Sub ParseField(ByRef field As Short)
field = CShort(lstrarrStream(pos))
pos += 1
End Sub
... other ParseField overloads...
End Class

TransformPDFFields option not working in CreateEnvelopeFromTemplatesAndForms using SOAP API

I am trying to create envelop using CreateEnvelopeFromTemplatesAndForms to make the pdf form fields editable. I am gettting unspecified_error. I have also tried removing the document from composite template and adding the document in the inline template envelop. In this case it creates and sends the envelop but does not make the fields editable. See my code below
'compositeTemplate
Dim envInfo As New EnvelopeInformation
With envInfo
.AccountId = c.AccountID
.Subject = subject
.EmailBlurb = emailBlurb
End With
Dim template As New CompositeTemplate
'recipients
Dim recipients As New List(Of Recipient)
For iRecip As Integer = 1 To packet.Recipients.Count
Dim recipient As New Recipient
Dim customfields As New List(Of String)
With packet.Recipients(iRecip - 1)
recipient.Email = .Email
recipient.SignerName = .Name
recipient.UserName = .Name
recipient.ID = .ID
recipient.RoutingOrder = .RoutingOrder
recipient.RoutingOrderSpecified = True
recipient.RequireIDLookup = .RequireIDLookup
recipient.RequireIDLookupSpecified = True
recipient.AccessCode = .AccessCode
recipient.AddAccessCodeToEmail = False
recipient.AddAccessCodeToEmailSpecified = True
recipient.DefaultRecipient = .DefaultRecipient
recipient.DefaultRecipientSpecified = .IsDefaultRecipientSpecified
If (Not String.IsNullOrEmpty(.CaptiveInfoClientUserId)) Then
recipient.CaptiveInfo = New RecipientCaptiveInfo()
recipient.CaptiveInfo.ClientUserId = .CaptiveInfoClientUserId
End If
customfields.Add(String.Format("SignerRole={0}", .Role))
End With
'add customfields list to recipient customfields
recipient.CustomFields = customfields.ToArray
recipients.Add(recipient)
Next
Dim inlineTemplate As New InlineTemplate
inlineTemplate.Sequence = 1
inlineTemplate.Envelope = New Envelope
inlineTemplate.Envelope.AccountId = c.AccountID
With inlineTemplate.Envelope
.Notification = New APIService.Notification
Dim exp As New APIService.Expirations
With exp
.ExpireEnabled = _envelopeExpirationEnabled
If _envelopeExpirationEnabled Then
.ExpireAfter = _envelopeExpirationDays
If _envelopeExpirationWarningEnabled Then
.ExpireWarn = _envelopeExpirationWarningDaysLeft
End If
End If
End With
.Notification.Expirations = exp
End With
Dim tabs As New List(Of Tab)
'add documents
Dim documents As New List(Of Document)
Dim matchBoxes As New List(Of MatchBox)
For iDoc As Integer = 1 To packet.Forms.Count
Dim theForm As Objects.Form = packet.Forms(iDoc - 1)
theForm.ID = iDoc
Dim document As New Document
document.Name = theForm.FilePath
document.PDFBytes = theForm.FileBytes
document.ID = theForm.ID
document.TransformPdfFields = True
'add tabs - this will be based on metadata defined in the database for the attached forms
For Each oTab As Objects.Tab In theForm.Tabs
Dim tab As New Tab
If Not String.IsNullOrEmpty(oTab.AnchorText) AndAlso oTab.TabType <> TabTypeCode.Custom Then
Dim aTab As New AnchorTab
aTab.AnchorTabString = oTab.AnchorText
tab.AnchorTabItem = aTab
ElseIf oTab.TabType = TabTypeCode.Custom Then
tab.TabLabel = oTab.AnchorText
End If
With tab
.DocumentID = document.ID
.RecipientID = oTab.Recipient.ID
.Type = oTab.TabType
.PageNumber = oTab.PageNumber
.XPosition = oTab.XPosition
.YPosition = oTab.YPosition
If .Type = TabTypeCode.InitialHere Then
.ScaleValueSpecified = True
.ScaleValue = 0.53
End If
End With
tabs.Add(tab)
Next
documents.Add(document)
Next
inlineTemplate.Envelope.Recipients = recipients.ToArray
inlineTemplate.Envelope.Tabs = tabs.ToArray
template.InlineTemplates = New InlineTemplate() {inlineTemplate}
template.Document = New Document
template.Document.ID = 1
template.Document.Name = "TemplateDoc"
template.Document.PDFBytes = documents(0).PDFBytes
template.Document.TransformPdfFields = True
template.Document.FileExtension = "pdf"
Dim _apiProxy As APIServiceSoap = CreateApiProxy(c)
Dim envStatus As EnvelopeStatus = _apiProxy.CreateEnvelopeFromTemplatesAndForms(envInfo, New CompositeTemplate() {template}, True)
Any assistance would be greatly appreciated.
Thanks,
Pulak
The best way to debug such issues (which are sometimes bugs on the DocuSign server side) is to inspect your raw (XML based) SOAP request that you are sending over the wire. If I were you I would include it here in your question as it's much easier to diagnose when we can see the request as opposed to the code that creates the request.
With that said, are setting the tab's Locked property to false so that it's editable? You'll also need to set CustomTabLockedSpecified property to true for this to take affect.
Basically, in your tab definition code try something like this:
With tab
.DocumentID = document.ID
.RecipientID = oTab.Recipient.ID
.Type = oTab.TabType
...
.CustomTabLockedSpecified = True
.CustomTabLocked = False

Datagridview doesnt show data in rows

I am currently working on project in which i have to display IP Configuration to user in VB.Net Application.
I am using DataGridView to display IP Config to user.
But problem is Datagridview doesnt display anything in its row at all.
Image for proof
Here is the code
Public Sub MT_Validate_Msg(ByRef lbData() As Byte)
Dim lsAddr(3) As String
Dim lsMAC(5) As String
Dim lstConfig As TCP_SER_Config
If lbData.Length >= 256 Then
'Check Header Footer and Response Size
If lbData(0) = Asc("$") And lbData(1) = Asc("#") _
And lbData(254) = Asc("<") And lbData(255) = Asc(">") _
And lbData(2) = UDP_RESPONSE_SIZE And lbData(3) = 0 Then
gnDevice_Search_Count += 1
'MsgBox("Response Received")
lsAddr(0) = lbData(7).ToString
lsAddr(1) = lbData(9).ToString
lsAddr(2) = lbData(11).ToString
lsAddr(3) = lbData(13).ToString
lstConfig.IP = String.Join(".", lsAddr)
lsAddr(0) = lbData(15).ToString
lsAddr(1) = lbData(17).ToString
lsAddr(2) = lbData(19).ToString
lsAddr(3) = lbData(21).ToString
lstConfig.Subnet = String.Join(".", lsAddr)
lsAddr(0) = lbData(23).ToString
lsAddr(1) = lbData(25).ToString
lsAddr(2) = lbData(27).ToString
lsAddr(3) = lbData(29).ToString
lstConfig.Gateway = String.Join(".", lsAddr)
lstConfig.Alive_Time = lbData(31)
lsMAC(0) = Hex(lbData(33)).ToString
lsMAC(1) = Hex(lbData(34)).ToString
lsMAC(2) = Hex(lbData(35)).ToString
lsMAC(3) = Hex(lbData(36)).ToString
lsMAC(4) = Hex(lbData(37)).ToString
lsMAC(5) = Hex(lbData(38)).ToString
lstConfig.MAC = String.Join("-", lsMAC)
MT_FillGrid(lstConfig)
End If
End If
End Sub
Public Sub MT_FillGrid(ByRef lstTCPConfig As TCP_SER_Config)
Dim row As String() = New String() {gnDevice_Search_Count.ToString, lstTCPConfig.IP, lstTCPConfig.Subnet, _
lstTCPConfig.Gateway, lstTCPConfig.Alive_Time.ToString, lstTCPConfig.MAC}
GridDev_List.Rows.Add(row)
row = New String() {"1", "192.168.0.100", "255.255.255.0", "255.255.255.255", "60", "22-0B-3C-2D-00-01"}
GridDev_List.Rows.Add(row)
End Sub
Expecting a result like this, Where i am going wrong in code ?

Calling ABAP function module from Excel VBA Macro

I want to call an ABAP function from an Excel VBA Macro.
Is there any method I can follow to achieve this.
Please help me regarding this.
Dim sapConn As Object 'Declare connection object
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
sapConn.Connection.user = "user" 'Specify user
sapConn.Connection.Password = "" 'Then password
sapConn.Connection.client = "001" 'Client
sapConn.Connection.ApplicationServer = "server" 'Target server address
sapConn.Connection.Language = "PT" 'Language code
'Finally, try to logon to the specified system and check if the connection established
If sapConn.Connection.Logon(0, True) <> True Then
MsgBox "Cannot Log on to SAP" 'Issue message if cannot logon
Else
MsgBox "Logged on to SAP!"
End If
Dim rfcAcctDocCheck As Object
Dim oAcctHeader As Object
Dim otAcctAR, otAcctGL, otAcctAP, otAcctAMT, otReturn As Object
Set rfcAcctDocCheck = sapConn.Add("BAPI_ACC_DOCUMENT_CHECK")
Set oAcctHeader = rfcAcctDocCheck.Exports("DOCUMENTHEADER")
Set otAcctGL = rfcAcctDocCheck.Tables("ACCOUNTGL")
Set otAcctAR = rfcAcctDocCheck.Tables("ACCOUNTRECEIVABLE")
Set otAcctAP = rfcAcctDocCheck.Tables("ACCOUNTPAYABLE")
Set otAcctAMT = rfcAcctDocCheck.Tables("CURRENCYAMOUNT")
Set otReturn = rfcAcctDocCheck.Tables("RETURN")
Dim qtLegs As Integer
Dim dt, comp, tpDoc, docRef, tpAcct, acct, customer, vendor, _
curr, val, spLedger, ccenter, order As String
Dim curLine As Integer
For lin = 1 To UBound(reg)
id = Format(tbPost.Cells(reg(lin).lin_ini, K_COL_ID), "0000000000")
dt = getDate(tbPost.Cells(reg(lin).lin_ini, K_COL_DT))
comp = getCompanyCode(tbPost.Cells(reg(lin).lin_ini, K_COL_EMPR))
tpDoc = getDocumentType(tbPost.Cells(reg(lin).lin_ini, K_COL_TP_DOC))
docRef = tbPost.Cells(reg(lin).lin_ini, K_COL_DOC_REF)
otAcctGL.freeTable
otAcctAR.freeTable
otAcctAP.freeTable
otAcctAMT.freeTable
oAcctHeader("USERNAME") = sapConn.Connection.user
oAcctHeader("HEADER_TXT") = "Lancado via Excel"
oAcctHeader("COMP_CODE") = comp
oAcctHeader("DOC_DATE") = dt
oAcctHeader("PSTNG_DATE") = dt
oAcctHeader("DOC_TYPE") = tpDoc
oAcctHeader("REF_DOC_NO") = docRef
otAcctAMT.Rows.Add
otAcctAMT(otAcctAMT.Rows.Count, "ITEMNO_ACC") = Format(leg, "0000000000")
otAcctAMT(otAcctAMT.Rows.Count, "CURRENCY") = curr
otAcctAMT(otAcctAMT.Rows.Count, "AMT_BASE") = val
Next
If rfcAcctDocCheck.Call = False Then
MsgBox rfcAcctDocCheck.Exception
End If