Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,252 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,222 people online right now. Registration is fast and FREE... Join Now!




How to create autonumber?

 
Reply to this topicStart new topic

How to create autonumber?, in VB

sam_wong
14 Oct, 2008 - 04:02 AM
Post #1

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 5

i'm having trouble generating the autonumber for the list box.
once i click the button all the number will shows in the list box.i just wan a number showing once at a time but not the whole list of number.can anyone help?

CODE
Private Sub AutoNumber()
        Dim iMax As Integer = 100
        Const sChar As String = "PO"
        Dim iCounter As Integer


        For iCounter = 0 To iMax
            lstOrderID.Items.Add(sChar & iCounter)

        Next iCounter
        iCounter = iCounter + 1

    End Sub

*Appreciate your help*
User is offlineProfile CardPM
+Quote Post

Reverand Dave
RE: How To Create Autonumber?
14 Oct, 2008 - 04:29 AM
Post #2

D.I.C Regular
Group Icon

Joined: 27 Jul, 2008
Posts: 373



Thanked: 2 times
Dream Kudos: 50
My Contributions
You need to have the iCounter = iCounter + 1 part inside the loop otherwise it won't increment while the loop is running
User is offlineProfile CardPM
+Quote Post

thava
RE: How To Create Autonumber?
14 Oct, 2008 - 06:29 AM
Post #3

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 442



Thanked: 18 times
Dream Kudos: 50
My Contributions
QUOTE(sam_wong @ 14 Oct, 2008 - 05:02 AM) *

i'm having trouble generating the autonumber for the list box.
once i click the button all the number will shows in the list box.i just wan a number showing once at a time but not the whole list of number.can anyone help?

CODE
Private Sub AutoNumber()
        Dim iMax As Integer = 100
        Const sChar As String = "PO"
        Dim iCounter As Integer


        For iCounter = 0 To iMax
            lstOrderID.Items.Add(sChar & iCounter)

        Next iCounter
        iCounter = iCounter + 1

    End Sub

*Appreciate your help*


i think yoi want to add the number one by one ok lets check this

declare the icounter at form level (i.e) declare in the general section
in the button click add the coding
vb

if iCounter<=imax then
lstOrderID.Items.Add(sChar & iCounter)
endif

when you click the button the list will add one by one

This post has been edited by thava: 14 Oct, 2008 - 06:31 AM
User is offlineProfile CardPM
+Quote Post

sam_wong
RE: How To Create Autonumber?
14 Oct, 2008 - 10:16 AM
Post #4

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 5

im sorry..i dont get wat u mean...

This post has been edited by sam_wong: 14 Oct, 2008 - 10:17 AM
User is offlineProfile CardPM
+Quote Post

thava
RE: How To Create Autonumber?
14 Oct, 2008 - 06:58 PM
Post #5

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 442



Thanked: 18 times
Dream Kudos: 50
My Contributions
did you want to add the counter variable one by one is it
then
declare the iCounter at the start of the form coding and follow my previous post

or not then you want to show only one item at a time if yes
shrink the listbox for your need

QUOTE

when you post a question make clear what is your need and what is your problem

User is offlineProfile CardPM
+Quote Post

sam_wong
RE: How To Create Autonumber?
15 Oct, 2008 - 08:27 AM
Post #6

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 5

i got it now...thanks for your help....
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:17AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month