Navigation

Search

Categories

On this page

I am a nerd
Using a text file to hold sequential numbers in Excel
Truth

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 120
This Year: 1
This Month: 0
This Week: 0
Comments: 40

Sign In
Pick a theme:

# Tuesday, January 11, 2005
Tuesday, January 11, 2005 11:38:49 AM (Mountain Standard Time, UTC-07:00) ( )

 Das Nerd 

Someone out there on the internet said that they were a "mid level nerd". I’m accused daily by my co-workers of being a geek, and I become scared of how highly nerdy this same quiz might tag me as…. I decided to take it.

I am nerdier than 88% of all people. Are you nerdier? Click here to find out!

Evidently the fear and loathing is well founded according to the said survey.  This means that I’m nerdier than about 9 out of every 10 people I meet in life. Scary isn’t it.

Edit – Apparantly Scott is a bigger nerd than I am http://www.hanselman.com/blog/Trackback,guid,f77753ff-5181-4a27-a9be-370c1fe1665e.aspx

Edit – Nice to see that female nerds still don’t rank quite as high as nerds. Cheers Michele! Do you know any early-20’s nerds that are as beatiful and smart as you?

Comments [0] | | # 
# Monday, January 10, 2005
Monday, January 10, 2005 9:46:52 AM (Mountain Standard Time, UTC-07:00) ( All things Microsoft )

Using a text file to hold sequential numbers

This method is more useful in some situations. The biggest advantage is that the sequential number is no longer tied to a particular machine - it can be stored on a common server, or even a thumb drive. Disadvantages include difficulty in keeping the file from being modified simultaneously by two users, or of the file being more easily deleted or modified. This function will return the next sequential number:

Public Function GetNextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long            
	Const sDEFAULT_PATH As String = "<your path here>"            
	Const sDEFAULT_FNAME As String = "defaultseq.txt"            
	Dim nFileNumber As Long                    
	nFileNumber = FreeFile            
	If sFileName = "" Then sFileName = sDEFAULT_FNAME                
		If InStr(sFileName, Application.PathSeparator) = 0 Then _                       
			sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName            

	If nSeqNumber = -1& Then                    
		If Dir(sFileName) <> "" Then                            
			Open sFileName For Input As nFileNumber                            
			Input #nFileNumber, nSeqNumber
			nSeqNumber = nSeqNumber + 1
			Close nFileNumber                    
		Else                            
			nSeqNumber = 1
		End If            
	End If                        

	On Error GoTo PathError                        
		Open sFileName For Output As nFileNumber                        

	On Error GoTo 0                        
		Print #nFileNumber, nSeqNumber                        
		Close nFileNumber            
		NextSeqNumber = nSeqNumber            
		Exit Function    

	PathError:            
		NextSeqNumber = -1
End Function

If you provide a full path in sFileName, that's where the file will be stored. If not, the file will be stored in whatever default directory you specify. You can set the sequential number by providing a value for nSeqNumber.

Thus, if I'm only using one sequence I can use

Public Sub Workbook_Open()            
	ThisWorkbook.Sheets(1).Range("B2").Value = GetNextSeqNumber    
End Sub

to return the next sequence number. If I'm using multiple sequences, I include the filename (with path, if the text file is not in the default path).

Public Sub NewClientInvoice()            
	This.Workbook.Sheets(1).Range("B2").Value = GetNextSeqNumber("Client1.txt")    
End Sub

And if I want to start a new sequence, beginning at, say, 1001, include that number in the function call. If the client name were in cell B4:

Public Sub SetUpNewClient()
	With ThisWorkbook.Sheets(1)        
		.Range("B2").Value = GetNextSeqNumber(.Range("B4").Value & ".txt", 1001)            
	End With    
End Sub
Original article credit to: http://www.mcgimpsey.com/excel/udfs/sequentialnums.html
Excel is a licensed product of Microsoft Corporation
Comments [0] | | # 
# Tuesday, January 04, 2005
Tuesday, January 04, 2005 7:54:07 AM (Mountain Standard Time, UTC-07:00) ( General )

I read something the other day that had a tremendous impact on me, I thought I'd share.

Truth

Truth is unchangeable reality.
It doesn't depend on circumstances.
What is true is always true in every place on every occasion.
Truth systematically links facts together to create an understanding of life's situations.
Line upon line, precept upon precept, truth builds it's house.
-Author unknown

Comments [0] | | #