PC Review


Reply
Thread Tools Rate Thread

"000" reverts back to "0" even with a string

 
 
Philosophaie
Guest
Posts: n/a
 
      22nd May 2010
I want to have a 4 digit number in all cases but some have 0 thru 3.

This is how I attempted to solve it:

dim x(3) as string
x(1)=234
x(2)=67
x(3)=5
If Len(x(m)) = 1 Then x(m) = 000 & x(m)
If Len(x(m)) = 1 Then x(m) = 00 & x(m)
If Len(x(m)) = 1 Then x(m) = 0 & x(m)
the problem is when you enter "000" in for the result it automatically
reverts back to "0"
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      22nd May 2010

They ain't strings until you make them strings...
If Len(x(m)) = 1 Then x(m) = "000" & x(m)
If Len(x(m)) = 1 Then x(m) = "00" & x(m)
If Len(x(m)) = 1 Then x(m) = "0" & x(m)
--
Jim Cone
Portland, Oregon USA
( http://www.mediafire.com/PrimitiveSoftware )




"Philosophaie" <(E-Mail Removed)>
wrote in message news:9FA3AEB6-FCD8-4D78-A50C-(E-Mail Removed)...
I want to have a 4 digit number in all cases but some have 0 thru 3.
This is how I attempted to solve it:

dim x(3) as string
x(1)=234
x(2)=67
x(3)=5
If Len(x(m)) = 1 Then x(m) = 000 & x(m)
If Len(x(m)) = 1 Then x(m) = 00 & x(m)
If Len(x(m)) = 1 Then x(m) = 0 & x(m)
the problem is when you enter "000" in for the result it automatically
reverts back to "0"
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd May 2010
Don't use a series of If..Then tests (by the way, the numbers you are
testing against should be 1, 2, 3 and not 1, 1, 1), use the Format function
instead. For all your cases, use this single statement...

x(m) = Format(x(m), "0000")

--
Rick (MVP - Excel)



"Philosophaie" <(E-Mail Removed)> wrote in message
news:9FA3AEB6-FCD8-4D78-A50C-(E-Mail Removed)...
> I want to have a 4 digit number in all cases but some have 0 thru 3.
>
> This is how I attempted to solve it:
>
> dim x(3) as string
> x(1)=234
> x(2)=67
> x(3)=5
> If Len(x(m)) = 1 Then x(m) = 000 & x(m)
> If Len(x(m)) = 1 Then x(m) = 00 & x(m)
> If Len(x(m)) = 1 Then x(m) = 0 & x(m)
> the problem is when you enter "000" in for the result it automatically
> reverts back to "0"


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
Power Mgt: "Turn off monitor" "Never" always reverts to "After 20 mins" OpaPiloot Windows XP Video 2 18th Jul 2008 08:16 PM
Howto? Dlookup("field","SAVED_QUERY","Criteria='string'") Jndrline via AccessMonster.com Microsoft Access VBA Modules 4 3rd Nov 2006 08:23 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 AM.