Filling PDF with AutoIT scripts - pdf

I am trying to fill a PDF fillable form using AUtoIT by using scripts. To make my agents works easy going. I ma trying to fill the pdf fields. Initially I am testing on single field Fname_c[0] ,but its not filling with value
Below is the code what i tried
$FilePath = "Form.pdf"
If $FilePath =-1 Then
MsgBox(0, "Error", "No file.")
Exit
EndIf
$fieldname = "Fname_C[0]"
$fileOut = "Form2.pdf"
$App = ObjCreate("AcroExch.App")
$AVDoc = ObjCreate("AcroExch.AVDoc")
If $AVDoc.Open($FilePath, "") Then
$PDDoc = $AVDoc.GetPDDoc
$AForm = ObjCreate("AFormAut.App")
$EX = "" _
& ' var f = this.getField("' & $fieldname & '")' & #LF _
& ' f.value = "Sunil"'
$AForm.Fields.ExecuteThisJavaScript($EX)
$PDDoc.save(1, $fileOut)
$App.closeAlldocs()
$App.exit()
Else
MsgBox(0, "", "Coudn't open report")
EndIf
;; release objects
$AForm = 0
$AVDoc = 0
$PDDoc = 0
$App = 0
where i am doing wrong?

Related

vb.net position cursor one space greater than text box length

I have a TextBox and it contains this text "File Was Created"
I would like to place the cursor one space over from the end of this text in the TextBox
I am trying to NOT say Simple Enough Task BUT I have wasted 2 hours with no solution
YES I know if I change the text to this "File Was Created " it will work NOT a solution
Here is the code mess I have tried
Dim L As Integer
L = tbMessage.Text.Length
L += 1
'tbMessage.Text = CStr(L)
'tbHaveTwo.Text = frmOne.vR
'Me.ActiveControl = tbMessage
'tbMessage.SelectionStart = tbMessage.Text.Length
tbMessage.SelectionStart = L
tbMessage.Select()<br/>
Here is Two updated ways to solve this issue Jimi way less code
tbMessage.Text = "File Was Created"
'This Code involves more code
'Dim str As String
'str = Mid(tbMessage.Text, tbMessage.Text.Length)
'If str <> " " Then
' tbMessage.Text = tbMessage.Text & " "
'End If
'Answer from Jimi Works Great
tbMessage.AppendText(ChrW(32))
tbMessage.SelectionStart = tbMessage.Text.Length
tbMessage.Select()
So you don't end up with a ton of spaces on the end of your message?
tbMessage.AppendText(If(tbMessage.Text.EndsWith(" "), "", " "))
tbMessage.SelectionStart = tbMessage.TextLength
tbMessage.Focus()

Wrong output result from VBA code in Access tool

I am having some issue with a value that is being determined from some VBA code in my Access tool. I am quite a beginner with VBA and this code was developed alongside a very experienced VBA programmer (who has gone away hence is unable to assist me).
This is the code in question:
Private Sub ValidatePrinting()
Dim rst As DAO.Recordset, PrintMethodVal As Boolean, PracIdVal As Long, datePrintedcol As String, PrintedCount As Integer, ImportedCount As Integer
Dim fromtxt As String, wheretxt As String, conditionalImportedCount As Integer, PrintConditions As Boolean
PrintMethodVal = Me.filter_PrintMethod.Value
PracIdVal = Me.filter_PracticeID.Value
datePrintedcol = Me.filter_LetterRound.Value
datePrintedcol = IIf(datePrintedcol = "1st Round", "datePrinted_1st", IIf(datePrintedcol = "2nd Round", "datePrinted_2nd", ""))
PrintedCount = Me.filter_LetterCount.Value
PrintConditions = Me.filter_PrintConditions.Value
If (datePrintedcol = "") Then
Call DisplayMessage("All letters already sent")
Else
fromtxt = " tbl_main_ListLog as T INNER JOIN tbl_dbextract_GPPractice as GPP ON T.GPPracticeID = GPP.Id"
wheretxt = PrintSQLCriteria(PracIdVal, datePrintedcol)
Set rst = CurrentDb.OpenRecordset(PrintValidationSQL(PrintMethodVal, fromtxt, wheretxt))
ImportedCount = rst.Fields(0).Value
conditionalImportedCount = rst.Fields(1).Value
If ImportedCount = conditionalImportedCount Then
If ImportedCount = PrintedCount Then
If PrintMethodVal = PrintConditions Then
tb_Result = "All OK"
CurrentDb.Execute (" update " & fromtxt & " set " & datePrintedcol & " = date() " & wheretxt)
Else
tb_Result = "Wrong print method selected"
End If
Else
tb_Result = "Counts don't match"
End If
Else
tb_Result = "Mismatched print conditions"
End If
End If
End Sub
So the issue is, when the PrintMethodVal does not equal PrintConditions it outputs "Mismatched Print conditions" as opposed to the "Wrong print method selected" which is what it should. It also outputs "Mismatched Print conditions" when the ImportedCount also does not equal the PrintedCount (as well as the first situation), which is weird as the If should end there and output "Counts don't match".
This code was functioning correctly when originally developed, but I had to include the check for PrintMethodVal = PrintConditions.
What am I missing here?

