How to write short than?

  • Thread starter Thread starter HM
  • Start date Start date
H

HM

Hello your guy,
I am new coding with VB so please help. Here is my code:
s1 = 0
s2 = 0
s3 = 0
s4 = 0

I want to store 0 to s1 ,s2,s3,s4,and many more.
How can I write in VB with short command?
Best Regards,
HM
 
HM said:
Hello your guy,
I am new coding with VB so please help. Here is my code:
s1 = 0
s2 = 0
s3 = 0
s4 = 0

I want to store 0 to s1 ,s2,s3,s4,and many more.
How can I write in VB with short command?
Best Regards,
HM

As long as s1, s2, etc., are all separate variables, there is no shorter
way. However, you could use an array "s" of four elements, and set the
value of each element using a loop. For example:

Dim s(3) As Integer
Dim i As Integer

For i = 0 To 3
s(i) = 0
Next i

If you want your array to use subscripts 1 to 4, rather than 0 to 3, you
have to declare it like this:

Dim s(1 To 4) As Integer

Then you could write

For i = 1 To 4
 
I am new coding with VB so please help. Here is my code:Dim s1, s2, s3, s4 as long

Now each variable is iniatised to 0

Regards,
Steve
 
Stephen Reilly said:
Dim s1, s2, s3, s4 as long

Now each variable is iniatised to 0

Actually, no. That line declares only s4 as Long; the others are all
implicitly declared as Variant. Further, while it's true that, if you
do declare each as Long, they will automatically have initial values of
0, that doesn't solve the general problem of setting them all to some
other value.
 
Back
Top