 |
 |

11-27-2005, 12:23 PM
|
|
Newcomer
|
|
Join Date: Nov 2005
Posts: 10
|
|
simple objects
|
Hi!
I've been looking for some basic examples of how to create some simple objects in my code. If anyone have some good links, please post them.
I'm thinking on real basic stuff, similar to code below, which is obviously not correct.
Code:
Public Sub setData()
With setData
.a = 43
.b = 30
End With
End Sub
Private Sub RandomEntry_Click()
Dim test1 As New setData
Dim test2 As Object
With test2
.x = 5
.y = 6
End With
Print test1.a, test2.y
End Sub
Feel free to post any comments!
Thanks!
|
|

11-27-2005, 12:30 PM
|
 |
Contributor
|
|
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 601
|
|
u mean a type structure like this?
Code:
Private Type data
A As Long
B As Long
End Type
Private Sub Form_Load()
Dim D As data
With D
.A = 43
.B = 30
Debug.Print .A; .B
End With
End Sub
|
|

11-27-2005, 12:41 PM
|
|
Newcomer
|
|
Join Date: Nov 2005
Posts: 10
|
|
|
Thanks!
yes, that looks interesting, allthough I get an error on it, "Method or data member not found" highligthing ".A".
Is "Type" considered an object? Or are there some other ways to do this without "Type"?
Can I also use arrays of Type's, and arrays as Type data member?
|
|

11-27-2005, 01:00 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
No, a Type is a structure. You create an Object from a Class.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

11-27-2005, 01:02 PM
|
 |
Contributor
|
|
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 601
|
|
nope a type structure is not a object...
yes u can make a array of a type structure
Code:
Private Type data
A As Long
B As Long
End Type
Private Sub Form_Load()
Dim D(0 To 9) As data
Dim i As Integer
For i = 0 To UBound(D)
With D(i)
.A = i
.B = i * 10
Debug.Print .A; .B
End With
Next
End Sub
|
|

11-27-2005, 02:03 PM
|
|
Newcomer
|
|
Join Date: Nov 2005
Posts: 10
|
|
|
Great! thanks for the examples!
Maybe I'm just looking for objects by class. Is it possible to use classes like you do in c or java?
|
|

11-27-2005, 02:06 PM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
|
Not exactly like c or java, but yes vb has classes.
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

11-27-2005, 04:42 PM
|
|
Newcomer
|
|
Join Date: Nov 2005
Posts: 10
|
|
|
Are the basic coding of classes different from VB to VB.NET?
|
|

11-28-2005, 08:05 AM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

11-28-2005, 02:21 PM
|
 |
Unashamed geek
Retired Moderator * Expert *
|
|
Join Date: Jul 2003
Location: London, England
Posts: 8,988
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|