CMS automation in VBA stalls after 63 iterations

I am writing an automation script as I have a need to run a report on 16 separate split skills each day for a period of 6 months. The script works, with one problem. It will run 63 iterations (i.e. 3 days at 16 = 48 + 15 = 63). After the 15th loop (63rd overall iteration) it will give an error: "microsoft excel is waiting for another application to complete an OLE action" It would appear to me, though I could very easily be wrong, that either I am overloading a variable or possibly not fully closing something on the CMS side. The fact that it is the 63rd iteration (64-1) seems awfully suspicious, but I am not sure what I could be overloading as far as variables going. I don't have any 8-bit variables (unless I am missing something). Also, I should point out that after running the macro, I am uanble to log back into the CMS app manually without restarting, so my hunch is that I am not fully closing something and that maybe there is a limit on the number of instances allowed in CMS. I included the script below, except that the names of the skills, server address, username and password have been removed for security reasons. Any help would be greatly appreciated.
Public Sub Single_CMS_Report_Extract()
On Error Resume Next
' Add the files specified below to the References section:
' Tools -> References -> Browse to the CMS directory,
' e.g.: "C:\Program Files\Avaya\CMS Supervisor R14"
Dim cmsApplication As ACSUP.cvsApplication 'acsApp.exe
Dim cmsServer As ACSUPSRV.cvsServer 'acsSRV.exe
Dim cmsConnection As ACSCN.cvsConnection 'cvsconn.dll
Dim cmsCatalog As ACSCTLG.cvsCatalog 'cvsctlg.dll
Dim cmsReport As Object 'ACSREP.cvsReport 'acsRep.exe
Dim myLog As String, myPass As String, myServer As String
Dim reportPath As String, reportName As String, reportPrompt(1 To 2, 1 To 3) As String
Dim exportPath As String, exportName As String
Dim StartRunTime, EndRunTime As Date
Dim DayToRun, EndDate As Date
Dim Skill(1 To 16) As String
MsgBox ("Please ensure CMS open and logged in prior to continuing")
StartRunTime = Now
'Start Date
DayToRun = "12/16/2015"
'End Date
EndDate = "12/21/2015"
Skill(1) = "XXXXXXXX"
Skill(2) = "XXXXXXXX"
Skill(3) = "XXXXXXXX"
Skill(4) = "XXXXXXXX"
Skill(5) = "XXXXXXXX"
Skill(6) = "XXXXXXXX"
Skill(7) = "XXXXXXXX"
Skill(8) = "XXXXXXXX"
Skill(9) = "XXXXXXXX"
Skill(10) = "XXXXXXXX"
Skill(11) = "XXXXXXXX"
Skill(12) = "XXXXXXXX"
Skill(13) = "XXXXXXXX"
Skill(14) = "XXXXXXXX"
Skill(15) = "XXXXXXXX"
Skill(16) = "XXXXXXXX"
While DayToRun < (EndDate + 1)
For i = 1 To 16
' Assigns Variables
myLog = "myuser"
myPass = "mypass"
myServer = "xx.xx.xx.xx"
'reportPath is the tab and "Category" that the report is found in Avaya
reportPath = "Historical\Split/Skill\"
reportName = "Summary Interval"
'list of input names requested.....
reportPrompt(1, 1) = "Split/Skill"
reportPrompt(1, 2) = "Date"
reportPrompt(1, 3) = "Times"
'list of responses being used for input
reportPrompt(2, 1) = Skill(i)
reportPrompt(2, 2) = DayToRun
reportPrompt(2, 3) = "00:00-23:30"
'path and name of exported report file
exportPath = "H:\Avaya data\"
If i <> 5 Then
exportName = Month(DayToRun) & "-" & Day(DayToRun) & "-" & Skill(i) & ".csv"
Else
exportName = Month(DayToRun) & "-" & Day(DayToRun) & "- DL-Toll Free" & ".csv"
End If
' Open the CMS Application, launches acsApp.exe
' If a CMS Supervisor console is already open,
' the existing acsApp.exe is used.
Set cmsApplication = CreateObject("ACSUP.cvsApplication")
Set cmsServer = CreateObject("ACSUPSRV.cvsServer")
Set cmsConnection = CreateObject("ACSCN.cvsConnection")
cmsConnection.bAutoRetry = True
' Connetsc to the server, launches acsSRV.exe & ACSTrans.exe (2x)
If cmsApplication.CreateServer(myLog, myPass, "", myServer, False, "ENU", cmsServer, cmsConnection) Then
If cmsConnection.login(myLog, myPass, myServer, "ENU", "", False) Then
End If
End If
' Gets collection of Reports available on cmsServer
Set cmsCatalog = cmsServer.Reports
If cmsServer.Connected = False Then cmsServer.Reports.ACD = 1
' Sets parameters for report, launches ACSRep.exe (2x)
cmsCatalog.CreateReport cmsCatalog.Reports.Item(reportPath & reportName), cmsReport
If cmsReport.SetProperty(reportPrompt(1, 1), reportPrompt(2, 1)) And cmsReport.SetProperty(reportPrompt(1, 2), reportPrompt(2, 2)) And cmsReport.SetProperty(reportPrompt(1, 3), reportPrompt(2, 3)) Then
End If
' Runs report and extracts results --- the 44 is the field delimiter
cmsReport.ExportData exportPath & exportName, 44, 0, False, False, True
' Kills active report & server
If Not cmsServer.Interactive Then
cmsServer.ActiveTasks.Remove cmsReport.TaskID
cmsApplication.Servers.Remove cmsServer.ServerKey
End If
' Logs out
cmsReport.Quit
cmsConnection.Logout
cmsConnection.Disconnect
cmsServer.Connected = False
' Releases objects
Set cmsReport = Nothing
Set cmsCatalog = Nothing
Set cmsConnection = Nothing
Set cmsServer = Nothing
Set cmsApplication = Nothing
Next
i = Nothing
DayToRun = DateAdd("d", 1, DayToRun)
Wend
EndRunTime = Now
MsgBox ("Run-time = " & Minute(EndRunTime - StartRunTime) & ":" & Second(EndRunTime - StartRunTime))
End Sub

