Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Keeping a number as a lenth=4 string

Posted on 2003-11-07
3
Medium Priority
?
152 Views
Last Modified: 2010-05-03
I have a string called CustomerID and I need it in the format 0003, 0014 etc...  this is what I have, but my problem is if I enter a number say 13 it gives me 00013 when I really want 0013.  It is the select case part of the function that the problem lays I think.

'Creates a new JobID
Public Function NewJobID() As String
    Dim JobID As String, Counter As Single
    JobID = LastJobID + 1
    LastJobID = LastJobID + 1
    Call UpdateLastIDs
    Select Case JobID
        Case 1 To 9
            NewJobID = "000" & JobID
        Case 10 To 99
            NewJobID = "00" & JobID
        Case 100 To 999
            NewJobID = "0" & JobID
        Case 1000 To 9999
            NewJobID = JobID
    End Select
End Function


Thanks, Jebus
0
Comment
Question by:dj__jebus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:dj__jebus
ID: 9706198
lol, woops I said CustomerID    oh well, I have identical functions for both CustomerID and JobID, same thing...
0
 
LVL 3

Accepted Solution

by:
NBrownoh earned 200 total points
ID: 9706222
Ret = Abs(4 - Len(CStr(YourNum)))
FormatNum = String(Ret, "0") & YourNum

FormatNum is the number correctly formatted for this, and YourNum should be replaced with the variable holding the number you want to format
0
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9706227
BTW FormatNum is a string variable and Ret is an integer variable
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question