[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Help with hexadecimals in VB6

BookWight

6/2/2011 6:45:00 AM

Hi -

I've got a label in a simple counting program and I'm trying to set the
background and foreground colors via a select case statement

Select Case TumsCounter
Case 0, 1, 2, 3, 4, 5, 6
lblTumsCount.BackColor = &H400000
lblTumsCount.ForeColor = &HFF00 <---- prog stops here w/ error
"runtime error 380
invalid property value"
Case 7, 8
lblTumsCount.BackColor = &H400000
lblTumsCount.ForeColor = &HFFFF
Case 9, 10, 11
lblTumsCount.BackColor = &H400000
lblTumsCount.ForeColor = &HFF
Case Else
' make the number blink by setting the text of the label to
' "0" and "" (blank) at intervals using the timer

End Select


Obviously, I'm doing something wrong, but I can't tell what . . .

Is the fact that the color falues in the label property box begin & end
with an '&' important or a red herring?

Why does the program stop at the second hex value and not the first?

TIA for any useful information
4 Answers

ralph

6/2/2011 7:15:00 AM

0

On 02 Jun 2011 06:44:57 GMT, BookWight <Bookwight@publicspam.com>
wrote:

>Hi -
>
>I've got a label in a simple counting program and I'm trying to set the
>background and foreground colors via a select case statement
>
>Select Case TumsCounter
> Case 0, 1, 2, 3, 4, 5, 6
> lblTumsCount.BackColor = &H400000
> lblTumsCount.ForeColor = &HFF00 <---- prog stops here w/ error
> "runtime error 380
> invalid property value"
> Case 7, 8
> lblTumsCount.BackColor = &H400000
> lblTumsCount.ForeColor = &HFFFF
> Case 9, 10, 11
> lblTumsCount.BackColor = &H400000
> lblTumsCount.ForeColor = &HFF
> Case Else
> ' make the number blink by setting the text of the label to
> ' "0" and "" (blank) at intervals using the timer
>
>End Select
>
>
>Obviously, I'm doing something wrong, but I can't tell what . . .
>
>Is the fact that the color falues in the label property box begin & end
>with an '&' important or a red herring?
>

Very, very important.

The ampersand at the end tells VB the value is Long. (It has nothing
to do with Hexdecimal notation.)

I suspect '&HFF' is translated to an Integer (2-byte) with the value
of -1, and is used below the surface as a MASK against a 4-byte
variable.

But frankly I'm not sure what VB might be doing. But correctly typing
the number to a Long will fix the problem.

>Why does the program stop at the second hex value and not the first?
>

Best guess is because it can't be interpreted as a 'signed' number.

-ralph

Dee Earley

6/2/2011 8:12:00 AM

0

On 02/06/2011 08:15, ralph wrote:
> On 02 Jun 2011 06:44:57 GMT, BookWight<Bookwight@publicspam.com>
> wrote:
>
>> Hi -
>>
>> I've got a label in a simple counting program and I'm trying to set the
>> background and foreground colors via a select case statement
>>
>> Select Case TumsCounter
>> Case 0, 1, 2, 3, 4, 5, 6
>> lblTumsCount.BackColor =&H400000
>> lblTumsCount.ForeColor =&HFF00<---- prog stops here w/ error
>> "runtime error 380
>> invalid property value"
>
> I suspect '&HFF' is translated to an Integer (2-byte) with the value
> of -1, and is used below the surface as a MASK against a 4-byte
> variable.
>
> But frankly I'm not sure what VB might be doing. But correctly typing
> the number to a Long will fix the problem.

&HFF00 will be expanded (when used as a long) to &HFFFFFF00 which, as it
says is an "Invalid property value" for a colour.

?hex(&HFF00),&HFF00
FF00 -256
?hex(clng(&HFF00)),clng(&HFF00)
FFFFFF00 -256
?hex(&HFF00&),&HFF00&
FF00 65280

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

ralph

6/2/2011 9:38:00 AM

0

On Thu, 02 Jun 2011 09:12:26 +0100, Dee Earley
<dee.earley@icode.co.uk> wrote:

>On 02/06/2011 08:15, ralph wrote:
>> On 02 Jun 2011 06:44:57 GMT, BookWight<Bookwight@publicspam.com>
>> wrote:
>>
>>> Hi -
>>>
>>> I've got a label in a simple counting program and I'm trying to set the
>>> background and foreground colors via a select case statement
>>>
>>> Select Case TumsCounter
>>> Case 0, 1, 2, 3, 4, 5, 6
>>> lblTumsCount.BackColor =&H400000
>>> lblTumsCount.ForeColor =&HFF00<---- prog stops here w/ error
>>> "runtime error 380
>>> invalid property value"
>>
>> I suspect '&HFF' is translated to an Integer (2-byte) with the value
>> of -1, and is used below the surface as a MASK against a 4-byte
>> variable.
>>
>> But frankly I'm not sure what VB might be doing. But correctly typing
>> the number to a Long will fix the problem.
>
>&HFF00 will be expanded (when used as a long) to &HFFFFFF00 which, as it
>says is an "Invalid property value" for a colour.
>
>?hex(&HFF00),&HFF00
>FF00 -256
>?hex(clng(&HFF00)),clng(&HFF00)
>FFFFFF00 -256
>?hex(&HFF00&),&HFF00&
>FF00 65280

Thanks for that correction.

'-256' makes more sense than '-1'. I always manage to confuse myself
when fiddling with a signed bit. You don't go down one, you go down a
lot. <bg>

Thorsten Albers

6/2/2011 11:54:00 AM

0

BookWight <Bookwight@publicspam.com> schrieb im Beitrag
<Xns9EF7F197EF89Abookwight@207.246.207.16>...
> lblTumsCount.BackColor = &H400000
> lblTumsCount.ForeColor = &HFF00 <---- prog stops here w/ error
> lblTumsCount.BackColor = &H400000
> lblTumsCount.ForeColor = &HFFFF
> lblTumsCount.BackColor = &H400000
> lblTumsCount.ForeColor = &HFF

Beside what the others said: The values presuambly would be much better to
read for you and others if you would use the predefined VB colour constants
(e.g. vbBlack); if there is none for your colour then you should let VB
compose it from the single RGB colour values by using RGB() which is an
easy to use and error free method.

--
Thorsten Albers

gudea at gmx.de