Excel VBA code to attach files in QC Test Cases

I have a tool that capture screenshots of the application that we test at our workplace. Now once I complete my testing of a particular test case or scenarios, we attach the screenshot that we have taken to HP Quality Center manually.
I want to automate this and make my tool to upload the word document to a test in QC Test Lab. Is this possible? If Yes, How can we do this in Excel VBA?
Operations that we need to perform would be as below:
Connect to QC project with login credentials, domain & project details
Pick a file(s) from a local folder
Upload a file(s) to QC Test Lab, specific test case
I used the below code, but getting error in that code. I marked it in the code below, please check below :
Dim intTestID, FldPath, TestSetName, i
Dim TestSetFact, tsTreeMgr, tSetFolder, TestSetsList, theTestSet
Dim TestSetIdentifier, TSTestFact, TestSetTestsList, testInstanceF, aFilter
Dim lst, tstInstance
intTestID = "8968"
FldPath = TextBox3.Text '"Root\ProjFold\Release1\BRD"
TestSetName = ComboBox3.Text '"BRD" '
Set Connection = CreateObject("TDApiOle80.TDConnection")
Connection.InitConnectionEx Sheet2.Range("B1").Value2
Connection.Login TextBox1.Text, TextBox2.Text
Connection.Connect ComboBox1.Text, ComboBox2.Text
Set TestSetFact = Connection.TestSetFactory
Set tsTreeMgr = Connection.TestSetTreeManager
Set tSetFolder = tsTreeMgr.NodeByPath(FldPath)
Set TestSetsList = tSetFolder.FindTestSets(TestSetName)
Set theTestSet = TestSetsList.Item(1)
TestSetIdentifier = theTestSet.ID
i = 0
Set TSTestFact = theTestSet.TSTestFactory
Set TestSetTestsList = TSTestFact.NewList("")
Set testInstanceF = Connection.TSTestFactory
Set aFilter = testInstanceF.Filter
aFilter.Filter("TC_TEST_ID") = intTestID
Set lst = testInstanceF.NewList(aFilter.Text)
Set tstInstance = lst.Item(1) <---------------- getting error here
MsgBox (tstInstance.Field("TS_Name"))
'tstInstance.Status = "Failed"
'tstInstance.Field("TC_STATUS") = Item1.Status '"Passed"
'tstInstance.Post
Dim RunF, runName, NewRun, runStepF, runlst, Item1, runStep2
MsgBox (tstInstance.Field("TS_Subject"))
Set RunF = tstInstance.RunFactory
runName = "Run_" & Month(Date) & "-" & Day(Date) & "_" & Hour(Now) & "-" & Minute(Now) & "-" & Second(Now)
Set NewRun = RunF.AddItem(Null)
NewRun.Status = "Passed"
NewRun.Name = runName
NewRun.Post
NewRun.CopyDesignSteps
NewRun.Post
Set runStepF = NewRun.StepFactory
Set runlst = runStepF.NewList("")
For Each Item1 In runlst
Set runStep2 = Item1
runStep2.Status = "Passed" '
runStep2.Field("ST_ACTUAL") = "As Expected"
runStep2.Post
Next
'tstInstance.Refresh
tstInstance.Status = "Failed"
tstInstance.Post
Connection.DisconnectProject
Connection.ReleaseConnection
'Set QC = Nothing
Set Connection = Nothing
The error is occurring because the array of objects is not returning. You need to check if the Filter gives you a list of results before assuming that lst.Item(1) exists.
For instance:
If lst.Count > 0 Then Set tstInstance = lst.Item(1)

