Click to See Complete Forum and Search --> : 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
Jason Bock
03-19-2000, 03:38 PM
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
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
>
>
Anthony Verna
03-20-2000, 02:26 PM
>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
devx.com
Copyright WebMediaBrands Inc. All Rights Reserved