As you've guessed, there's no compile-time ability to get the length of a
string (or to execute any member of any const at compile-time).

ReadOnly members are the way to get around this problem.  For example:

   Public Shared ReadOnly c1FullAddr As String = "1 Colonial Drive  Parma
Ohio 21321"
   Public Shared ReadOnly c1FaLen As Integer = Program.c1FullAddr.Length

Personally, I think simply using c1FullAddr.Length instead of c1FaLen is
much more clear.  Moving code from one language to another often involves
much more than translation; it often means re-writing the code to fit the
paradigm and colloquialisms of the destination language.

 On Wed, 6 Aug 2008 12:08:16 -0500, Greg Rothlander <[EMAIL PROTECTED]>
wrote:

>I'm moving some code from an old language and rewriting it in .Net.  I
have
>come across an odd situation where I will have to go in and rework a great
>deal of code and I'm looking for a less complex and time consuming
solution.
>Here's the basic idea...
>
>In the old language they are using a string constant such as:
>
>        Const c1FullAddr as String = "1 Colonial Drive  Parma  Ohio 21321"
>
>Then they follow that up with another constant:
>
>        Const   c1FaLen as String = c2FullAddr.length
>
>In VB.Net you cannot do this.  Is there a way to do this without having to
>count the length of c1FullAddr and hard coding the value or without
changing
>it from a constant?  I can ceratianly go through and count the lengths and
>hardcode the values, or I could do through and change all of the "const"
to
>"dim" and it would work, but it would like to keep it as a constant in the
>new version as well, if I can.
>
>Of course the most obvious solution would be to simply make it a string
>variable and not a string constant.  I will do that if I need to, but I
>thought there might be a trick here to get this to work as a constant,
but I
>certainly cannot see any way to make it work as a constant.
>
>I think the real issue here is that if it is defined at runtime and not
>design time, then it's not really a constant.  So maybe there is no way to
>do this in VB.Net, as a constant and just simply changing it to a string
>variable is the correct approach.
>
>Any thoughts or suggestions would be very much appreciated.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to