• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Syntax of a ushort parameter in a method

I try to use a method declared as this:

         OSensor (ushort PID, ref TOak)

with this line:

        OSensor ( " {1:X4}", refTOak)

Gives me an error : "invalid argument, unable to convert from string to ushort"

What is the exact syntax ?

Thank you
0
luciepaul
Asked:
luciepaul
  • 5
  • 4
  • 2
1 Solution
 
käµfm³d 👽Commented:
Why are you passing a string?
0
 
Fernando SotoCommented:
Hi luciepaul;

Use implicit cast to ushort :

OSensor ( (ushort) 5, ref TOak)

Or

ushort PID = 5;
OSensor ( (ushort) PID, ref TOak)

Fernando
0
 
käµfm³d 👽Commented:
@FernandoSoto

Did you mean to say "explicit"   ; )
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Fernando SotoCommented:
Yes I did. That is what happens when you get a little bit on in years your mind thinks one thing and your fingers do another. LOL
0
 
luciepaulAuthor Commented:
None of those solutions are working
0
 
käµfm³d 👽Commented:
You didn't answer my question...  : (
0
 
luciepaulAuthor Commented:
To Kaufmed
The manufacturer doc that provide the function gives an example using string
0
 
käµfm³d 👽Commented:
What you have posted, {1:X4}, appears to be a format string. Given the format of the string, it appears that a hexadecimal representation is expected. One problem with the format string, however, is that is starts with 1, which would indicate that it's the second parameter to a String.Format() call. I would expect the call using that string to be something like:

    string.Format("{0} {1:X4}", someVariable, someOtherVariable);

I'm guessing that's not what you need here, though.

Can you provide the name of some variable you have declared as ushort in your code? A line similar to:
ushort myVariable = 4;

Open in new window

0
 
luciepaulAuthor Commented:
As you see in the code I send, there is no variable of that kind.
In the Form3.cs, when I use the overloaded function Oak_FindSensor_a with all the arguments, the ony error message i've got concern the two "ushort" arguments.

Here is the wrong line:

OakSensor.Oak_FindSensor_a("{1:X4}PID" , "{2:X4} REV ", "{3} SN", "{0} DeviceName",  "{0} ChannelName", "{0} UserDeviceName", "{1} UserChannelName", ref sensor);
0
 
käµfm³d 👽Commented:
As you see in the code I send, there is no variable of that kind.
Ah, but there is! You declared a new "tOakSensor" just before the call to Oak_FindSensor_a(). "tOakSensor" has a few members that are defined as type ushort...  you can send those. However, see my comment in the other question as to why I don't think that's the final answer.
0
 
luciepaulAuthor Commented:
kaufmed

My question was not really well written.. so I think I have to give you the points in that question and follow with the other one
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now