DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: Initializers

  1. #1
    Lobo Guest

    Initializers

    I was thinking about the new "Initializers" feature and, although that's not
    an "incredible" thing, it can be useful sometimes. But, it would be really
    useful if it work with arrays like C++ does:

    int value[5] = {1, 2, 3} // Initializes the first 3 elements with the
    // corresponding values (1, 2, 3)
    and the
    // 2 remaining to zero.
    int value[100] = {7} // Initialize all elements to zero.

    Don't you think? It would free us from coding this way:

    Dim value(4) As Integer
    value(0) = 1
    value(1) = 2
    value(2) = 3
    value(3) = 0
    value(4) = 0

    Dim intInd As Integer
    Dim value(99) As Integer
    For intInd = 0 To 99
    value(intInd)=7
    Next intInd

    Wouldn't it be good?

    Lobo.
    Soon: VBFX - http://www.fatorx.com.br



  2. #2
    Jason Bock Guest

    Re: Initializers


    Lobo <lobo@fatorx.com.br> wrote in message news:38d512b5@news.devx.com...
    > I was thinking about the new "Initializers" feature and, although that's

    not
    > an "incredible" thing, it can be useful sometimes. But, it would be really
    > useful if it work with arrays like C++ does:
    >
    > int value[5] = {1, 2, 3} // Initializes the first 3 elements with

    the

    Yes, this would be a nice thing to have in VB7. My guess is they will add
    something like this, but that's purely a guess. Remember that's there also
    UDTs in the picture. Given:

    Type MyUDT
    SomeString As String
    SomeLong As Long
    SomeItf As Integer
    End Type

    it would be nice to see something like this:

    Dim udtNewType As MyUDT = {"New Value", 4, 5}

    It would be nice to have this for constants of a UDT type as well. We'll
    see what happens when the final version rolls out.

    Regards,

    Jason



  3. #3
    Lobo Guest

    Re: Initializers

    Sorry, I just wrote "bullshit"... That's because I'm a beginner in C/C++
    (very beginner...)... In fact, you can't associate a default number to a
    whole array like I said:

    int value[100] = {7}

    This statement just set the first element to 7 and all the rest to zero.
    That's because I saw an example setting zero, what caused the setting of all
    the rest of elements to zero... This is useful to C/C++ 'cause the initial
    values of variables are just "trash" from the memory. But this isn't useful
    in VB, since VB manages all this service of cleaning up the variables'
    values... Isn't that right? Well, but I think you've caught the idea...

    Lobo.
    Soon: VBFX - http://www.fatorx.com.br



    Lobo <lobo@fatorx.com.br> wrote in message news:38d512b5@news.devx.com...
    > I was thinking about the new "Initializers" feature and, although that's

    not
    > an "incredible" thing, it can be useful sometimes. But, it would be really
    > useful if it work with arrays like C++ does:
    >
    > int value[5] = {1, 2, 3} // Initializes the first 3 elements with

    the
    > // corresponding values (1, 2,

    3)
    > and the
    > // 2 remaining to zero.
    > int value[100] = {7} // Initialize all elements to zero.
    >
    > Don't you think? It would free us from coding this way:
    >
    > Dim value(4) As Integer
    > value(0) = 1
    > value(1) = 2
    > value(2) = 3
    > value(3) = 0
    > value(4) = 0
    >
    > Dim intInd As Integer
    > Dim value(99) As Integer
    > For intInd = 0 To 99
    > value(intInd)=7
    > Next intInd
    >
    > Wouldn't it be good?
    >
    > Lobo.
    > Soon: VBFX - http://www.fatorx.com.br
    >
    >




  4. #4
    Anthony Verna Guest

    Re: Initializers


    >values of variables are just "trash" from the memory. But this >isn't useful
    >in VB, since VB manages all this service of cleaning up the >variables'
    >values... Isn't that right? Well, but I think you've caught the idea...
    >
    >Lobo.


    Vous avez raison!
    But - it is useful so we don't have to always assign every single element
    of an array when programming in C/C++.

    -Anthony


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links