Re: inserting textbox value into bookmark

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jonathan West (jwest_at_mvps.org)
Date: 06/22/04


Date: Tue, 22 Jun 2004 18:15:47 +0100


"Alex Ivanov" <consul@collegeclub.com> wrote in message
news:u1gRxeHWEHA.3120@TK2MSFTNGP12.phx.gbl...
> & does the cstr in the background, you could save some typing efforts
> without calling it explicitly :)
> Me.Controls("txtLocation" & i).Text
> will do the same thing.
>

The & operator does something different, it deals with string concatenation.
What is happening if you omit the CStr function is that an implicit type
conversion is being done to the integer.

Personally, I prefer to do my type conversions explicitly, because then I
know exactly what is happening. 99 times out of a hundred it doesn't matter,
because the implicit type conversion does what I expect. But I would rather
be sure, because there are a number of different conversion functions, and
they produce slightly different results.

For instance, the Str() function does the same conversion as CStr(), except
that it puts a leading space on the resulting string if the number is
positive. Similarly, CLng returns an error if the string being converted
does not contain a valid number, but Val returns zero and does not throw an
error.

I prefer to use these functions explicitly rather than rely on VBA's default
behaviour. It's not impossible that the default might change in a future
version of Office, and even though I would want to hunt down the program
manager in Microsoft responsible for such a change, it would be too late
once the new version of Office had been released!

I'm not laying this down as a law - "Thou shalt use explicit type
conversions at all times", but it is a coding style which I use in my own
code, for the reasons I have described.

-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Relevant Pages

  • Re: Explicit conversion
    ... > Docs says that "The compiler does not use an explicit constructor to ... > implement an implied conversion of types. ... the "explicit" keyword deals with constructors declarations only withing ... > into ExClass type? ...
    (comp.lang.cpp)
  • Re: On "type casting"
    ... whether used in reference to an implicit conversion or an explicit ... refer to an explicit conversion is considered wrong by a number of people on this newsgroup who think type casting is only what ... They believe "cast" is correct but "type cast" isn't. ...
    (comp.lang.c)
  • Re: More static type fun.
    ... languages, such a conversion must be explicit, though there are a few ... a type is always explicit though, ... This is different to the situation in dynamically typed languages ... difference between static typing with a union-of-all-types-type ...
    (comp.lang.lisp)
  • Re: bug in visual studio .net 2003 - breakpoints and memcpy
    ... No other conversion can be performed explicitly ... does the C standard say the same?). ... > So neither reinterpret_cast nor the explicit cast notation can be ... >> cast works it works. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: FindFirst Method
    ... Whether intCompNum is declared as a Variant or as an Integer is irrelevant to this. ... There is no real need to use CStr() anyway. ... If VB didn't do implicit type conversions, one would have to make an explicit conversion such as seen above using CStr. ...
    (microsoft.public.access.modulesdaovba)