|
-
Mar 27th, 2005, 02:47 AM
#1
Thread Starter
Lively Member
Format ??? Resolved
Hi All
I cant not seem to figure this out . Can anyone look at this??
Step$ = .0003
Step1 = Abs(Int(Format(Step$, "##.####')*10000))
The problem is that "Step" in this = 2 when formatted. It should be 3
This seems to work for on all numbers except .0003 in this example.
Thanks Reston
Last edited by tiguy; Mar 27th, 2005 at 03:07 AM.
Reason: Resolved
-
Mar 27th, 2005, 02:58 AM
#2
Re: Format ???
I don't think I understand.
Step$ is not valid in VB. You should use Option Explicit.
VB Code:
Option Explicit
Private Sub Form_Load()
Dim step1 As Currency
Dim stepx As Currency
stepx = 0.0003
step1 = Abs(Format(stepx * 10000, "#.#####"))
MsgBox step1
End Sub
Is this what you want? ?
-
Mar 27th, 2005, 03:05 AM
#3
Thread Starter
Lively Member
Re: Format ?[RESOLVED]
Step$ is a string in my app.
And thank for helping, that worked nice.
Reston
-
Mar 27th, 2005, 03:08 AM
#4
Re: Format ???
It's not good to let VB coerce the values. You set Step$ = .0003 which generated an error on my system. That's why I changed it.
As glad as it worked, I'm happy.
-
Mar 27th, 2005, 03:10 AM
#5
Thread Starter
Lively Member
Re: Format ??? Resolved
I'm not getting an error on my system?
-
Mar 27th, 2005, 03:15 AM
#6
Thread Starter
Lively Member
Re: Format ??? Resolved
Hey do you have any idea why vb was rounding 3 to 2 the way i had things or was that the problem that the format was all wrong.
Private Sub Command1_Click()
ee$ = 0.0003
'tth$ = Abs(Int(Format(ee$, ".####") * 10000))
step1 = Abs(Int((Format(ee$ * 10000, "#.#####"))))
End Sub
I want to make sure that step1 is forced to an interger.Thats why it's in there
reston
-
Mar 27th, 2005, 05:57 AM
#7
Addicted Member
Re: Format ??? Resolved
Well forcing it to an integer means no decimal places, thus, vb must round it Use a double and format it in this way:
VB Code:
Private Sub Form_Load()
Dim dblL As Double
dblL = 34.32
MsgBox dblL & vbCrLf & Format(dblL, "##")
End Sub
The output from the MsgBox is:
34.32
34
Artificial Intelligence At War! - The best game of its genre
Program your own robot and watch it fight in 3d!
Droidarena 3
If I have been useful, please Rate My Post
Support FireFox - 
Microsoft Visual Studio .NET Professional 2003
Microsoft Visual Studio 6, Enterprise Edition
Microsoft Windows XP Professional, Service Pack 2
-
Mar 27th, 2005, 05:23 PM
#8
Re: Format ??? Resolved
 Originally Posted by tiguy
I'm not getting an error on my system?
Must be that I have option explicit in every module/form.
In the VB IDE Click on Tools -> Options, and then tick the box that says
"Require Variable Declaration" and it will put Option Explicit in every module/form automatically. Only in future projects. You have to paste it into current projects.
It will then error out when you don't declare a variable or something like trying to set an integer to a string value.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|