Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27388

Opening/refreshing/saving/closing excel in VB.net Script

$
0
0
I have a project where I am trying to automate the stamping process of our product nameplates. The nameplates are stamped with a MarkMaster Peen Stamp machine. The peen stamp machine is controlled with MarkMaster software. In the MarkMaster software there is an option to use a script to control the peen stamper. The script is in VB.net. I need the script to ask the operator for a barcode scan and then input that barcode scan into my excel database and then read the information in my excel database which is then used to open the correct layout and input the correct information in the various nameplate fields. The script I have will do all of this except I am having one problem. When I use the scriptexecutedatabase command to input the barcode scan it inputs the scan correctly into excel but it doesn't save the excel so when I use the querydatabase command the query produces the excel that was saved last and not the correct excel. I need to open/save/refresh/close the excel after the execute command and before the query command in the script in order to have the query return the updated information. I can't figure out how to do this. This is the script that I have:

dim dbPath as string
dim layoutPath as string
dim layoutName as string
dim markingDetails as string

dbPath = "\\document\myexcel.xls"
messagebox.show(dbPath)

layoutPath = "\\document\"


oMainWnd.ScriptAppendMessage("Connecting to excel spreadsheet... Ensure it is not open...", Color.Green, false)

' keep going until user cancels script
while (Not oMainWnd.ScriptCancellationPending)
try

'look for the master db file
if oMainWnd.FileExists(dbPath) then

dim scannedCode as string
scannedCode = Microsoft.VisualBasic.Interaction.InputBox("Scan the item", "Mark Master")

if scannedCode.Length > 0 then
dim scriptWnd as LayoutEditor.EPMDIChild
scriptWnd = oMainWnd.ActiveMdiChild

dim data as new System.Collections.Generic.List(of Object)



scriptWnd.ScriptExecuteDatabase("test", "BarCodeInput", "dbConn", "update [InputOutput$] set BarCodeInput='" & scannedCode & "'")



data = scriptWnd.ScriptQueryDatabase("test", "dbConn", _
"select layout, * from [InputOutput$]", _
false, true)

'pass the scanned barcode as a query parameter and return the layout name and marking details



messagebox.show(data.count)
'anything come back?
if data.Count > 0 then
layoutName = data(0)
markingDetails = data(1)

end if

if layoutName.Length > 0 then
dim fullPath as string
fullPath = layoutPath + layoutName + ".mmlay"

'open & mark layout(s)
if oMainWnd.FileExists(fullPath) then
dim quantityReqd as integer
quantityReqd = Microsoft.VisualBasic.Interaction.InputBox("Quantity to mark", "Mark Master")

dim variable as LayoutObjects.EPVariable
dim layout as LayoutObjects.EPLayout
dim ndx as integer

for ndx = 0 to quantityReqd - 1 step 1
oMainWnd.ScriptFileOpen(fullPath)

'important to reassign this as active child is now the layout just loaded by previous call
scriptWnd = oMainWnd.ActiveMdiChild

'set the layout variable with data from the spreadsheet
layout = scriptWnd.Layout

For Each obj As LayoutObjects.EPLayoutObject In layout
Dim tx As LayoutObjects.EPTextObject
If obj IsNot Nothing And obj.UIDTypeAsString = "Text" Then
If obj.UIDName.Equals("Size") = True Then
tx = obj
tx.Text = data(23)
End If
End If
Next obj

For Each obj As LayoutObjects.EPLayoutObject In layout
Dim tx As LayoutObjects.EPTextObject
If obj IsNot Nothing And obj.UIDTypeAsString = "Text" Then
If obj.UIDName.Equals("Model") = True Then
tx = obj
tx.Text = data(3)
End If
End If
Next obj



scriptWnd.ScriptShowMarkingDialogSetCounter(oLayoutWnd, true, ndx)

oMainWnd.ScriptLayoutClose()
next ndx
else
oMainWnd.ScriptAppendMessage("Layout not found", Color.Red, true)
end if
else
oMainWnd.ScriptAppendMessage("Error querying for layout name, is barcode '" + scannedCode + "' valid?", Color.Red, true)
end if
else
return 0
end if
end if
catch ex as Exception
oMainWnd.ScriptAppendMessage(ex.Message, Color.Red, true)
end try
end while
Attached Files

Viewing all articles
Browse latest Browse all 27388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>