How to increment and print a serialized bar code in vb.net

I wrote a bar code program sometime ago with vb.net that when the end user clicks the print button, the program will open the text file that contains the ZPL bar code, increment the serial number by 1, write the new serial number back to the text file, and then print out the predetermined amount of bar codes to a zebra printer.
Now I am trying to rewrite the code so that it will print the number of bar codes the end user wants from the number they type into the PrintDialog. In my updated code, I tried putting in a DO UNTIL ......LOOP. It will print out the number of bar codes the user puts into the PrintDialog box, but it doesn't serialize. By that I mean if the user enters 5 into the PrintDialog, the program will print serial # 01 five times instead of printing 02, 03, 04, 05, 06.
Can anyone give me some pointers on how to have the program read, write, and print the desired x amount of times based on the number a user inputs into the PrintDialog?
Here is my original code:
Dim sL() As String = IO.File.ReadAllLines("C:\Labels\loop test.txt")
Dim CurrentBar(2) As String
For i = 0 To 2
CurrentBar(i) = sL(sL.Length - 3 + i)
Next
If CurrentBar(1).Length >= 28 Then
CurrentBar(1) = CurrentBar(1).Substring(0, 18) & Format(CInt(CurrentBar(1).Substring(18, 10) + 1), "0000000000") & CurrentBar(1).Substring(28)
Else
MessageBox.Show("String is not long enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'Write the updated vaules back to the Text File
IO.File.WriteAllText("C:\Labels\loop test.txt",
CurrentBar(0) & vbNewLine &
CurrentBar(1) & vbNewLine &
CurrentBar(2))
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.FileName = "C:\Labels\loop test.txt"
Process.Start(psi)
And here is my updated code:
Dim PrintDialog1 As New PrintDialog()
Dim psi As New ProcessStartInfo
Dim sL() As String = IO.File.ReadAllLines("C:\Labels\loop test.txt")
Dim CurrentBar(2) As String
Do Until PrintDialog1.PrinterSettings.Copies - 1
For i = 0 To 2
CurrentBar(i) = sL(sL.Length - 3 + i)
Next
If CurrentBar(1).Length >= 28 Then
CurrentBar(1) = CurrentBar(1).Substring(0, 18) & Format(CInt(CurrentBar(1).Substring(18, 10) + 1), "0000000000") & CurrentBar(1).Substring(28)
Else
MessageBox.Show("String is not long enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'Write the updated vaules back to the Text File
IO.File.WriteAllText("C:\Labels\loop test.txt",
CurrentBar(0) & vbNewLine &
CurrentBar(1) & vbNewLine &
CurrentBar(2))
'Print the labels
'Get the number of copies to print
If (PrintDialog1.ShowDialog() = DialogResult.OK) Then
'print desired number of copies to target printer
For I = 0 To PrintDialog1.PrinterSettings.Copies - 1
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "C:\Labels\loop test.txt"
Process.Start(psi)
Next
End If
Loop
And here is my text file:
^XA
^LH20,85^BY3^AE^SN0000000001R,,Y^B3N,,60,,Y^FS
^XZ
I think your problem in your new code is that you are reading in the text file before you do the loop. At the end of the loop, you write out the new values, but never read them back in (or reuse them). Therefore, the input is always going to be what it was before the loop iterates. I think by putting
sl() = IO.File.ReadAllLines("C:\Labels\loop test.txt")
right after your Do Until statement should fix this.