how we create a function/method in vb.net??
if i want to make a method of auto_generate_id,
then how will i start?
i have written this code please help me.....

void auto_generate_id()
 
   Dim j As Integer = 0
        Dim cmd As New SqlCommand("select staffid from  staff order by staffid", c.con)
        Dim dr As SqlDataReader()
            dr=cmd.executereader()
            while(dr.read())
            txtstaff_id.text=dr("staffid").tostring()
          end while
          j=converttoint32(txtstaff_id.text.to string())
            j=j+1
            txtstaff_id.text=j.to string()
            dr.close()
            c.con.close()

           end sub

please help me........

You want to use this function in all the forms? or in just one form?
If all Create function in Module with Public member
like

Public Function auto_generate_id() as Integer
' After your code retrnuj the value
Return J

End function

What exactly is the problem with your codes and
How do you want to access the auto generated numbers?

What exactly is the problem with your codes and
How do you want to access the auto generated numbers?

i am asking about functions not about auto_generate_id()
it may be blank or other function.

i told how to create function in VB.net in my previous post. whats ur exact problem?

You want to use this function in all the forms? or in just one form?
If all Create function in Module with Public member
like

Public Function auto_generate_id() as Integer
' After your code retrnuj the value
Return J

End function

It's not working.

Whats not working? Whats your complete code? from where you want to access this function? give details...

i am asking about functions not about auto_generate_id()
it may be blank or other function.

You have not explicitly stated what you want. From your codes, you're retrieving the staff_id in the database and incrementing to make another id. That's good and most vb6.0 developers do that but what if there is no current record. That's why you need to create a random class that would generate ID's independently.

So from this, do you want to learn how to create a function or you want to learn how to generate auto_id that works?

We create a function or method in VB using the following:

Sintax for a method:

Sub Methodname
'
' Place your method here
'
End Sub

Sintax for a function:

Function FunctionName as TypeOfReturnValue
'
' Place here your function
'
Return TheValueToReturn
End Function

Please read here (and next chapters) to learn howto.

Hope this helps

You have not explicitly stated what you want. From your codes, you're retrieving the staff_id in the database and incrementing to make another id. That's good and most vb6.0 developers do that but what if there is no current record. That's why you need to create a random class that would generate ID's independently.

So from this, do you want to learn how to create a function or you want to learn how to generate auto_id that works?

Thanx, it's working

Synthax for a method:

Sub Methodname
'
' Place your method here
'
End Sub

...

lolafuertes, in your previous post, you mentioned "Sub Methodname".
Being a hobbyist programmer, I really have no use to learn all those fancy words, I just learn what I need to learn. Since I just recently somewhat got a clearer understanding of what a "Method" is(reading a reply by adatapost), your post threw me off.

I always thought a Sub was a "Sub" and a Function was a "Function", and of course, just somewhat learned that "Method" was everything following the dot.
Example: Me.Text = "test" .Text being the Method.

If no problem for either you or anyone else, do clarify this; and no, not busting chops, just trying to move on to the next thing without confusion.
Thanx.

Member Avatar for Unhnd_Exception

A Method is a category. A method is a sub or function. There are four main categories. Field, Property, Method, Event.

For any class, it can be broken down to the following.

Fields - all your global variables
Methods - all your subs and functions
Properties - all your properties
Events - any events you create

Me.Text would fall under Properties which is a combination of a sub and a function.
The Set part is a sub. The Get part is a function.

commented: interesting; thanx for the provided info and not giving you a + rep. "just because", that's for the - rep..:D +10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.