Re: String or Numeric Variable?
- From: "ProfitMaxTrading.com" <nospam@xxxxxxxxxx>
- Date: Fri, 28 Oct 2005 16:27:55 -0500
Cool.
Thanks Alfie.
:-)
"Alfie [UK]" <me@xxxxxxxxxxx> wrote in message
news:mg25m158u7foom64h6988c3bgmaq2sfj2c@xxxxxxxxxx
> On Fri, 28 Oct 2005 14:59:11 -0500, "ProfitMaxTrading.com"
> <nospam@xxxxxxxxxx> wrote:
>
>>Hi Mike.
>>
>>Thanks for your comments.
>>
>>Okay, it appears that using numeric constants will solve the 'readability'
>>issue and Enum (Fernando's comment) perhaps more efficient? So I'll go
>>with
>>the numeric route rather than string because I have a ton of these
>>IF..THENS that work off these all through the program.
>
> Considering your usage CONSTs or ENUMs are definitely a good choice for
> readability, efficiency, etc. I believe CONSTs, and therefore checks
> against CONSTs, are optimized in the compiled EXE, whereas variables are
> not (and the ENUM would rely on a variable).
>
> I would think that in your proposed usage it would not make much
> difference if you used;
>
> Const Morning As Long = 1 ' or BYTE
> Const Afternoon As Long = 2
> Const Evening As Long = 3
>
> If TimeOfDay = Morning Then ...
>
> ...or...
>
> Enum TOD
> Morning = 1
> Afternoon = 2
> Evening = 3
> End Enum
> Dim TimeOfDay as TOD
>
> If TimeOfDay = Morning Then ...
>>
>>But you mentioned LONG as opposed to BYTE or INTEGER. Are you saying that
>>a
>>LONG type is better for even single-digit numbers used for nothing more
>>than
>>comparisons (as opposed to having math performed on them) than a BYTE or
>>INTEGER type?
>>
>>Obviously the BYTE or INTEGER type would use less memory. But I suppose
>>not
>>a big deal if you don't over do it. But just why is LONG better?
>>
> LONGs are generally more efficient (in 32-bit environments) when used in
> calculations, so if for instance you were ANDing or ORing your values
> for some reason to get combinations of TimeOfDay you might see some
> difference (definitely if performing math functions on them).
>
> If memory is likely to be an issue then use the lowest datatype you need
> to support your min/max possible values, but if not it never hurts to
> use a LONG (I've not tried any profiling but I wonder if a LONG CONST
> produces any lesser/greater optimisation than a BYTE CONST ?).
>
> ENUM values are always declared as LONGs by the way (hence no datatype
> specifier).
> --
> Alfie
> <http://www.delphia.co.uk/>
> Steinbach's Guideline for Systems Programming: Never test for an error
> condition you don't know how to handle.
>
.
- Follow-Ups:
- Re: String or Numeric Variable?
- From: Alfie [UK]
- Re: String or Numeric Variable?
- References:
- String or Numeric Variable?
- From: ProfitMaxTrading.com
- Re: String or Numeric Variable?
- From: ProfitMaxTrading.com
- Re: String or Numeric Variable?
- From: Alfie [UK]
- String or Numeric Variable?
- Prev by Date: Re: Virtual DOS Window in VB?
- Next by Date: Re: String or Numeric Variable?
- Previous by thread: Re: String or Numeric Variable?
- Next by thread: Re: String or Numeric Variable?
- Index(es):
Relevant Pages
|