|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Working with structures and the New keywordWhat is the proper way to initialize a variable as a structure? It
seems to work for me either way, using the New keyword or not. Private Structure FLASHWINFO Dim cbSize As Int32 Dim hwnd As Int32 Dim dwFlags As Int32 Dim uCount As Int32 Dim dwTimeout As Int32 End Structure Dim FI As FLASHWINFO --OR-- Dim FI As New FLASHWINFO Both seem to work fine. *** Sent via Developersdex http://www.developersdex.com ***
Show quote
Hide quote
"Terry Olsen" <tolse***@hotmail.com> schrieb: Both lines are semantically equivalent. It's up to personal preference to > What is the proper way to initialize a variable as a structure? It > seems to work for me either way, using the New keyword or not. > > Private Structure FLASHWINFO > Dim cbSize As Int32 > Dim hwnd As Int32 > Dim dwFlags As Int32 > Dim uCount As Int32 > Dim dwTimeout As Int32 > End Structure > > Dim FI As FLASHWINFO > --OR-- > Dim FI As New FLASHWINFO prefer one of the methods over the other. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> If the structure actually defines a constructor, do you have to call
it? e. g. : Private Structure FLASHWINFO Dim cbSize As Int32 Dim hwnd As Int32 Dim dwFlags As Int32 Dim uCount As Int32 Dim dwTimeout As Int32 Public Sub New() 'some code here End Sub End Structure Does this still work and does it call the constructor? Dim fwi As FLASHWINFO
Show quote
Hide quote
"Chris Dunaway" <dunaw***@gmail.com> schrieb: It's not supported to declare a parameterless non-shared constructor for a > If the structure actually defines a constructor, do you have to call > it? e. g. : > > Private Structure FLASHWINFO > Dim cbSize As Int32 > Dim hwnd As Int32 > Dim dwFlags As Int32 > Dim uCount As Int32 > Dim dwTimeout As Int32 > > Public Sub New() > 'some code here > End Sub > End Structure > > Does this still work and does it call the constructor? > > Dim fwi As FLASHWINFO structure type. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> A structure is always allocated so using new or rather a matter of personal
preference (though it would be interesting to see if new erases the previous members). -- Show quoteHide quotePatrice "Terry Olsen" <tolse***@hotmail.com> a écrit dans le message de news:uI82Iv4GGHA.1192@TK2MSFTNGP11.phx.gbl... > What is the proper way to initialize a variable as a structure? It > seems to work for me either way, using the New keyword or not. > > Private Structure FLASHWINFO > Dim cbSize As Int32 > Dim hwnd As Int32 > Dim dwFlags As Int32 > Dim uCount As Int32 > Dim dwTimeout As Int32 > End Structure > > Dim FI As FLASHWINFO > --OR-- > Dim FI As New FLASHWINFO > > Both seem to work fine. > > *** Sent via Developersdex http://www.developersdex.com ***
Problem with SHAppBarMessage
How to create a "DataSource" & "Items" properties on Custom Combob The Irish fada (áéíóú/ÁÉÍÓÚ) and encryption/decryption problem! Binding sources question in Vs2005 Encyrption in VB and Decryption in VB.NET Detect Remote Shutdown Alignment problem displaying .txt file in window's textbox? Impersonation without credentials ? DataTable.Expression New to XML |
|||||||||||||||||||||||