Results 1 to 8 of 8

Thread: Format ??? Resolved

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    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

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Format ???

    I don't think I understand.

    Step$ is not valid in VB. You should use Option Explicit.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim step1 As Currency
    5. Dim stepx As Currency
    6. stepx = 0.0003
    7. step1 = Abs(Format(stepx * 10000, "#.#####"))
    8. MsgBox step1
    9. End Sub
    Is this what you want? ?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    Talking Re: Format ?[RESOLVED]

    Step$ is a string in my app.

    And thank for helping, that worked nice.

    Reston

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    Re: Format ??? Resolved

    I'm not getting an error on my system?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    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

  7. #7
    Addicted Member Luke K's Avatar
    Join Date
    Jun 2004
    Location
    Perth, Australia
    Posts
    183

    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:
    1. Private Sub Form_Load()
    2.  
    3.     Dim dblL As Double
    4.  
    5.     dblL = 34.32
    6.     MsgBox dblL & vbCrLf & Format(dblL, "##")
    7.  
    8. 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

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Format ??? Resolved

    Quote 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
  •  



Click Here to Expand Forum to Full Width