You could also use the routines below that I use with existing Dymo label templates. I just went into dymo software one day and created a lot of templates that I wanted and threw them intot he program directory that I wanted. Then the user selects the template that they want and uses the code below to add the user selected details.
I had a lot of help getting this going.
Code: Select all
; Find the specific printer needed for Dymo labels and warn user if it doesn't exist
Procedure FindNeededPrinter(NeededPrinter.s)
;#PRINTER_ENUM_LOCAL | #PRINTER_ENUM_CONNECTIONS;| #PRINTER_ENUM_REMOTE
;"DYMO LabelWriter"
;
; Find the list of printers installed on the system
EnumPrinters_(#PRINTER_ENUM_LOCAL | #PRINTER_ENUM_CONNECTIONS, 0, 1, #Null, 0, @dwNeeded, @dwReturned)
; Show the error returned by this system call. There will be one but not critical
Debug GetLastErrorString(GetLastError_())
;
If dwNeeded
*buffer = AllocateMemory(dwNeeded)
EnumPrinters_(#PRINTER_ENUM_LOCAL | #PRINTER_ENUM_CONNECTIONS, 0, 1, *buffer, dwNeeded, @dwNeeded, @count)
For i = 1 To count
PointerString = PeekI(*buffer + (i - 1) *SizeOf(PRINTER_INFO_1) + OffsetOf(PRINTER_INFO_1\pName))
;Debug PeekS(PointerString)
If FindString(PeekS(PointerString), NeededPrinter.s, 1)
PrinterFound.i = 1
EndIf
Next
FreeMemory(*buffer)
EndIf
;
If PrinterFound.i
Debug NeededPrinter.s + " was found in the system. Labels can be printed."
Else
Debug "Needed label printer: " + NeededPrinter.s + " was Not found in the system!!"
EndIf
;
EndProcedure
; Read and load Dymo XML data off disk to extract the images too display to the user
Procedure DecodeDymoXMLFile(*CurrentNode, CurrentSublevel.i)
;
If XMLNodeType(*CurrentNode) = #PB_XML_Normal
;
*ChildNode = ChildXMLNode(*CurrentNode)
;
While *ChildNode <> 0
; Returns the tagname of the given XML node;
NodeName.s = GetXMLNodeName(*ChildNode)
;
If NodeName.s = "Image"
; Returns the text inside the given XML node.
Program\DecodedLabelGraphic = GetXMLNodeText(*ChildNode)
;
EndIf
;
DecodeDymoXMLFile(*ChildNode, CurrentSublevel.i + 1)
*ChildNode = NextXMLNode(*ChildNode)
;
Wend
;
EndIf
;
EndProcedure
; Show the dymo label graphic next to the label template picker in my data form
Procedure ShowDymoLabelGraphic()
;
LabelName.s = GetGadgetText(#Gadget_Address_template)
;
If LabelName.s <> ""
; Did we get a file handle?
FileId.i = LoadXML(#PB_Any, Program\LabelDirectory + LabelName.s)
; Did we get a file handle?
If FileId.i
; Get the main node of the XML document
*MainNode = MainXMLNode(FileId.i)
; Parse the XML file
DecodeDymoXMLFile(*MainNode, CurrentSublevel.i)
;
If Program\DecodedLabelGraphic <> ""
; Get the real file length
ActualLen.i = Len(Program\DecodedLabelGraphic)
; Create a buffer for the file to decode
*DecodeBuffer = AllocateMemory(ActualLen.i)
; Create a buffer for the decoded file
*OutputBuffer = AllocateMemory(ActualLen.i)
;
If PokeS(*DecodeBuffer, Program\DecodedLabelGraphic, ActualLen.i) <> 0
; Decode the file
ActualBytes.i = Base64Decoder(*DecodeBuffer, ActualLen.i, *OutputBuffer, ActualLen.i)
;
If ActualBytes.i
;
DecodedPictureHandle.i = CatchImage(#PB_Any, *OutputBuffer, ActualBytes.i)
;
If DecodedPictureHandle.i
;
ResizeImage(DecodedPictureHandle.i, 85, 55, #PB_Image_Smooth)
;
SetGadgetState(#Gadget_Address_itemplate, ImageID(DecodedPictureHandle.i))
;
Program\DecodedLabelGraphic = ""
;
Else
Debug "Could not create the output file on disk, no handle"
EndIf
;
Else
Debug "Didn't manage to decode any data damn it"
EndIf
;
Else
Debug "Didn't manage to poke any string data!!"
EndIf
;
Else
Debug "No image found in label code."
EndIf
;
Else
Debug "Cold not load the XML label code."
EndIf
;
Else
; SetGadgetState(#Gadget_Address_template, ImageID(#Image_Address_itemplate))
EndIf
;
EndProcedure
; Create a dymo label for each passed address string
Procedure MakeDymoLabel(AddressString.s, LabelTemplate.s)
;
AddressString.s = ReplaceString(AddressString.s, #CRLF$, Chr(34) + " + chr(10) + " + Chr(34))
;
If AddressString.s
;
DymoScript.i = CreateFile(#PB_Any, Program\TemporaryDirectory + "DymoLabel.vbs")
;
If DymoScript.i
;
WriteStringN(DymoScript.i, "Dim DymoAddIn")
WriteStringN(DymoScript.i, "Dim DymoLabel")
WriteStringN(DymoScript.i, "Set DymoAddIn = CreateObject(" + Chr(34) + "DYMO.DymoAddIn" + Chr(34) + ")")
WriteStringN(DymoScript.i, "Set DymoLabel = CreateObject(" + Chr(34) + "DYMO.DymoLabels" + Chr(34) + ")")
;
If LabelTemplate <> "" ; Blank template selected
If FileSize(Program\LabelDirectory + LabelTemplate.s) > 3 ; If the label file is GREATER THAN 3 characters and exists
WriteStringN(DymoScript.i, "DymoAddIn.Open " + Chr(34) + Program\LabelDirectory + LabelTemplate.s + Chr(34))
; Else
; Debug "No template file found, writing to blank label."
EndIf
EndIf
;
WriteStringN(DymoScript.i, "DymoLabel.SetAddress 1, " + Chr(34) + AddressString.s + Chr(34))
WriteStringN(DymoScript.i, "DymoAddIn.Print 1, TRUE")
;
CloseFile(DymoScript.i)
;
RunProgram(Program\TemporaryDirectory + "DymoLabel.vbs", "", "", #PB_Program_Hide|#PB_Program_Wait)
;
Else
Debug "Dymo label VBScript file could not be created."
EndIf
;
Else
Debug "Address string cannot be empty"
EndIf
;
EndProcedure
And as for how I personally collect the data and send it to the MakeDymoLabel routine..
Code: Select all
; Print labels for the selected addresses
Procedure PrintLabel(SourceForm.s)
; Work out the source of the record number
Select SourceForm.s
Case "MainForm"
CurrentLine.i = GetGadgetState(#Gadget_AddressMuncher_NameList)
RecordNumber.s = GetGadgetItemText(#Gadget_AddressMuncher_NameList, CurrentLine.i, Program\AddressColumn)
Case "AddressForm"
RecordNumber.s = Program\CurrentAddressRecord
EndSelect
; Setup a query to get the elements needed for the label
DatabaseQuery.s = "SELECT "
DatabaseQuery.s + "Title, Firstname, Middlename, Lastname, Pobox, Street, Suburb, City, "
DatabaseQuery.s + "State, Postcode, Template "
DatabseQuery.s + "FROM Addresses "
DatabaseQuery.s + "WHERE Record = '" + RecordNumber.s + "'"
;
If DatabaseQuery(Program\DatabaseHandle, DatabaseQuery.s)
; Loop through all returned data
While NextDatabaseRow(Program\DatabaseHandle)
;
Title.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 0))
Firstname.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 1))
Middlename.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 2))
Lastname.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 3))
PoBox.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 4))
Street.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 5))
Suburb.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 6))
City.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 7))
State.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 8))
Postcode.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 9))
Template.s = KillQuote(GetDatabaseString(Program\DatabaseHandle, 10))
;
Wend
FinishDatabaseQuery(Program\DatabaseHandle)
EndIf
;
RequesterString.s = "Print label for:" + Chr(10) + Chr(10) + Title.s + " " + Firstname.s + " " + Middlename.s + " " + Lastname.s + Chr(10)
If PoBox.s <> ""
RequesterString.s + PoBox.s + Chr(10)
EndIf
If Street.s <> ""
RequesterString.s + Street.s + Chr(10)
EndIf
RequesterString.s + Suburb.s + " " + City.s + " " + State.s + " " + Postcode.s
;
If MessageRequester("Print label for current address.", RequesterString.s, #PB_MessageRequester_YesNo) = PB_MessageRequester_Yes
;
If Title.s <> "" : NameString.s + Title.s + " " : EndIf ; Mr_
If Firstname.s <> "" : NameString.s + Firstname.s + " " : EndIf ; Gary_
If Middlename.s <> "" : NameString.s + Middlename.s + " " : EndIf ; John_
If Lastname.s <> "" : NameString.s + Lastname.s : EndIf ; Rhinoceros
If PoBox.s <> "" : PoBoxString.s + PoBox.s : EndIf ; P.O Box 1238
If Street.s <> "" : StreetString.s + Street.s : EndIf ; 12 Rototruah Way
If Suburb.s <> "" : SuburbString.s + Suburb.s + " " : EndIf ; Wakatonky_
If City.s <> "" : SuburbString.s + City.s + " " : EndIf ; Braxtonia__
If State.s <> "" : SuburbString.s + State.s + " " : EndIf ; Hamilton_
If Postcode.s <> "" : SuburbString.s + Postcode.s : EndIf ; 20398
;
If NameString.s <> "" : DymoString.s + NameString.s + #CRLF$ : EndIf
If PoBoxString.s <> "" : DymoString.s + PoBoxString.s + #CRLF$ : EndIf
If StreetString.s <> "" : DymoString.s + StreetString.s + #CRLF$ : EndIf
If SuburbString.s <> "" : DymoString.s + SuburbString.s : EndIf
;
MakeDymoLabel(DymoString.s, Template.s)
;
Else
Debug "User elected to cancel the label print job."
EndIf
;
EndProcedure ;