[VB.NET] Arrays

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I am doing a little VB.NET and was wondering how i can make an array and not set the size and then use a loop to keep adding things too it.

Thanks.
 
As said if you do not know the size then you will be better of with an ArrayList as you can just keep adding to it.

TrUz
 
Thanks.

Couple of quick questions:

How do you do a newline in VB.NET and how do you escape a quote in a string so i can have:

Code:
string = "this great string is "stringy" isn't it"

Thanks.
 
Like this

Code:
string = "this great string is ""stringy"" isn't it"

And for newline you have a choice:

Code:
Microsoft.VisualBasic.

  ControlChars.Cr [Char]
  ControlChars.Lf [Char]
  ControlChars.CrLf [String]

  Constants.vbCr [String]
  Constants.vbLf [String]
  Constants.vbCrLf [String]

  Chr(13) [Char]
  Chr(10) [Char]

System.

  Environment.NewLine [String]

System.Windows.Forms.

  Keys.Return.ToString (String)
  Keys.LineFeed.ToString (String)
  Chr(Keys.Return) (Char)
  Chr(Keys.LineFeed) (Char)
 
Of the above, Environment.NewLine is probably the best choice; it means that your code will be more easily portable, and run on other platforms properly without too much hassle (although the only other platform for C# at the moment is Mono :p). It doesn't matter all that much though, as you're unlikely to want to run a .NET application outside Windows, so platform independence in such a minor issue isn't that important.
 
Thanks.

In vb6 you can set 4 variables the same value by this:

Code:
a, b, c, d = 1

But how would i do this in VB.NET. Is it possible without using 4 different lines.

Thanks.
 
Conrad11 said:
Thanks.

In vb6 you can set 4 variables the same value by this:

Code:
a, b, c, d = 1

But how would i do this in VB.NET. Is it possible without using 4 different lines.

Thanks.

Code:
a = b = c = d = 1

That's typical of virtually every programming language, I would presume it's the same in VB.NET.
 
Conrad11 said:
Thanks for the reply, but it doesn't appear to work.

:eek:

what is the assignment operator in VB?????


is it pascalish := ?

or perpaps the assignment a = 2 doesn't evaluate to int 2 and evaluates to true or something odd??

&vbnewline& is the new line operator iirc from a similar thread the other day

Paul
 
I think you have to use four lines of code to do this in VB.NET

You can't do a = b = c = d = 1 because = is used as both the assignment and comparison operator in VB.NET so in the above usage the compiler gets a bit confused.

So, a = b = c is actually evaluated as a = (b = c) where b = c is a boolean that is true or false depending on whether b or c are the same.
 
Haircut said:
I think you have to use four lines of code to do this in VB.NET

You can't do a = b = c = d = 1 because = is used as both the assignment and comparison operator in VB.NET so in the above usage the compiler gets a bit confused.

So, a = b = c is actually evaluated as a = (b = c) where b = c is a boolean that is true or false depending on whether b or c are the same.



so in VB.net a = is the same as an == and an = at the same time :eek:

everytime I hear stuff about this language it gets worse and worse

HT
 
happytechie said:
so in VB.net a = is the same as an == and an = at the same time :eek:

everytime I hear stuff about this language it gets worse and worse

HT
Yep, there is no == in VB.

You would simply use something like
Code:
If Variable = Value Then

What's even better is that logical ANDs and ORs use the same keyword as bitwise ANDs and ORs.
 
When you declare multiple values in a single line, you can’t specify default values as you can in C#. However, Visual Basic .NET does allow you to do something you can’t in C#—declare multiple variables of different types in a single line.

Dim Bottom As Integer, FieldName As String

Seems us C#ers are really missing out on that one :(........
 
Inquisitor said:
List > ArrayList :)

List = LinkedList?

It depends what operations you are performing on the list, and for example where abouts you are doing your insertions/deletions.
 
Back
Top Bottom