I am running scripts in UFT and I want to write results to an excel sheet. How would I go about this?
Every test I run will have a test Id and a Pass or Fail status.
I think the easiest way is to write data to the built in DataTable, and then Export the DataTable to an excel file.
For example...
First, add a column (aka a parameter). This also adds the first data record to the column.
'add a new column
DataTable.GetSheet("Global").AddParameter "TestResult", passOrFail
Then, if you need to add more records...
currentRow = DataTable.GetCurrentRow
DataTable.SetCurrentRow = currentRow + 1
DataTable.Value("TestResult","Global") = AnotherPassOrFail
Once done, just export the dataTable to an Excel sheet
DataTable.Export "c:\filename.ext"
There you go.
Create Excel sheet with "Test ID", "Test Result" columns in some location (ex: "C:\TestResults\" folder).
Create a function to write test results into Excel sheet for each test
Call that function at the end of each script
Function WriteResulttoExcel(ID, TestResult, SheetPath)
'Creating the Excel Object
set objExcel = createobject("excel.application")
'Creating the Workbooks object
set objWB = objExcel.workbooks.open (SheetPath)
'Creating the sheet object
set objsheet = objwb.worksheets(1)
' Write test results to excel sheet
rws=objsheet.UsedRange.Rows.count
objsheet.cells(1,rws+1).Value= ID
objsheet.cells(2,rws+1).Value= TestResult
'Saving the workbook after changes
objWb.save
'closing the workbook
objWB.close
'Quit the Excel and destroying the Excel object
objExcel.Quit
set objExcel=nothing
End Function
Related
I have a db that imports files in to temp tables prior to exporting the data to excel and appending the temp data to the main table. Each of the files loaded to the temp tables had a column with the same unique value for each record. I would like to create a query to used to filter on the first and add that value from the query to my file naming convention for the person that has to work the output files.
I've created the query that filters on the first but I am not able to find a way to incorporate that result into the file naming for the output.
Function Export_2nd_Level_Excel()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "2ndLevel", "\pbfsvr01\pbf\PharmNetwork\Audits_Pharmacy\Provider_Audits\Completed Audit files\2nd_Level\" & "[Insert NPI]" & Format(Now, "_ddmmmyy""_2ndLevel_to_PharmAudit") & ".xlsx", True
End Function
I would like to have the "[Insert NPI]" be the actual value from the query that pulls the first of NPI.
after playing around with this for quite some time, I was able to make this work
Function Export_2nd_Level_Excel()
Set db = CurrentDb
Set recd = db.OpenRecordset("2nd_level_NPI")
Dim NPI As String
recd.MoveFirst
NPI = recd![NPI]
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "2ndLevel", "\pbfsvr01\pbf\PharmNetwork\Audits_Pharmacy\Provider_Audits\Completed Audit files\2nd_Level\" & NPI & Format(Now, "_ddmmmyy""_2ndLevel_to_PharmAudit") & ".xlsx", True
End Function
How to load all fields name into combo box. I am using visual basic 6.0.
My code is like this.
Private Sub combo2_option()
Call Dbase
Set rs = New ADODB.Recordset
rs.Open "select ID,DATE,REFNO,SUPPLIER,MODEL,SERIAL,DESCRIPTION,UOM,CATEGORY,PUH,GDP from product_aging_monitoring ", db, 3, 3
Combo2.AddItem rs(2)
End Sub
Option 1. You can limit the records to 1 if you wish to get only the field names.
For i=0 to rs.fields.count-1
Combo2.AddItem rs.fields(i).Name
Next
Option 2 is to use ADOX (DAO) Reference instead of writing a select query. Use ADOX.Catelog object to get metadata of the tables and database
Background: a LOB app we use has the ability to use macros written in VBScript, but no access to WScript, etc., as far as I know.
I have successfully received user input, passed it to a stored procedure on a SQL Server, and returned a recordset to the VBScript macro in the application.
What I want to do now, is write a function or loop or something, that for as long as there is a record left in the recordset, accept additional user input, and check this against the returned recordset.
The recordset returned from SQL Server contains two columns: PART_ID and PART_QTY. For as many number of entries there are, I want to accept additional user input, lets say PART_ID_INPUT and PART_QTY_INPUT, and validate it against the in-memory recordset.
My biggest problem is working with the disconnected recordset.
When in doubt, read the documentation. You can use the Filter and RecordCount properties to determine if the recordset contains matching records:
part_id_input = InputBox("Enter part ID:")
If part_id_input <> "" Then
rs.Filter = "PART_ID = '" & part_id_input & "'"
If rs.RecordCount > 0 Then WScript.Echo "Found matching record."
End If
The filter is cleared by setting it to an empty string:
rs.Filter = ""
The current record can be removed from the recordset using the Delete method:
rs.Delete
Navigate through records via MoveFirst/MoveLast/MoveNext/MovePrevious.
A client have a long lived IBM Notes application where someone along the line changed the type of a field from number to text.
So, now when we're trying to do an FT search like: [myField] = "1234" receive the error message: "Query is not understandable".
If I do: [myField] = 1234 it works but won't return any hits. Even though there's a document where myField = "1234".
The field is of type text in the design.
I've created a new view for testing, only allowing documents from one form.
Deleted the full text index (even on the file system)
updall -X
Fixup -r
Created full text index
In my test view I've got one column that shows if the field content being searched is of type text #IsText(myField) and all rows shows: 1 (so it's field content must be text)
None of the above worked so I created a new database copy locally.
Same problem.
Created an entirely new database (for testing only), form, view and full text index and that works.
Feels like the existing database design somewhere stores the old field type...
Any ideas appreciated.
Thanks!
/J
Datatypes and field names are stored in the UNK table. There is just one entry per field name, so it's critical not to use the same field name more than once in an application with different datatypes.
You need to rebuild the UNK table, as I blogged here http://www.intec.co.uk/full-text-search-musings/
Note, it must be an offline compact, as Duffbert says here http://www.duffbert.com/duffbert/blog.nsf/d6plinks/TDUF-5SMHV4. If anyone is in the database when you do the compact, it will fail and the UNK table will not be rebuilt.
Links are useful, but if you don't want to remove data from documents - for me such steps worked (and there was no need in removing fields from forms in designer):
Run from designer with manager access with such code inside
Sub Initialize
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim i As Integer
Dim nc As NotesNoteCollection
Dim noteid As String
Dim nextnoteid As string
Dim itemArr As Variant
Dim NeedSave As Boolean
Const ITEM_NAME = "itemName1|itemName2"
itemArr = Split( ITEM_NAME, "|" )
'погромист-кун не должен забывать про наличие итемов в формах...
Set db = s.Currentdatabase
Set nc = db.CreateNoteCollection(False)
nc.SelectForms = true
Call nc.BuildCollection
noteid = nc.Getfirstnoteid()
For i = 1 To nc.Count
Set doc = db.Getdocumentbyid( noteid )
noteid = nc.Getnextnoteid( noteid )
NeedSave = false
ForAll IA In itemArr
If doc.Hasitem( IA ) Then
Call doc.Removeitem( IA )
NeedSave = true
End If
End ForAll
If NeedSave Then
Call doc.Save( True, False )
End If
Print CStr( i ) & "\" & CStr( nc.Count )
Next
End Sub
Remove database index
Run from administrator command lo compact database.nsf -c , like mentioned in links above
Create index
I am new to Crystal reports and now I have designed a report via Crystal reports 8.5 in vb6 and wanna to display the report.
I have picked up fields data from a View within my database but as you know Views have several records.
I want to select a special record by a Primary key which is value of a textbox on my form.
Add a parameter to the report and use the parameter in the select expert. Then, call SetParameterValue on the report document before loading.
Why not do a dynamic sql in you vb form picking the values from the textbox
strSql = "select blah from blah where blah ='" + txtBox.text +"'"
Then use then execute the query in a ado.recordset and pass that into a crystal reports application report object, using ttx files to define the data etc ...
Doing this you only have to worry about the dynamic sql from your vb form for parameter selection. The rest can be templated for any report.
Here is some code to start you off
Set AdoRs = New ADODB.Recordset
Set AdoRs = conn_rep.Execute(strSql)
Set CrRep = CrAppl.OpenReport(App.Path + "\crystal\" + CryReportName)
CrRep.Database.Tables(1).SetDataSource AdoRs, 3
CRViewer1.ReportSource = CrRep
CRViewer1.EnablePrintButton = True
CRViewer1.EnableExportButton = True
CRViewer1.EnablePrintButton = True
CRViewer1.viewReport