Solved

variable looses all the zeros in + calc

Posted on 2004-09-01
8
209 Views
Last Modified: 2010-05-02
ok I have one problem...
when I have number 000001 stored to variable, and I add 1 to it
(000001 + 1) I end up with 2, but I wanna have 000002. I know
that I can add those missing zeros with 00000 & 2 but I would like to
know if there is any way to not to loose those zeros in the calculation process.

This would help me a lot in what I have been coding
(my own coordinate system)
0
Comment
Question by:jozne
[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
  • 2
  • 2
  • +2
8 Comments
 
LVL 8

Accepted Solution

by:
mladenovicz earned 125 total points
ID: 11950366
Format(number, "000000")
0
 
LVL 10

Expert Comment

by:anv
ID: 11950448
the only way to do so is using string

let var1 stores the value 000001

then do following
dim var1Str as string, lastDigit as integer
dim otherDigits as string

var1str=cstr(var1)
lastDigit = cint(left(var1str,1)) 'will store 1

otherDigits = right(var1str,len(var1str)-1 'will store 00000

lastDigit=lastDigit +1 'will have 2 now

var1 = otherDigits + lastdigit

'now var1 will have 000002


0
 
LVL 19

Expert Comment

by:Shauli
ID: 11951144
Private Sub Command1_Click()
Var1 = "000001"
MsgBox Format(Var1 + 1, "000000")
End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:VIkasumit
ID: 11951153
Hi..
I certainly go with the format string however the correct syntax for me is

newvalue=format (number, "00000#")

VIkasumit
http://sumitonnet.20m.com

0
 
LVL 10

Expert Comment

by:anv
ID: 11951296
Shauli's code will work but if u store the data in an integer variable the value will again go as  2 removing leading 0's

yes for storing as a string it will work...
like

Private Sub Command1_Click()
dim str1 as string
Var1 = "000001"
str1 =  Format(Var1 + 1, "00000#")
End Sub
0
 
LVL 4

Expert Comment

by:VIkasumit
ID: 11952739
Hi..

Yes He is right but Again when ever you need You can use Format Like while displaying, Storing or even manupulating. And If you just want to use it as a ID field than better use the string datatype once generated u doesn't need to change it....

VIkasumit
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11952756
Var1 can be stored as String or as Varinat, as in:

Private Sub Command1_Click()
Dim Var1 As Variant, Var2 As Variant
Var1 = "000001"
Var2 = Format(Var1 + 1, "000000")
MsgBox Var2
End Sub

Either way will work. And there is no different if you go 00000# or 000000. The result is the same.

S
0
 

Author Comment

by:jozne
ID: 12003813
Thank you guys for your answers. My coordination system is up and running :)
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

738 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