|
Hi Shane,
I never thought that you assign a Com-Port at this place.
So ... there are some Information missing to go further.
How is ReaderDeviceInfo declared ?
How and where do you have the COM-Port in your code ? Where do you assign an initialize it ?
I think that are parts which belong to the Designer-Scripts from the C#-Project - you should look also there and perhaps complete your code.
If not try to answer my questions ...
|
|
|
|
|
Perhaps little background will help as I can't post an image of the form. I have an RFID reader which connects to the computer via a usb. The sample app from the supplier (the c# Code). Just provides a list of available devices in a combobox after clicking the refresh button. This all works in my VB code as well and after clicking the button it shows a list of (COM1 and COM5 on my laptop) in the combobox. After selecting the correct COM from the dropdown (COM5 in my case). You then click the connect button and it is at this point that my VB code falls over, but the C# code works fine. The form is very simple, I have compared the designer code and nothing different there either. I'm just very confused as to why the VB code gives the null exception but the C# code doesn't. Yet the code is almost identical.
The writelog is just a list box which provides a log of all the steps taken and events which are initiated by the reader.
Hope this helps
Regards
Shane
|
|
|
|
|
Hi Shane,
when I compare both codes (C# vs. VB) I can't see any relevant difference. For me both codes should do the same.
But any difference must be there ...
So : what about the Visual Studio Settings ? Have you added the required DDL's to the references (I hope the name is right - In German it's called 'Verweis') of your Project ?
Greetings
Ralf
|
|
|
|
|
Yes, all dll's have been added. Very confusing to me, why it doesnt work
|
|
|
|
|
If I put the reader = New Reader() in the connect sub, the error goes away, but nothing works like it should. it doesnt pick up the events or anything
Private Sub connect()
reader = New Reader()
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
reader.InputDevice = readerDeviceInfo
reader.OutputDevice = New ReaderDeviceInfo(ReaderDeviceType.None)
reader.OpenInputDevice()
reader.OpenOutputDevice()
End Sub
|
|
|
|
|
Let's get back to the ComboBox and it's ReaderDeviceInfo ...
I can't see a code-line where the ComboBox is assigned/filled AND with what it is filled.
I suggest that you should look there ...
|
|
|
|
|
Shane James wrote: If I put the reader = New Reader() in the connect sub, the error goes away, but nothing works like it should. it doesnt pick up the events or anything
This is normal: you create a new instance of the Reader class but this one is not configured like the first one was in the constructor of Results_Capture_Enduro . But I don't think the problem is here, you should remove this line.
You did not tell us which variable triggers the exception. To find it you can remove the try...catch block around the call to connect() to let the debugger stop at the line the exception occurs.
There is one line where the VB code is not equivalent to its C# counterpart:
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
The strictly equivalent version would be:
Dim readerDeviceInfo As ReaderDeviceInfo = DirectCast((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
See this article:
DirectCast vs. CType[^]
for explanations. In general using CType for a simple type cast is dangerous because it will try to do something even if the cast is not possible, so that the error may propagate to other parts of the code where it is difficult to understand.
NB. Also be careful when translating from C# to VB.NET as the latter is not really case sensitive which may cause compilation errors:
vb.net - Is VB really case insensitive? - Stack Overflow[^]
|
|
|
|
|
Shane James wrote: it shows a list of (COM1 and COM5 on my laptop) in the combobox. I am going to guess that it does not contain a list of strings that represent comports, but objects.
Show us how the VB version that initializes the combobox looks like.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I've got this code that queries a table and returns a model:
Public Function GetRightCategory(Id As Integer) As RightCategoryModel
Dim result As New RightCategoryModel
Dim queryCmd As String
queryCmd = "SELECT RightCategoryId, Category, Description, IsDeleted FROM tblRightCategories WHERE RightCategoryId = " + CStr(Id)
Dim Db As Database
Dim rs As Recordset
Set Db = DBEngine(0)(0)
Set rs = Db.OpenRecordset(queryCmd)
If rs.RecordCount > 0 Then
With result
.Id = rs.Fields("RightCategoryId")
.Category = rs.Fields("Category")
.Description = rs.Fields("Description")
.IsDeleted = rs.Fields("IsDeleted")
End With
End If
set GetRightCategory = result
Everything works great until I get past the last line. Then I get "Object doesn't supprot this property or method"
What's wrong here?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You have result defined as a RightCategoryModel type. How is GetRightCategory defined?
|
|
|
|
|
It's at the top. The formatter didn't format it
"Public Function GetRightCategory(Id As Integer) As RightCategoryModel"
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Sorry, I can't see anything untoward in that. I use functions in both Excel and Word and have never had a problem with return values.
|
|
|
|
|
I saw something while Googling that suggested that this record set syntax is what it doesn't like:
I have this:
.Id = rs.Fields("RightCategoryId")
The Google result had this:
.Id = rs!RightCategoryId
Is there any difference in these two syntaxes?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
How is this method being called? The "Set ..." has to be there on the line of code calling this method.
In VBA/6, you had to specify "Set something = MyMethodCallReturningAnObject()". Any method returning an intrinsic type doesn't need the Set before the assignment, but methods that return objects do.
|
|
|
|
|
That did it. I didn't have the 'set' in the call to the method.
Thank you!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It's scary that I still remember that crap from 2001.
|
|
|
|
|
|
Good day friends, I am trying to check the status of a printer connected to a system from VB.Net application.
But when I start the application, it shows the following error: Object reference not set to an instance of an object. pointing to the PrintQueue.
I made a successful reference to the System.Print.
Imports System.Printing
Public Class Form1
Private Sub ConnectionStatusToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ConnectionStatusToolStripMenuItem.Click
If thPQueue.IsOffline = True Then
MsgBox("The printer is currently offline.", vbInformation + vbOKOnly, "Printer Status")
ElseIf thPQueue.IsWaiting Then
MsgBox("The printer is on wait mode.", vbInformation + vbOKOnly, "Printer Status")
ElseIf thPQueue.IsWarmingUp Then
MsgBox("The printer is currently warming up. Please wait", vbInformation + vbOKOnly, "Printer Status")
ElseIf thPQueue.IsNotAvailable Then
MsgBox("The printer is currently not available.", vbInformation + vbOKOnly, "Printer Status")
End If
End Sub
End Class
Any solution will be appreciated. Thanks in advance!
|
|
|
|
|
If thPQueue Is Nothing Then
MsgBox("Printer queue not initialized.", vbCritical + vbOKOnly, "Printer Status")
ElseIf ...
Now debug your code and find out why thPQueue has not been initialized.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for your quick response. But how can check if the thPQueue is been initialized or not?
|
|
|
|
|
If it's Nothing , then it hasn't been initialized.
Debug your code and step through the part that creates the PrintQueue . Either it's not being executed, or it's not doing what you expect.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi All,
Please can any one help with a sample code to store DICOM files into mssqlserver dataase. Thanks
|
|
|
|
|
The format of the file is not important to the database; binary data is all stored the same way. Any tutorial that shows how to save a picture in a database should work.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Goggle for "vb.net store images in SQL Server". A DICOM image is no different than any other blob you might store in the database.
Depending on what your app is doing, you really wouldn't store the images in the database, but you would store all the metadata for that image, including a path to the actual image file, which you store on disk in a well-known location somewhere.
|
|
|
|