Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > simple objects


Reply
 
Thread Tools Display Modes
  #1  
Old 11-27-2005, 12:23 PM
bretthedog bretthedog is offline
Newcomer
 
Join Date: Nov 2005
Posts: 10
Default 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!
Reply With Quote
  #2  
Old 11-27-2005, 12:30 PM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 601
Default

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
Reply With Quote
  #3  
Old 11-27-2005, 12:41 PM
bretthedog bretthedog is offline
Newcomer
 
Join Date: Nov 2005
Posts: 10
Default

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?
Reply With Quote
  #4  
Old 11-27-2005, 01:00 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

No, a Type is a structure. You create an Object from a Class.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #5  
Old 11-27-2005, 01:02 PM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 601
Default

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
Reply With Quote
  #6  
Old 11-27-2005, 02:03 PM
bretthedog bretthedog is offline
Newcomer
 
Join Date: Nov 2005
Posts: 10
Default

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?
Reply With Quote
  #7  
Old 11-27-2005, 02:06 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Not exactly like c or java, but yes vb has classes.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #8  
Old 11-27-2005, 04:42 PM
bretthedog bretthedog is offline
Newcomer
 
Join Date: Nov 2005
Posts: 10
Default

Are the basic coding of classes different from VB to VB.NET?
Reply With Quote
  #9  
Old 11-28-2005, 08:05 AM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Very.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #10  
Old 11-28-2005, 02:21 PM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

My favourite tutorial about classes and objects in VB6 - excerpt from a book by Francisco Balena:
http://www.visualbasicbooks.com/progVB6samplepg1.html
Very understandable and very thorough.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->