modCOMM - Written by: David M. Hitchner

The problem is that the second argument in the declaration of the CommSetLine procedure is declared ByRef and it's data type is incompatible to the data type of the variable or constant LINE_RTS.
And how can I solve it please, excuse me I'm truly a beginner at VBA
 
And how can I solve it please, excuse me I'm truly a beginner at VBA
I cannot tell. The problem is that this error does not happen with the original code. So, you must have either changed the declaration of the CommSetLine function or the LINE_RTS constant, which are both not visible in your screenshot.

You must make sure that the data type of the argument in the function declaration matches the data type of the variable you pass in to the function. Both were originally of type Integer.
I don't see any reason except laziness for passing the argument ByRef. So you could also change the passing mechanism for the argument to ByVal. Then the data types do not need to be identical but merely compatible.

If you want to learn this stuff in-depth, you could take a look at my VBA online course.
 
you teach him VBA for a fee when there are millions of E-book on VBA for free?
is there a guarantee that his serial comm will work?
I cannot tell.
 
And how can I solve it please, excuse me I'm truly a beginner at VBA

The general way to solve this is based on the fact that you called a function called CommSetLine. While I am an old hardware man and understand the concepts, I don't know that function personally. So here is what you must do.

You used that function because it has been declared somewhere. I know that because you couldn't get that error if the function had not been declared. You must examine the declaration of that function to see what the arguments look like in terms of data types. Then you need to find the declarations for those LINE_xxx constants. I'm going to make an educated GUESS that they are line status flags for DATA TERMINAL READY (DTR) and REQUEST TO SEND (RTS), two of the status bits for an RS-232-C serial port (the most common of the older serial ports). This link isn't from modCOMM but it does discuss use of RS-232-C serial ports using simple serial protocols and flags. It might help you to understand what you are doing, or at least trying to do.


There is an outside chance that in that context (from a VBA code page), you COULD try to open up the VBA Project Explorer and look for the CommSetLine function or procedure. If it is there, you can see its declaration data types. You can also look up LINE_DTR and LINE_RTS to see their defined data types. This will tell you if the data types match up correctly.

Here's the catch. I am answering this from my early days as a device-driver writer who had to "bit-twiddle" lots of devices back before Windows was even a thing. My serial-port experience was based on something other than a PC. So I'm basing this on stuff I did literally decades ago and haven't had to do recently - (translates to >30 years ago). Therefore if this is vague, I'm sorry but its the best I can do for you.
 

Users who are viewing this thread

Back
Top Bottom