Solved

ASP Barcode Print function?

Posted on 2011-03-24
8
554 Views
Last Modified: 2012-05-11
Can someone help me to understand what exactly this code is doing?
What happens is this .asp pulls label info from a SQL DB, then it splits up the label info into 3 parts (barcode, labelname, createdby). Then it calls a function (DoPrint) that I am not sure really what is doing exactly. In dBartender2009CTdish.exe there is this line of code sArg = Command(). Does this tie the .asp to the VB6 exe somehow?

Thanks

Here is the rest of the .asp code from that page:


<%

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConn

sSQL = "select * from PrintList where ID = " & Request.QueryString("PLID")
set rs = oConn.Execute(sSQL)

sArg = rs("PrintList")
sSTR = ""

sSubArg = Split(sArg, "|") ' - whole passed argument is now an array
Dim y
For y = 0 To UBound(sSubArg)
    sLabelInfo = Split(sSubArg(y), ",") ' - sLabelInfo is now an array
    nBarcode = CStr(sLabelInfo(0))
    sLabelName = CStr(sLabelInfo(1))
    sCreatedBy = CStr(sLabelInfo(2))
	sStr1 = "dBartender2009CTdish.exe " & nBarcode & "," & sLabelName & "," & sCreatedBy
	sStr = sStr & "setTimeout " & Chr(34) & "doPrint('" & sStr1 & "')" & Chr(34) & "," & (y * 2500) & vbcrlf
Next

if Request.QueryString("redir") <> "" then
	sRedir = Request.QueryString("redir")
else
	sRedir = "search.asp"
end if

sStr = sStr & "setTimeout " & Chr(34) & "window.document.location.href='" & sRedir & "'" & Chr(34) & "," & (y * 2500) + 1500 & vbcrlf

sSQL = "delete from PrintList where ID = " & Request.QueryString("PLID")
oConn.Execute(sSQL)

%>

Open in new window

<META name="VI60_DefaultClientScript" Content="VBScript">
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Dim sStr

Sub window_onload
	<%= sStr %>
End Sub

Sub doPrint(sLabelData)
	set WSHShell = CreateObject("WScript.Shell")
	WSHShell.Run sLabelData,0,1
	set WSHShell = nothing
End Sub

-->
</SCRIPT>

Open in new window

0
Comment
Question by:Ahelbling
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 13

Accepted Solution

by:
samic400 earned 500 total points
ID: 35207376
                    set WSHShell = CreateObject("WScript.Shell")
      WSHShell.Run sLabelData,0,1
      set WSHShell = nothing

This code above is actually executing the vb program called dBartender2009CTdish.exe and passing its parameters from your code above in your ASP page.

WSHShell.Run is the command that is doing the work in your ASP page.
0
 

Author Comment

by:Ahelbling
ID: 35207389
samic400, thanks. But where is sLabelData coming from/doing ? I dont see it anywhere else in any of the code?
0
 
LVL 13

Expert Comment

by:samic400
ID: 35207392
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Assisted Solution

by:samic400
samic400 earned 500 total points
ID: 35207419
See line 22 and 23 above - you are building it there -

sStr1 = "dBartender2009CTdish.exe " & nBarcode & "," & sLabelName & "," & sCreatedBy
sStr = sStr & "setTimeout " & Chr(34) & "doPrint('" & sStr1 & "')" & Chr(34) & "," & (y * 2500) & vbcrlf

Whatever gets put in thr sStr1 variable -
doPrint('" & sStr1 & "')"

gets passed into this sub routine for doprint -
Sub doPrint(sLabelData)
      set WSHShell = CreateObject("WScript.Shell")
      WSHShell.Run sLabelData,0,1
      set WSHShell = nothing
End Sub

And that is how it would work.
0
 

Author Comment

by:Ahelbling
ID: 35207478
I see now thank you.

Can you help explain to me this vb .exe part?
Is  sArg = Command() accepting the arguments passed from doPrint via WSHShell.Run sLabelData,0,1 ?  What is the 0,1 doing?


Thanks

Private Sub Form_Load()
    
    If App.PrevInstance = True Then End
    'On Error Resume Next
    
    Dim nBarcode As String
    Dim dBeginDate As Date
    Dim sSpecies As String
    Dim sOwner As String
    Dim sNotes As String
    Dim sArg As String
    Dim nQty As Integer
    Dim i As Integer
    Dim sLabelInfo
    
    i = 0
    sArg = Command()
    'sArg = "30101,labelname1,jiskra1|30102,labelname2,jiskra2|30103,labelname3,jiskra3"

    Set BTApp = CreateObject("Bartender.Application")
    
    sSubArg = Split(sArg, "|") ' - whole passed argument is now an array
    Dim y
    For y = 0 To UBound(sSubArg)
        'MsgBox sSubArg(y)
        sLabelInfo = Split(sSubArg(y), ",") ' - sLabelInfo is now an array
        nBarcode = CStr(sLabelInfo(0))
        sLabelName = CStr(sLabelInfo(1))
        sCreatedBy = CStr(sLabelInfo(2))
        'printing snippet ++++++++++++++++++++++++++++++++++++++++++++
        Set BTFormat = BTApp.Formats.Open(App.Path & "\dish.btw")
        BTFormat.SetNamedSubStringValue "barcode", nBarcode
        BTFormat.SetNamedSubStringValue "LabelName", sLabelName
        BTFormat.SetNamedSubStringValue "CreatedBy", sCreatedBy
        BTFormat.PrintOut
        BTFormat.Close btDoNotSaveChanges
        '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Next

    BTApp.Quit
    
    Set BTApp = Nothing
    Set BTFormat = Nothing
    Set rs = Nothing
    Set conn = Nothing
    
    End
    
End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:samic400
ID: 35207536
These are parameters to the call - basically the parms are 0, 1

The 0 is for field for window style - 0 means don't show the cmd window when it runs
The 1 is for field for waiting for for the command to run before continuing in your ASP script

This can all be seen and described:
http://ss64.com/vb/run.html
http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx
0
 

Author Comment

by:Ahelbling
ID: 35207573
Perfect!

So for me to create a new label using this same information in the code above, all i really need to do is create the label in the designer, and make a renamed copy of the asp and .exe and change only this line in the .exe:

Set BTFormat = BTApp.Formats.Open(App.Path & "\dish.btw")


0
 
LVL 13

Expert Comment

by:samic400
ID: 35207596
That should do it for you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question