Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Increment 5 Digits Number


Hello, I need help here. What I'm trying to do:

1) to has a function that will generate a unique 5 digits number that will increase everytime I call the function. I want to use it as slip number. It start from 00000 to 99999. If it more than 99999 then it will be reset to 00000.

2)this function will search in the table whether the number generated already existed or not, if yes it will increment the number if no then it will assign the number to the txtfields(1).

Below is my code but it doesn't work well.

code:
________________________________________________


Private Function tranNo()
Static code1 As Double
start:
txtFields(1).Text = Format(code1, "00000")
txtFields(1).Refresh
If code1 < 99999 Then

If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do Until Adodc1.Recordset.EOF
If Adodc1.Recordset("tranNo") = code1 Then
code1 = code1 + 1
GoTo start:
Else
Adodc1.Recordset.MoveNext
End If
Loop

End If

Else
code1 = 0

End If


End Function

___________________________________________________

In summary, this number like an autonumber. Can anyone help me to correct the code, or suggest another way to do it? Help me please!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Number Gen With Different Digits
I am working on a program where the user can pick how many digits and it will generate txtNumber.text amout of a certain digit. Here is the code:


VB Code:
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub cmdClear_Click()List1.ClearEnd Sub Private Sub cmdExit_Click()Unload MeEnd Sub Private Sub cmdGenerate_Click()Combo1.Enabled = FalsetxtNumber.Enabled = FalseProgressBar1.Max = txtNumber.TextProgressBar1.Value = 0lblStatus.Caption = "0/" + txtNumber.Text If Combo1.Text = 5 ThenFor x = 1 To txtNumber.Text'blahtempnumber = Int((99999 - 10000 + 1) * Rnd + 10000)List1.AddItem (tempnumber)Me.RefreshProgressBar1.Value = ProgressBar1.Value + 1tempr = ProgressBar1.ValuelblStatus.Caption = ProgressBar1.Value + "/" + txtNumber.TextSleep (50)NextEnd If If Combo1.Text = 6 ThenFor x = 1 To txtNumber.Text'blahtempnumber = Int((999999 - 100000 + 1) * Rnd + 100000)List1.AddItem (tempnumber)Me.RefreshProgressBar1.Value = ProgressBar1.Value + 1lblStatus.Caption = ProgressBar1.Value + "/" + txtNumber.TextProgressBar1.Value = ProgressBar1.Value + 1Sleep (50)NextEnd If If Combo1.Text = 7 ThenFor x = 1 To txtNumber.Text'blahtempnumber = Int((9999999 - 1000000 + 1) * Rnd + 1000000)List1.AddItem (tempnumber)Me.RefreshProgressBar1.Value = ProgressBar1.Value + 1lblStatus.Caption = ProgressBar1.Value + "/" + txtNumber.TextProgressBar1.Value = ProgressBar1.Value + 1Sleep (50)NextEnd If If Combo1.Text = 8 ThenFor x = 1 To txtNumber.Text'blahtempnumber = Int((99999999 - 10000000 + 1) * Rnd + 10000000)List1.AddItem (tempnumber)Me.RefreshProgressBar1.Value = ProgressBar1.Value + 1lblStatus.Caption = ProgressBar1.Value + "/" + txtNumber.TextProgressBar1.Value = ProgressBar1.Value + 1Sleep (50)NextEnd If Combo1.Enabled = TruetxtNumber.Enabled = TrueEnd SubPrivate Sub Form_Load()Combo1.AddItem ("5")Combo1.AddItem ("6")Combo1.AddItem ("7")Combo1.AddItem ("8")End Sub


I cant do the line that says :


VB Code:
lblStatus.Caption = ProgressBar1.Value + "/" + txtNumber.Text
and I dont know a way around that. All help is appreciated.

Count The Number Of Digits
how will i count the number of digits in a number if it's declared as double? pls help me!

Adding Digits In A Number
Hey everyone! I searched for something like this buit could not find anthing. What I need to do is take a number like 123456789 and add each digit together. So it would be: 1+2+3+4+5+6+7+8+9=Whatever. I have tried a lot of different methods, but I can't seem to get it to work. Could some of you guys help me out? Thanx!

Forcing A Set Number Of Digits
This is probably a really simple question but how do I force my program to insert zeros infront of a number if it's not large enough? For example, I want all my numbers to have exactly 3 digits, so if the number is 19, I want it to store it as 019. I know you can use formatcurrency function to force 0's after the decimal, but how do you do it in my case? Thanks in advance.

Count The Number Of Digits
confusedhow will i count the number of digits in a number. NOTE: it's declared as double

Counting Number Of Digits
hi all!!

is there any method to check how many digits a number contains that is entered in the text box or if it is assigned to an integer variable??

thnx

Number Of Decimals Digits
Hello to all.

I am new with VB, so please forgive me if I sound ignorant. I am doing some calculations that involve double numbers, the results are ok, but I need to show only 2 decimal digits... and I have not been able to figure this out.

Could any body help me with this. ?

Thanks.

Get Individual Digits Of A Number
Whats the best way to do this. Soft of like the Mid$ function exept for numbers.

Increment For A Number With The Alphabet...
Dear all,

Can anyone teach me how to increase the number with the alphabet as well?

For Example, "A00001", everytime, when i click the command button, it will automatically + 1, "A00001" -> "A00002-> "A00003 -> "A00004 -> ... until "A99999"

Many Thanks...

Regards,
Nicholas

Increment The Invoice Number
i am working a Simple invoice but i need it to auto increment the invoice number.
want when Comand Button that once clicked increases the number in Range 1 by one already save number.

please if some one have any simple project please send it to me.
i am really thankful to you .

Inputbox - Limit Number Of Digits?
Is there any way to limit the number of digits the user can put into a inputbox? its because my "game" gets overflowed very easily and i figured my problem would be easily overcame if i could limit the user to only being able to put a max of 3 digits in the box.

anyone?

thanks

Calculating A Number That Has (approx) 238 Digits :O
Hi all

How would I go about calculating this, without it giving an "Error(3) Overflow!" error :P


Code:
Dim iCounter as Integer
Dim lngTotal As Long
Dim lngPrevAnswer As Long
For iCounter = 1 To 500
If lngPrevAnswer < 1 Then
lngPrevAnswer = 1
Else
lngPrevAnswer = (lngPrevAnswer * 3) + 3 'I know the brackets aren't needed.... Just clearifies the equation...
End If
lngTotal = lngTotal + lngPrevAnswer
Next iCounter

This gives an overflow error around... 15 :$

CAn someone please help me?

Kalkran

How To Limit The Number Of Digits In A Textbox?
we only need to allow to numbers to be entered in a textbox.. i mean if you have typed 2 digit numbers already, the third digit to be entered will cause a beep..

Limit Number Of Digits Entered
hi..is there a way of showing users a messagebox when they have exceeded the limit of numbers that can be entered into a text box? i created a database using visual datamanager where only 10 digits can be entered..i cant seem to be able to change that so is there a way of letting users know? thanks.

How Do You Separate 1 Big Number Into All The Individual Digits?
say you've got a number like 2749386 and rather than doing something with that number you want to split it into the individual numbers and do something with all those numbers.
So you'd have 2, 7, 4, 9, 3, 8 and 6 and can do different things to each.
it's reaaly annoying
if u can help i'd be pleased
thanx

Number Of Digits After Decimal Point
Hi Gang,

Google search gave me nothing, so here it goes:

Is there a better way to find out how many digits there are after decimal point in the given number?

123   => 0
12.56 => 2
3.4   => 1   etc.

Right now I have a little Function that accepts a number and returns another number (of digits after decimal point + 1, this 1 is the decimal point itself)

Private Function MoveNumberBy(sngValue As Single) As Double

If InStr(1, CStr(sngValue), ".") > 0 Then
    MoveNumberBy = (Len(CStr(sngValue)) - InStr(1, CStr(sngValue), ".")) + 1

End If

End Function

I hope there is a better way than dealing with converting the number to string and messing with it like that.

---- Andy

Removing Digits Form A Number
Hi there,
This may be a really biginners question, but If I had a variable say
[code]
Dim random =134830809584545445
[code]

and I want to remove the first 5 digits at the right (so removing (13483) in this case, is there a good function that can do this?

Thanks!

Unique Digits In A Number- You Might Find This Useful.
Since there's no codebank for VBA, here's something I'd like to share with you all. I just finished working on a project which I needed to count how many unique digits are in a number. In fact, I've modified it so that it works on strings too!

Code:Option Explicit

Enum typeOutput
    INDICATOR_STAR
    NUMBER_OF_UNIQUES
End Enum

Function CheckDuplicates(valRng As String, Output As Byte) As String
    Dim Count As Byte, oLen As Byte, nLen As Byte
    Dim totLen As Byte, i As Byte
    
    totLen = Len(valRng)
    ReDim Num(totLen) As Variant
    ' Populate the array one digit each.
    Call Pad(Num(), valRng)
    ' Cycle thru each digit, replacing each one in the string.
    ' For each replacement, increment Count.
    For i = 1 To totLen
        ' Pre-replace string length.
        oLen = Len(valRng)
        valRng = Replace(valRng, Num(i), "")
        ' Post-replace string length.
        nLen = Len(valRng)
        If oLen <> nLen Then Count = Count + 1
    Next i
    ' If there were upto two digits replaced,
    ' the orignal number was made up of 0, 1
    ' or 2 unique digits.
    Select Case Output
        Case INDICATOR_STAR
            ' Record one more for a replacement.
            If Count <= 2 Then CheckDuplicates = "*"
        Case NUMBER_OF_UNIQUES
            CheckDuplicates = Count
    End Select
End Function

Sub Pad(ByRef myArray() As Variant, str As String)
    Dim i As Byte
    
    For i = 1 To Len(str)
        myArray(i) = Mid(str, i, 1)
    Next i
End Sub

I use a trick I learnt many years ago where you use Replace to count how many times a specific character or digit appears in a string. Let me know what you think of it.

|
+--JDMils
|
+--VB6
+--VB Dot Net
|
+-- Navman GPS Forums @ http://forum.jdmils.com
|

How To Make Number Increment In A String?
For example the last member's ID from the database is "TP0022", then if got another guy make a new registration he/she will get the ID "TP0023".

How Do I Increment An Hex Number Inside A String?
I have this string:
"ecc9ddaa-6643-429b-9844-8dc429826254"
and I want to add a number to the last section, I splited this string:
Lsec(0)= "ecc9ddaa"
...
LSec(4) = "8dc429826254"

Now I want to add 15 to this number (Lsec(4)), and then change it back to a string so I can get something like this:

"ecc9ddaa-6643-429b-9844-8dc429826263"

Any ideas?? :S

btw ... I'm using VB 2005

Auto Increment Of A Number According To Year....
Hi Friends,

I have a problem here,I want to increase the number like this ....
2002/1 ; 2002/2 ; 2002/3 ; 2002/4 .......
2003/1 ; 2003/2 ; 2003/3 ; 2003/4 .......
like wise.....
If I select the year from combobox then according to the year the number should increse and that should be concatinated to the year and the whole should be pasted in text box.....Using Ms-Access as a database and VB as frontend......
Thanks

Storing Digits For Large Number Calc
I'm planning a module for arithmetic on large numbers and I need to store an arbitrary amount of numerical digits (0-9) in the quickest variable type possible and without wasting horrendous amounts of memory.

Longs and Integers, while the fastest of variable types, simply cannot store that amount of data.

Strings are virtually free of length boundaries, but they're 38 times slower than bytes and given that they're Unicode, they would require 2 bytes per digit. Also, string operations are notoriously slow.

I was thinking byte arrays would work well, although they are still much too large (256 possible values as compared only needing 10). This would waste half the byte. 4 bits would work well (16 possible values), but the problem would be storing and retrieving two numerical digits for individual operations. I could mathematically determine two separate digits from a value 00-99. Correct me if I'm wrong, but I think the first and second character of a byte in Hex would return the values of the first and second group of 4 bits independently.

I'm just tossing some ideas around. Thanks for any feedback!

Taking A Number In A Textbox, And Finding The Mean Of The Digits.
How do you write in a number in a text, and seperate the digits of that number? I need to find the mean of a number from 1 to 99999, then find the digit in the number that is closest to the mean, but isnt larger. Please help me.

I'm going to have a text box, label, and command button.

Textbox=input
Label=output

Basically how do I seperate digits in a number that is a string.

Extracting Digits From A Number Entered In A Textbox???
One question: I'm inputting a number in a text box, lets assume that the number is 2276340912. I want to extract specific digits out of this number, how do I do this?

Verify Correct Number Of Digits Entered (not To Few/many)
Is there a simple code for ensuring all the appropriate digits (for a credit card etc) are entered? I know how to prevent too many digits (max length).

Thanks in advance!

Taking A Number In A Text, And Finding The Mean Of The Digits.
How do you write in a number in a text, and seperate the digits of that number? I need to find the mean of a number from 1 to 99999, then find the digit in the number that is closest to the mean, but isnt larger. Please help me.

Choosing Number Of Digits After Decimal To Display
Hello,

To display numbers according to the regional setting I used this code:

nNumber = 123456.789
msgbox format(nNumber,"Standard")
and the result is 123,456.79

I want that I can choose how many number of digits after decimal to display, but the thousand and decimal separator symbol remain to follow the regional setting.
Is it possible?




Edited by - zuohui on 8/26/2004 12:39:59 AM

Taking A Number In A Textbox, And Finding The Mean Of The Digits.
How do you write in a number in a text, and seperate the digits of that number? I need to find the mean of a number from 1 to 99999, then find the digit in the number that is closest to the mean, but isnt larger. Please help me.

Solved: Increment About Form Version Number
Happy holidays!!

Can someone explain how to increment the About form version number? It just stays at 1.1.0. Other than not incrementing the form looks just fine. The code in the About form includes...
Code:
Private Sub Form_Load()
    Me.Caption = "About " & App.Title
    lblVersion.Caption = "Version " & App.Major & "." & App.Minor & _
                           "." & App.Revision
    lblTitle.Caption = App.Title
    lblDescription.Caption = "This program was written by ...blah blah"
    lblDisclaimer.Caption = "Warning: ...This program is protected ....blah"
End Sub

..but there is also under - project properties - make, the version number Major, Minor, Revision.
I have them each set to 1. And, the Auto increment is checked. But, I'm not sure about under Application the Title and Icon part. The drop down for the Icon just lists all the different forms I have in this project. I don't think of a form as an icon what am I missing here?

Under Version Information Type there are entries like comments, company name, file description and so on. What are these for?

Forgive my ignorance I realize this ain't rocket science. Maybe it's the triptophan kicking in.

thanks for any help
Hal



Edited by - Hal on 11/29/2003 7:57:44 PM

(RESOLVED)(VB6)Auto Increment Number In Access
Hon'ble gurus,
I use Access2002 and VB6. My project is a school project. I have 2 comboboxes and one textbox. In my Access database I've already entered data. In combo1 I show the classes like LKG,UKG,STD I,STD II,STD III etc. In combo2, I show the names of students found in that particular class which is selected in Combo1.Let's assume that the maximum strength in each class is 100. Now I want to allot Roll no to students of different classes in a particular way. For example: Students of LKG should have Roll no starting from 101. Students of UKG should have Roll no from 201. Students of STD I should have Roll no from 301 like this. In the textbox if I write the first roll no of a class, can I allot roll no to all students of that class in auto increment way? Hope, you got me.Right? I mean, if I choose UKG and in the textbox I write 501 then roll no should be added in database against all students of that class like 501,502,503,504 and each name. The roll no should be incremented till the no of students are found in the class. Is it possible throught VB6 coding? Thanks.

pkb_pkb

Edited by - pkb_pkb on 6/28/2007 3:58:50 AM

Auto Increment Number With Alpha Numeric
hi!,
  could you tell me how to create codes in VB about Auto increment with alpha numeric?

example:
    001A01B

thanks.

Reversing The Digits Of A Number/display The Day Of The Week For Any Date
1.)How do I write a VB function/procedure that reverses the digits of a given number? I don't want to assume the length (no. of digits) of the number. That is, the user may input a 2-digit, 3-digit or number of any length (less than 6 digits).
2.) How do I write an event procedure to display the day of the week for any given date. What functions should I use?

This is not my homework. My exams are knocking on the door and so I was solving earlier year's question papers. I am stuck, so please help!

How Do I Get The ID (AutoNumber) To Automatically Increment A Number Sqlserver??URGE
I am having a problem using the INSERT statement in ASP.NET



I have a table "Information" with the following :



Name

Email

Comments

ID (Auto Number)



I have the following insert statement



Insert into Information VALUES (MyName,Email@My.com,MyComments);

How do I get the ID ( Auto Number ) to automatically increment a number.??
i am using SQL SERVER 2000

How Do I Get The ID (AutoNumber) To Automatically Increment A Number Sqlserver??URGE
no..sql server is not handling it..
Actualyy i am doing this in ASP.NET

In my table design i have ID in the first coloumn.
Actually in my form design there are only 3 feilds like Name,Email,Comments. and a submit button.

so in my coding part i have written my sql statement like this:

sqlInsert=INSERT INTO TblTran (TRFP_Name,TTRFP_EMail,TTRFP_Comments)

so how do i get my ID in the first coloumn of the datatable??

in query analyzer when initially the value of the ID is showing NULL

so how to increment this NULL value?

Generate Auto-Number Increment In A MS Access Report
I would like to insert a automatic number field in a report that is not bound to any table. I.E. if I wanted to insert the date or time, I would simply type" =Date() ". However I would like to have every report that I generate include a auto number/random number. Any Suggstions?

PS This is for a MS Access 2000 report page.

Is There A Way To Remove Digits And Digits Only?
Is there a way to remove digits and digits only?

Hello, I feel a little embarrassed. An acquaitance
asked me a question. Namely, he works for a REIT
company and he has to put together a project where
they must retrieve various documents from the
archives. By convention, the documents are stored
according to the name of the street the property is
on, not by the street address number, and prefixes
such as "North" or "South" are ignored in ordering the
files.

He has an excel file with a list of all the
properties, but sadly, the properties are input with
the street number and directional prefixes (e.g.
"East" for "East Clinton" street) in the cell. So
sorting them in the Excel file would not at all
correspond with the order they would appear while
searching in the archives for them.

Is there a way to remove digits and digits only? I am
aware of Len and
http://office. microsoft. com/en-us/ excel/HA01154901 1033.aspx? pid=CL1005705510 33

Non-digits
I'm not sure if this is the right area or not, but how do I make it so that only numbers can be entered into a textbox, or If It dedects that non-digit charachters are entered, It changes the text.

Digits
help!
i have an exercise on school which involve time (digital clock) recording i have made my vb and un the program but when i enter the hour, minute and second in the textbox the time in the label stop i don't know how to make it continue working... you help will be vey much apreciated, thanks!

How Many Digits
Is there a way you can tell how many digits are to the left of the deciaml point in a variable dimmed as single? And how can you tell if there are numbers to the left of the decimal point in a variable dimmed as a single?

Digits
Hello. i am Running VB 6.0. i am making a countdown clock for school and every time it gets one digit in seconds, like 19:09, it cuts off the 0 and says 19:9. How can i insure that the variable stays two digits?

Thanks

4 Digits
Hey people do you know how i can get 4 digits to be displayed in a text box?

Sum Of Digits
From memory, so no warranty of any kind


VB Code:
Function SumOfDigits (ByVal Number As Integer) As Integer    Dim r As Integer    Do While Number > 0        r = r + Number Mod 10        Number = Number / 10    Loop    SumOfDigits = rEnd Function

Digits
What's the easiest way to find the # of digits (or letters) in a string or in a int? Is there a built in function or do you have to do it manually?

2 Digits
Hello,

Since I am new with vb i have a little question.
I'm calculating in a ppc program some numbers and i want that the result
only have 2 digits after the comma. Can anyone helpme ?

SQL AND ADO SIG DIGITS
I am retrieving a value from the database that resides as "10.0" (a float value) When using Query Analyzer I am retrieving "10.0".

When I run a stored procedure and utilize the ADO object to display the value it shows a "10". "10" is not the same as "10.0" for my application.

Please let me know if there are any settings to ensure that the value is returned as inputted. The alternative I have is to store the values a varchar data.

Note: Implied decimal values will not work for this application. The significance of the data is not known prior to receiving it.

Thanks everyone!!

Getting Three Digits Off The Website
The use of my program requires it being added to the startup group. I may be a throwback for even considering these types of things, but because it's going to be permanently running in the background, I want to minimize the footprint in every way possible.

I do, however, want the program to be able to check what the latest version is on the website. All it needs is to pull down is three digits from the website, be it checking the filename of the latest version posted or reading a three character text file.

My question then is can I do this without adding a control? Is there some sort of API that could do this?

If the control is the only way to go, would INet be the best way (smallest footprint) to go about it?



thanks,

Inserting Digits
Ok, i know the solution is probably really simple but i don't really know what to search for when looking for a solution.

I am renaming files using a number ordering system but i need the files to be numbered as follows:

If the length of digits is only 2 then:
01, 02, 03, 04, 05...10, 11, 12, 13, 14, 15

If the length of digits is only 3 then:
001, 002, 003...010, 011, 012, 013...100, 101, 102, 103

Obviously i can get the length of digits as Len($String) so that's fine. I just need to know how to insert the preceding zero's (this is so that Windows lists them in the correct order).

Thank you for any help.

Long To Digits?
is there a way that i can divide a long into its seperate digits and put them in an array? ie-

x=1423

temp(0)=1
temp(1)=4
temp(2)=2
temp(3)=3

Copyright © 2005-08 www.BigResource.com, All rights reserved