I want to print a label through a Dymo LabelWriter 450 using the Dymo.Connect.SDK NuGet package.
Here my code:
Imports DymoSDK.Implementations
Imports DymoSDK.Interfaces
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dymoSDKLabel As DymoSDK.Implementations.DymoLabel
dymoSDKLabel.LoadLabelFromFilePath("path\Name.dymo")
Dim SelectedPrinter As String = "DYMO LabelWriter 450"
DymoPrinter.Instance.PrintLabel(dymoSDKLabel, SelectedPrinter, 1, True)
End Sub
Error message:
"The object reference was not set to an object instance."
That's why I set dymoSDKLabel = new DymoLabel() before i load the path. That would have been logical for me, but I get the error message: "Error resolving overload because no "new" is accessible"
Does anyone have any ideas how i can get to my goal? Unfortunately there is no real documentation for the NuGet package or code examples. If more information is needed, just ask. I am thankful for every help.
Best regards
I had the exact same issue as you, however after looking at the 1 VB sample available for the nuget package I adapted something I found there about using DymoLabel.Instance and have now managed to print:
Dim dymoSDKLabel As DymoLabel
dymoSDKLabel = DymoLabel.Instance
It also seems necessary to retrieve the printers prior to printing, even when specifying the printer by name:
Dim SelectedPrinter As String = "DYMO LabelWriter 450"
Dim Printers = DymoPrinter.Instance.GetPrinters()
Have to say working with this Dymo SDK is one of the worst things I have had to deal with. The documentation is appaling.
This work well for me !!
DymoSDK.App.Init()
Dim dymoSDKPrinter = DymoPrinter.Instance
Dim fullpath As String = System.IO.Path.GetFullPath(FileNameOfLabel)
Dim dymoSDKLabel = DymoLabel.Instance
dymoSDKLabel.LoadLabelFromFilePath(fullpath)
Dim LabelTextObject1 As DymoSDK.Interfaces.ILabelObject
LabelTextObject1 = dymoSDKLabel.GetLabelObject("NameOfLabel")
dymoSDKLabel.UpdateLabelObject(LabelTextObject1, "ValueOfLabel")
If dymoSDKPrinter.PrintLabel(dymoSDKLabel, LabelWriterCmb.Text, 1, False, False, 0, False, False) Then
MsgBox("Printed !", vbInformation)
End If
Related
I have a WinForms project that contains a RichTextBox (RTB) written with VB
I have set ShortcutsEnabled = FALSE in the RTB
To use any Spell Checker I am guessing this would need to set to TRUE
That is NOT my question! I have been reading for way more hours than I care to admit
With the understanding that Spell Checking is easy if you have a ASP.Net OR WPF project
Well I don't so here are the three candidates from NuGet NONE of these candidates offer much help
WeCantSpell.Hunspell and VPKSoft.SpellCheckUtility and NetSpell
I am not asking for a recommendation
Because I can not find a tutorial and am clueless on how to implement these Add In's with code
As well as NOT knowing if they are compatible with WinForms
I even looked at this CP post
CP LINK
Just a suggestion how to use one of these Add In's OR how to add spell checking to the RTB?
To achieve spell checking, you can try Nuget Package NHunspell.
First, you need to add "NHunspell" from "NuGet" and import it. The specific operation is as follows:
Right click the Reference and select "Manage NuGet Packages...", then type "NHunspell " in the search bar and install it:
Second step, you need to create a folder to store ".aff" and ".dic" like this.
Download the "zip" containing the corresponding file, you can access this site.
Here is a demo you can refer to.
Private Sub btCheck_Click(sender As Object, e As EventArgs) Handles btCheck.Click
Dim affFile As String = AppDomain.CurrentDomain.BaseDirectory & "../../Dictionaries/en_us.aff"
Dim dicFile As String = AppDomain.CurrentDomain.BaseDirectory & "../../Dictionaries/en_us.dic"
lbSuggestion.Items.Clear()
lbmorph.Items.Clear()
lbStem.Items.Clear()
Using hunspell As New Hunspell(affFile, dicFile)
Dim correct As Boolean = hunspell.Spell(TextBox1.Text)
checklabel.Text = TextBox1.Text + " is spelled " & (If(correct, "correct", "not correct"))
Dim suggestions As List(Of String) = hunspell.Suggest(TextBox1.Text)
countlabel.Text = "There are " & suggestions.Count.ToString() & " suggestions"
For Each suggestion As String In suggestions
lbSuggestion.Items.Add("Suggestion is: " & suggestion)
Next
Dim morphs As List(Of String) = hunspell.Analyze(TextBox1.Text)
For Each morph As String In morphs
lbmorph.Items.Add("Morph is: " & morph)
Next
Dim stems As List(Of String) = hunspell.Stem(TextBox1.Text)
For Each stem As String In stems
lbStem.Items.Add("Word Stem is: " & stem)
Next
End Using
End Sub
The result,
Hope this can help you.
I am creating an application using a windows forms application in visual studio in the vb.net language. I need help converting a structure that I coded into a binary file that is essentially a save in user results. I'm not a very good coder so excuse the poor code.
The code below shows that I have created a structure called saveresults and by clicking button1, it should get the contents of the binary file and edit them to be the new result. When I run the code the problem seems to be in the line FileOpen(1, "/bin/debug/1.txt", OpenMode.Binary) in the saveres subroutine.
Structure saveresults 'Structure for saving results
Dim numright As Integer
Dim numwrong As Integer
Dim totalnum As Integer
End Structure
'Subroutine aimed at getting stats saved to a text file to eventually be displayed to the user
Sub saveres(saveresults As saveresults, correct As Boolean)
saveresults.totalnum = saveresults.totalnum + 1
'Determining the contents to be saved to the binary file
If correct = True Then
saveresults.numright = saveresults.numright + 1
ElseIf correct = False Then
saveresults.numwrong = saveresults.numwrong + 1
End If
FileOpen(1, "/bin/debug/1.txt", OpenMode.Binary)
FilePut(1, saveresults)
FileClose(1)
End Sub
'attempt at saving results to the binary file
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim correct = True
Dim results As saveresults
FileOpen(1, "/bin/debug/1.txt", OpenMode.Binary)
FileGet(1, results)
saveres(results, correct)
FileClose(1)
End Sub
Any help would be appreciated. Thank you.
Use this instead
FileOpen(1, "1.txt", OpenMode.Binary)
Using the above opens the file in your project's debug folder.
You are referring to text files and binary files as if they are the same thing. They are not. Text files are human readable in Notepad; binary files are not.
I have not used the methods you are attempting since VB 6. Use the .Net System.IO methods. To use these you need to add Imports System.IO at the very top of your code file.
I have broken your code into Subs and Functions that have a single purpose. Reading the file, writing the file, updating the data, and displaying the data. This makes code more maintainable. If your code misbehaves it is easier to find the error and easier to fix if a method has only one thing to do.
The file location in the example is in the same directory as your .exe file. Probably
/bin/Degug.
'A Form level variable to hold the data
Private results As New saveresults
Structure saveresults 'Structure for saving results
Dim numright As Integer
Dim numwrong As Integer
Dim totalnum As Integer
End Structure
'Update the data
Private Sub UpdateResults(Correct As Boolean)
'It is not necessary to include = True when testing a Boolean
If Correct Then
'this is a shortcut method of writin results.numright = results.numright + 1
results.numright += 1
'A Boolean can only be True or False so if it is not True
'it must be False so, we can just use an Else
'No need to check the condition again
Else
results.numwrong += 1
End If
results.totalnum += 1
End Sub
'Write text file
Private Sub SaveResultsFile(results As saveresults, correct As Boolean)
Dim sb As New StringBuilder
sb.AppendLine(results.numright.ToString)
sb.AppendLine(results.numwrong.ToString)
sb.AppendLine(results.totalnum.ToString)
File.WriteAllText("1.txt", sb.ToString)
End Sub
'Read the text file
Private Function ReadResultsFile() As saveresults
Dim ResultsFiLe() = File.ReadAllLines("1.txt")
Dim results As New saveresults With
{
.numright = CInt(ResultsFiLe(0)),
.numwrong = CInt(ResultsFiLe(1)),
.totalnum = CInt(ResultsFiLe(2))
}
Return results
End Function
'Display
Private Sub DisplayResults()
Dim ResultsToDisplay As saveresults = ReadResultsFile()
'The $ indicates an interpolated string, the same thing can be accomplished with String.Format
Label1.Text = $"The correct number is {ResultsToDisplay.numright}. The wrong number is {ResultsToDisplay.numwrong}. The total is {ResultsToDisplay.totalnum}."
End Sub
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Wordprocessing
Imports DocumentFormat.OpenXml.Packaging
Public Class Add_bookmark
Const fileName As String = "F:\vb\part2 here\AddRemove.docx"
Const bookmarkName As String = "Page1"
Private Sub Add_bookmark_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using doc As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
Dim docBody As Body = doc.MainDocumentPart.Document.Body
Dim addBookmark As BookmarkStart = docBody.Descendants(Of BookmarkStart)().FirstOrDefault(Function(a) a.Name = bookmarkName)
If addBookmark Is Nothing Then
Throw New Exception(String.Format("Bookmark {0} not found", bookmarkName))
End If
'addBookmark.InsertAt(bookmarkName)
doc.MainDocumentPart.Document.Save()
End Using
End Sub
End Class
Here's my recommendation that I think will pretty much solve most Open XML SDK issue. They have both a comparison tool and a code generation tool. Use thoughts to your advantage.
Create the document you want to see in Microsoft Word. Save It.
Open the document again, add a bookmark. Save it again, but under a different name.
Open the XML SDK comparison tool and select both documents. It'll show you the differences, and also will show you the sample .NET code that can be used to create the 2 documents. In this case, you'll focus on the differences in the code.
I am having a problem with a tool that I wrote in VB.NET running on certain XP machines. The tool runs fine and as expected on Windows 7 and XP machines that have .NET 4.0.30319.1022.
I've noticed the XP machines that I am having trouble on are those that did not have .NET 4 even on it, so I went and installed .NET 4 which puts on version .NET 4.0.30319.1.
Here is the error:
Here is the code at line 86 (86 is the For Each):
'_BIOSVer
Dim bios_query As String = "SELECT * FROM " & "Win32_BIOS"
Dim bios_searcher As New ManagementObjectSearcher(bios_query)
For Each info As ManagementObject In bios_searcher.Get()
_BIOSVer = info.Properties("BIOSVersion").Value.ToString()
Next info
I am running Windows Updates for .NET 4 Framework to see if that will fix the issue, but I was wondering if you guys might have a sense of what is happening, or if my code is just wrong.
Updates just finished, restarted. It is running off of .NET 4.0.30319.1022 but still throws that error. Must be my code then.
There are several problems, but mainly BIOSVersion is a string array. Rather than poking into that, you can just get the Name which returns the version info (so does Caption and Description). Since you are after one thing, you dont need a loop, but I left it in as a template:
Dim myver As String = ""
Using searcher As New ManagementObjectSearcher("Select Name From Win32_Bios")
For Each mo As ManagementObject In searcher .Get
' EXAMPLE
'DebugProperties(mo)
' no real need to Loop - just for illustration
For Each pd As System.Management.PropertyData In mo.Properties
' if you do SELECT * and want to find something,
' compare Pd.Name to the target property
' some things can be nothing. Such as when a property does not
' exist on older systems, so always test:
If pd.Value IsNot Nothing Then
myver = pd.Value.ToString
Exit For
End If
Next
Next
End Using
Return myver
This is a helpful WMI debug tool to display all the property names and values (the code above has the call to this commented out):
Private Shared Sub DebugProperties(mo As Management.ManagementObject)
For Each pd As PropertyData In mo.Properties
If pd.Value IsNot Nothing Then
Console.WriteLine("{0} {1}", pd.Name,
If(pd.Value IsNot Nothing,
pd.Value.ToString,
"Nothing"))
End If
Next
End Sub
BIOS Version returns a string array (for more information check this link).
Try reading the data like this
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim BIOSSearcher As New ManagementObjectSearcher("SELECT BIOSVersion FROM Win32_BIOS")
Dim BIOSVersionInfo() As String = BIOSSearcher.Get(0).Properties("BIOSVersion").Value
Dim BIOSVersion As String = ""
If Not BIOSVersionInfo Is Nothing Then
BIOSVersion = String.Join(vbCrLf, BIOSVersionInfo)
End If
MsgBox(BIOSVersion)
End Sub
can you help me with that code ?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As String = "C:\Users\Andy\Documents\Visual Studio 2008\Projects\minecraft srv\"
For Each app As Process In Process.GetProcesses
If app.ProcessName = "notepad" Then
app.Kill()
End If
Next
Dim result As String
Dim servprop() As String
servprop = System.IO.Directory.GetFiles(x, "server.*")
For Each file In servprop
result = Path.GetFileName(file)
Next
Dim z As String = "C:\Users\Andy\Documents\Visual Studio 2008\Projects\minecraft srv\" & result.ToString
Dim t As StreamWriter = New StreamWriter(z)
t.WriteLine(TextBox1.Text.ToString)
t.Close()
End Sub
so... I got a button (button1) that finds if notepad is opened and kills it.
Then it searches for "server.Properties" in "x" location
if server.properties is found , then "result" will get his name (server)
"z" is the file location where streamwriter must write the text from textbox1 .
And it doesn't work... streamwirter is not writing on server.properties ... why ?
mention : I'm just a kid :D and i'm trying to learn by myself visual basic .
If you have only one file called "server.properties" then you could remove all the code that search for this file and write it directly.
Dim z As String
z = System.IO.Path.Combine(x, "server.properties")
Using t = New StreamWriter(z)
t.WriteLine(TextBox1.Text.ToString)
t.Flush()
End Using
Regarding the error, encapsulating the writing code with a proper using statement ensures a complete clean-up. Also adding a call to Flush() is probably not necessary, but doesn't hurt.