VB6 Types

W

wg

I am sort of new to C# from VB6. Is there a similar function to the variable
Type found in VB6. There I created a Type then an array of that variable
that could be used. I could then dynamically alocate memory depending on the
number of variables needed.

For example

Type Tags
Dim Name as String
Dim Value as Float
Dim Enable as Bool
End Type

Dim iTags() as Tags

used as iTags(0).Name, etc...

Thanks

Wade Greene
 
S

Steve Walker

wg said:
I am sort of new to C# from VB6. Is there a similar function to the variable
Type found in VB6. There I created a Type then an array of that variable
that could be used. I could then dynamically alocate memory depending on the
number of variables needed.

For example

Type Tags
Dim Name as String
Dim Value as Float
Dim Enable as Bool
End Type

Hmm. Do I tell you what you want to know, or what you need to know? :blush:)

Yes, there is something in C# superficially similar to that, declared
like this:

struct Tags
{
public string Name;
public float Value;
public bool Enable;
}

However, a C# struct is closer to a VB6 class than to a VB6 type, and in
many cases it would be more appropriate to use a C# class. Incidentally,
I would also personally avoid using public fields as shown, I'd make
them private and expose them through properties as I would with a class.

I would advise doing some reading. Planning to handle arrays of structs
suggests to me that you are thinking of trying to write procedural-style
VB6 in C#. You can do that, but you won't really be making best use of
C#.
 
M

Moty Michaely

Define a class or struct.

Then define an array or any kind of list with the type of the class or
struct you defined.

Struct is the equivalent to Type in vb6.

I think you should check more about Object Oriented programming which for
vb6 programmers is hard to understand at first.

- Moty -
 
J

John B

Moty said:
Define a class or struct.

Then define an array or any kind of list with the type of the class or
struct you defined.

Struct is the equivalent to Type in vb6.

I think you should check more about Object Oriented programming which for
vb6 programmers is hard to understand at first.
Hey, I resemble that comment. :)
Yeah, coming from a "hack" of a oo language such as vb6, "proper" oo
concepts are a bit hard to understand.
Its bloody nice when it does click though and you realise the power at
your fingertips <insert evil laugh>.

JB :)
 
W

wg

Thanks to everyone for their help. I believe that I am using OO as much as
possible. This is an hardware interface program that has reference tags with
many properties that is loaded on startup. I have written serveral in VB6
and now stepping up to C#.

Thanks again,

wg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top