Monday, May 24, 2010

Why does this line of C++ code not work?

label1 -%26gt;Text = vScrollBar1-%26gt;Value;





The control names are correct what else can it be ???????

Why does this line of C++ code not work?
vScrollBar1-%26gt;Value provides an integer, while the label1 -%26gt;Text requires a string. Cast vScrollBar1-%26gt;Value to a string and hopefully that should work.
Reply:The first answer looks right to a point.


If you try to do this:


label1 -%26gt;Text = (char)vScrollBar1-%26gt;Value;





you will probably not get what you expect. For example, if vScrollBar1-%26gt;Value=65, then label1 -%26gt;Text will be the ASCII character with value 65, which is 'A'.





You can do the following:





char buffer[10];


sprintf(buffer, "%d", vScrollBar1-%26gt;Value);


label1 -%26gt;Text = buffer;





provided you have the appropriate member to set Text from char[].














cast the integer to char to


You can't cast a integer into text. You can do the following


No comments:

Post a Comment