.Net Arrays

  • 14 years ago

    In VB6, for a program I made, I used the following code:

    Dim varNames() As Variant
    Dim intIndex As Integer
    Dim strName As String

    varNames() = Array("Beast", "Minotaur", "Skeleton")
    Call Randomize
    Let intIndex = Int(Rnd() * (UBound(varNames) + 1))
    Let strName = varNames(intIndex)

    Let Label1.Caption = strName








    ===

    What this did was randomly get a name from the array (Beast, Minotaur, or Skeleton) and display it in a label.

    I'd like to use this code again in NET 2005, so I was wondering how do I rewrite this code to make it work in NET?

  • 14 years ago

    You could use almost the same code, but you shouldn't.

    Dim names As String() = {"Beast", "Minotaur", "Skeleton"}
    Dim randomiser As New Random
    Dim index As Integer = randomiser.Next(0, names.Length)
    Dim name As String = names(index)

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic