Contatore alfanumerico

Forum dedicato ai programmatori di X# in lingua italiana – Italian language forum

Moderator: wriedmann

Post Reply
User avatar
softdevo@tiscali.it
Posts: 189
Joined: Wed Sep 30, 2015 1:30 pm

Contatore alfanumerico

Post by softdevo@tiscali.it »

Salve a tutti. La fatturazione elettronica limita a 5 caratteri il contatore progressivo dei file XML.

99999 è un numero facilmente raggiungibile e superabile.

Mi servirebbe una idea per creare un contatore tipo:

00001
00002
00003
………
99999
A0001
A0002
………
AB001
……...
ZZZZZ

Qualche idea?

Grazie

Danilo
FFF
Posts: 1522
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Contatore alfanumerico

Post by FFF »

Class Alfanumerico, using ascii values and overwrite the + operator? You'll have to skip the "unusable" values, so it might not be ultra fast, but usually you won't generate invoices in millisecond steps ;)

Karl
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Contatore alfanumerico

Post by Chris »

Danilo,

Are you sure you prefer to use letters only after reaching 99999? In my opinion, if you want to eventually start combining numbers and letters, it is better to do that from the start, so 00009->0000A, 0000Z->00010 etc.

This code should do that, but if you want to do it your original way (letters only after "99999"), it can be modified..

Code: Select all

USING System.Text

FUNCTION Start() AS VOID
	? NextNumber("00000")
	? NextNumber("0000A")
	? NextNumber("0000Y")
	? NextNumber("0000Z")
	? NextNumber("00099")
	? NextNumber("000ZZ")
	? NextNumber("01ZZZ")
RETURN

FUNCTION NextNumber(cCurrent AS STRING) AS STRING
	STATIC LOCAL cNext := StringBuilder{} AS StringBuilder
	LOCAL lCarry := TRUE AS LOGIC
	cNext:Length := 0
	FOR LOCAL n := cCurrent:Length - 1 AS INT DOWNTO 0
		LOCAL nAsc AS INT
		nAsc := cCurrent[n]
		IF lCarry
			lCarry := FALSE
			nAsc ++
			IF nAsc == 58 // '9' + 1
				nAsc := 65 // 'A'
			ELSEIF nAsc == 91 // 'Z' + 1
				nAsc := 48 // '0'
				lCarry := TRUE
			END IF
		END IF
		cNext:Insert(0 , (Char)nAsc)
	NEXT
RETURN cNext:ToString()
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
softdevo@tiscali.it
Posts: 189
Joined: Wed Sep 30, 2015 1:30 pm

Contatore alfanumerico

Post by softdevo@tiscali.it »

Grazie a tutti, thank you to all
User avatar
softdevo@tiscali.it
Posts: 189
Joined: Wed Sep 30, 2015 1:30 pm

Contatore alfanumerico

Post by softdevo@tiscali.it »

In some cases I have to maintain compatibility with the past, Cases in which they started to number the invoices from 1 to 99999

Danilo
Post Reply