none
convert.tolnt16 result question. RRS feed

  • Question

  • Hello,

    I'm duplicate C# by labview so i need result of C# program.

    I'm stuck with one value that

    " Int16 interval = Convert.ToInt16(ADC_INTERVAL.Text); "

    " buff[4] = (byte)(interval / 256); "

    at here, ADC_INTERVAL.Text looks like a number but it is not defined.

    above that code, there is a remark about ADC_INTERVAL.Text. that says

    "       //     ADC_INTERVAL.Text = "500"; "

    as it is remark(//) it is not effect to program right?

    but there is "interval" value. how could it possible?

    does Convert.ToInt16 can change string to number?

    if it is possible, what is the value of "interval"

    please help me...

    Wednesday, April 4, 2018 7:01 AM

Answers

  • There certainly IS a definition of ADC_INTERVAL.Text, otherwise the program wouldn't build at all! (Assuming it does in fact build).

    What kind of project is this?

    Windows Forms? WPF? ASP.NET?

    I also suggest you look up the link I posted first about running with debugging. It is very easy to set a debug point and see what is happening.

    • Marked as answer by plasmablacktea Wednesday, April 4, 2018 11:45 AM
    Wednesday, April 4, 2018 11:07 AM

All replies

  • ADC_INTERVAL must clearly be defined somewhere but possibly in another file.

    It must be a class of some type with a Text property and my guess would be a visual control (maybe a TextBox control on a form or something; it depends on the type of project you are looking at).

    In Visual Studio you can run the program and set a debug point in your code. When the code stops, you can look at the value of ADC_INTERVAL.Text. Step through the program and you will see how your interval variable gets set.

    You are correct that ADC_INTERVAL.Text is a string value that holds a string-representation of a number (presumably). The Convert.ToInt16() method will convert that to an actual 16-bit integer and put it in the interval variable.

    Wednesday, April 4, 2018 8:06 AM
  • Well... I cannot find any other definition of ADC_INTERVAL.Text

    So, the fourth paragraph would be right

    (You are correct that ADC_INTERVAL.Text is a string value that holds a string-representation of a number (presumably). The Convert.ToInt16() method will convert that to an actual 16-bit integer and put it in the interval variable.)

    But I'm just a biggner that don't know how to set debug point

    and furthermore, this program is not working properly that i cannot run this..

    Would you tell me what is the value of Int16 interval = Convert.ToInt16(ADC_INTERVAL.Text);  ?

    Wednesday, April 4, 2018 9:03 AM
  • Hi plasmablackea,

    In C#, Convert is a static class, it has much methods to convert a base data type to another base data type.

    You can get more details about it with the following document in MSDN:

    Convert Class.

    For example, the code you provided above:

    ADC_INTERVAL.Text = "500";
    Int16 interval = Convert.ToInt16(ADC_INTERVAL.Text); 

    Just as RJP1973 said, the ADC_INTERVAL may be a control, its text is "500", and the ADC_INTERVAL.Text is a string-type, you can convert the string-type to Int16-type with Convert.ToInt16() method, so the 'interval' is 500.

    The point that must be specified is that if you want to convert type A to type B, its possibilities must exist. For example, you can convert string-type "500" to Int16-type and the result is 500, but you can not convert string-type "string" to Int16, because 'string' is not an integer.

    Regards,

    Frankie


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 4, 2018 9:05 AM
  • Hello Stanly Fan

    There is a one thing that I wonder.

    as I mentioned at my question,

    "       //     ADC_INTERVAL.Text = "500"; "

    is remarked (by //) line.

    even if it is remarked, can

    "Int16 interval = Convert.ToInt16(ADC_INTERVAL.Text);"

    take value of 500 from ADC_INTERVAL.Text ?

    Wednesday, April 4, 2018 9:51 AM
  • The line 

     //     ADC_INTERVAL.Text = "500";

    is just a comment (the // means that everything after it on the same line is a comment).. It won't do anything. My guess is that somebody put it in there just to test the following code and then commented it out rather than removing it.

    Wednesday, April 4, 2018 10:39 AM
  • If so, there is no definition of value of ADC_INTERVAL.Text

    Than, can I get the value of Int16 interval = Convert.ToInt16(ADC_INTERVAL.Text); ?

    I checked other programs that does not have any definition of ADC_INTERVAL.Text....

    Wednesday, April 4, 2018 10:43 AM
  • There certainly IS a definition of ADC_INTERVAL.Text, otherwise the program wouldn't build at all! (Assuming it does in fact build).

    What kind of project is this?

    Windows Forms? WPF? ASP.NET?

    I also suggest you look up the link I posted first about running with debugging. It is very easy to set a debug point and see what is happening.

    • Marked as answer by plasmablacktea Wednesday, April 4, 2018 11:45 AM
    Wednesday, April 4, 2018 11:07 AM