Home All Groups Group Topic Archive Search About

Got to be an easier way...

Author
28 Mar 2005 5:47 PM
Wardeaux
Hey all,
   struggling to find an easier way to initialize an array of structures...
Structure room
   Public Description as string
   Public Refridge() as string
   Public WeaponsVault() as string
end structure

Dim MyApt() as Room

I'd like to find a way similar to init an array of strings like:
Dim MyString() as String = {"str1","str2"}

Any assist is helpful...
wardeaux

Author
28 Mar 2005 6:20 PM
José Joye
Hi,

Not too sure I undertood what you are looking for....

Here are my 2 Swiss cents ;-)

  Structure room
    Public Description As String
    Public Refridge() As String
    Public WeaponsVault() As String
    Public Sub New(ByVal description As String, ByVal refridge() As String,
ByVal weaponsVault() As String)
      Me.Description = description
      Me.Refridge = refridge
      Me.WeaponsVault = weaponsVault
    End Sub
  End Structure

  Dim MyApt As New room("BlahBlah", New String() {"1", "2"}, New String()
{"3", "4"})


- José


"Wardeaux" <warde***@bellsouth.net> a écrit dans le message de news:
%23rFdx37MFHA.3***@TK2MSFTNGP12.phx.gbl...
Show quoteHide quote
> Hey all,
>   struggling to find an easier way to initialize an array of structures...
> Structure room
>   Public Description as string
>   Public Refridge() as string
>   Public WeaponsVault() as string
> end structure
>
> Dim MyApt() as Room
>
> I'd like to find a way similar to init an array of strings like:
> Dim MyString() as String = {"str1","str2"}
>
> Any assist is helpful...
> wardeaux
>
>
Author
28 Mar 2005 8:41 PM
Herfried K. Wagner [MVP]
"Wardeaux" <warde***@bellsouth.net> schrieb:
>   struggling to find an easier way to initialize an array of structures...
> Structure room
>   Public Description as string
>   Public Refridge() as string
>   Public WeaponsVault() as string
> end structure
>
> Dim MyApt() as Room
>
> I'd like to find a way similar to init an array of strings like:
> Dim MyString() as String = {"str1","str2"}

\\\
Dim MyApt() As Room = {New Room(), New Room()}
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
2 Apr 2005 10:43 AM
Rob Nicholson
> I'd like to find a way similar to init an array of strings like:
> Dim MyString() as String = {"str1","str2"}

I don't tend to use Structure in VB.NET but they are pretty similar to
classes so I'd use something like this:

Module Module1

    Sub Main()
        Dim Rooms() As Room = _
            { _
            New Room("Lounge", "Yes", "No"), _
            New Room("Kitchen", "Bilko", "Womble") _
            }
        For Each Room As Room In Rooms
            Console.WriteLine(Room.Description)
        Next

    End Sub

End Module

Public Class Room

    Public Description As String
    Public Refridge As String
    Public WeaponsDefault As String

    Sub New(ByVal Description As String, ByVal Refridge As String, ByVal
WeaponsDefault As String)
        Me.Description = Description
        Me.Refridge = Refridge
        Me.WeaponsDefault = WeaponsDefault
    End Sub

End Class