|
-
Dec 13th, 2004, 03:11 PM
#1
Thread Starter
Fanatic Member
Structures?
Hi,
are there structures in VB?how can i create one if it is availbale?i need to have 2 integer varaible and a string variable inside a structure.......and create a structure array....is it possible?
Thanks and Regards
vivek.s
Last edited by vivek.shankar; Dec 13th, 2004 at 03:17 PM.
-
Dec 13th, 2004, 03:14 PM
#2
Banned
Re: Structures?
Type NAME_OF_TYPE
int1 as integer
int2 as integer
str1 as string
End Type
array(6, 6, 6) as NAME_OF_TYPE
-
Dec 13th, 2004, 03:17 PM
#3
Thread Starter
Fanatic Member
Re: Structures?
Thanks a lot!
Regards
vivek.s
-
Dec 13th, 2004, 05:31 PM
#4
Re: Structures?
Before you get too far into your program consider if you'll need to pass the structure to a Sub or Function. If the answer is yes then you'll need to use a class instead.
-
Dec 13th, 2004, 05:34 PM
#5
Fanatic Member
Re: Structures?
 Originally Posted by MartinLiss
Before you get too far into your program consider if you'll need to pass the structure to a Sub or Function. If the answer is yes then you'll need to use a class instead.
Why? There is no reason why you can't pass a user defined type to a sub or function!?
-
Dec 13th, 2004, 05:53 PM
#6
The picture isn't missing
Re: Structures?
 Originally Posted by Blade
Why? There is no reason why you can't pass a user defined type to a sub or function!?
I forgot the technical reason, but you get an error if you try.
Compile error:
Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types
You just can't. Although it IS possible to convert it to bytes, send to bytes to the sub/function, then convert it back to a UDT.
Or just use a class, which is easier if you use the Class Builder add-in. (look into your add-in's for that).
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Dec 13th, 2004, 06:04 PM
#7
Frenzied Member
Re: Structures?
Try it - sadly you get a compile error. You will probably be as dissapointed as I was when I found that out.
The quick and dirty get around is to define your type as public in a module making it global n scope. That gets messy when you have a few of them dotted around though
The slicker get around is as Marty says, use a class. It's not as messy as you would think. Consider this code example. Throwing a few public variables into a class eg ..
Option Explicit
Code:
Option Explicit
GRID 1 VARIABLES
' This is the grid is the main descriptor grid.
Public Assessment As Long
Public AssCalculated As Long the descriptors
Public Subject As String
Public YG As String
Public UPN As String
Public Forename As String
Public Surname As String
Public aAssessInfo As Variant
and because variables declared as Public in a class are visable at the interface, you have your portable type. But now BECAUSE it is in a class you can do all of the other wizzy class things. You can addd subs and functions. So all of a sudden you type is on setroids.
I personaly found that my class Type quickly became the container for all of the variables I needed in one code area. This ringfenced my code and made it very portable.
There was one downside though. You can't use this approach to expose Arrays directly. You have to get at them though methods. So it is a type replacement but not an exact replacememt.
HTH
.
-
Dec 13th, 2004, 07:00 PM
#8
Thread Starter
Fanatic Member
Re: Structures?
oops i was doin it the messy way........i declared a global structure and since i am using only 2 functions i used that......maybe i shud condier using class.....but unfortunatley i havnt dwelled into object oriented features of VB.......
regards
vivek.s
-
Dec 13th, 2004, 07:20 PM
#9
Frenzied Member
Re: Structures?
It all depends on how far you want to take your coding. For me object oriented programming is nervanah. I don't think I will ever have the luxury of getting there. I program, small to medium apps for myself and have no need to share modules. Hence true OO is not my personal goal.
I have recently found classes to be a great way of
1. Containing local code variables / routines (as above)
2. Wrapping groups of similar soubroutines and functions.
3. Holding all of the business logic and providing a wrapper for a database.
In non of these cases was I codeing pure OO. I always have the odd variable that I have wandering about globally, but the code structure reflects how I think and so it is easy for me to maintain.
In short, Classes allow me to pidgeonhole code.
In terms of portability, within code I can drag and drop classes between projects. That is good enough for me.
If you want to know more from a class nebies perspective (which is definitely me) post again or ping me direct. Good luck
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|