AuthorMessage
Meka][Meka
Unstopable
Posts: 700

note: you may use this tutorial on other sites as long as u post the author note.
--------------------------
Understanding Classes
--------------------------
Author: Meka][Meka
--------------------------
http://www.meka-meka.com/
--------------------------
   Ok start a new project, then create an empty class, on the left u have your com,.net components, think of them as a class, only with a usercontrol combined, your application is also a class. Ok lets get started, first we need our class code.
Open the class and paste this code
Code:

   Public Class UserData
      Public sName, sDesc, sTag As String
   End Class

close and save the class, we need a function to use to pass it forward for example, view form code and paste:
Code:

   Private Sub Boxit(ByVal user As UserData)
      MsgBox(user.sName & " - " & user.sDesc)
      MsgBox(user.sTag)
   End Sub

now we need to create an instance of the class,
Code:

   Dim user As New UserData

we need now to give it some data, in form load paste
Code:

   Dim user As New UserData
        With user
            .sName = "Meka][Meka"
            .sDesc = "http://www.meka-meka.com/"
            .sTag = "some misc data here"
        End With

then we need to pass it to the function
Code:
       
Boxit(user)

Code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim user As New UserData
        With user
            .sName = "Meka][Meka"
            .sDesc = "http://www.meka-meka.com/"
            .sTag = "some misc data here"
        End With
        Boxit(user)
    End Sub

now run your application and see your class work ;)
C0D3Z3R0
Pro
Posts: 166

The tutorial is useful but it's confusing me as well... heres my code, everything I paste shows as error.
Form1.vb
Code:
Dim user As New UserData
        With user
            .sName = "Meka][Meka"
            .sDesc = "http://www.meka-meka.com/"
            .sTag = "some misc data here"
        End With
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim user As New UserData
    With user
        .sName = "Meka][Meka"
        .sDesc = "http://www.meka-meka.com/"
        .sTag = "some misc data here"
    End With
    Boxit(user)
End Sub

Class1.vb:
Code:
    Public Class UserData
        Public sName, sDesc, sTag As String
    End Class

hope you can help fix this
Meka][Meka
Unstopable
Posts: 700

well this tut is for ametuars at VB7, by looks of it, u dont know much of vb6 neither, y u have the user item outside the function, i state in the tutorial
'we need now to give it some data, in form load paste'
Code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim user As New UserData
    With user
        .sName = "Meka][Meka"
        .sDesc = "http://www.meka-meka.com/"
        .sTag = "some misc data here"
    End With
    Boxit(user)
End Sub

-/Meka][Meka
C0D3Z3R0
Pro
Posts: 166

i'll forget trying to learn this, i'll stick to learning vb6 for now ;)
Meka][Meka
Unstopable
Posts: 700

Quoted from C0D3Z3R0
i'll forget trying to learn this, i'll stick to learning vb6 for now ;)

learning vb6 is the same problem, ther is still same things like this, only this is the more advanced of it, dont bother with vb6 if u wanna come to vb7, come straight to vb7, ther is not much difference
code should be like this:
class1.vb
Code:

   Public Class UserData
      Public sName, sDesc, sTag As String
   End Class

Form1:
Code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim user As New UserData
        With user
            .sName = "Meka][Meka"
            .sDesc = "http://www.meka-meka.com/"
            .sTag = "some misc data here"
        End With
        Boxit(user)
    End Sub
   Private Sub Boxit(ByVal user As UserData)
      MsgBox(user.sName & " - " & user.sDesc)
      MsgBox(user.sTag)
   End Sub

-/Meka][Meka
MethodZ
n00b
Posts: 12

i do it like this?:
 
Quote:
Public Class Class1
    Public sName, sDesc, sTag As String
End Class

cause i was getting the error with UserData lol.. im super newbie okay  :roll:  ...
but i think this is it.. but i get:
 
Quote:
vbc : error BC30420: 'Sub Main' was not found in 'class1'.

more then likely... im just retarded and it's something simple that i have no idea of..  :?
Meka][Meka
Unstopable
Posts: 700

when u create your class, by that error u have changed startup item, goto project settings, and select form 1 class as your startup item ;)