473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Working with structures and the New keyword

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 ***
Jan 17 '06 #1
4 1249
"Terry Olsen" <to******@hotmail.com> schrieb:
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 lines are semantically equivalent. It's up to personal preference to
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/>

Jan 17 '06 #2
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).

--
Patrice

"Terry Olsen" <to******@hotmail.com> a écrit dans le message de
news:uI**************@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 ***

Jan 17 '06 #3
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

Jan 17 '06 #4
"Chris Dunaway" <du******@gmail.com> schrieb:
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


It's not supported to declare a parameterless non-shared constructor for a
structure type.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: faktujaa | last post by:
Hi All, Microsoft says that structures are value types. Also primitive data types are value types. And memory for value types is allocated on the stack. Then why we need new operator to allocate...
6
by: nick | last post by:
I have tried finding an answer to this, but most people just explain classes as a more modular way to program. It seems to me that (forgetting OO programming which I don't quite understand) the...
4
by: Animesh | last post by:
Hi All, I don't know whethher this is possible or not. This is the result of a bad design problem. Here I go; I have a structure like this: typedef struct _s_index_entry { char *doc_id;...
3
by: mosscliffe | last post by:
Newbie struggling with VB.NET I wish to create an arraylist of structures. I am very new to this coding syntax, so bear with my poor syntax - please struct mystruct Fld1 as short Fld2 as...
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
0
by: Kaushik C P | last post by:
Can you tell me , why this code does not run: <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AJAX6.aspx.cs" Inherits="Experiments_AJAX_AJAX6"...
4
by: davidcollins001 | last post by:
Hi, I am trying to get more to grips with pointers in C so I am trying to make a program that reads a file, places the data in a struct then sorts it using qsort. I have just about got my head...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.