Solved

ASP Barcode Print function?

Posted on 2011-03-24
8
531 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
  • 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now