Results 1 to 12 of 12

Thread: [RESOLVED] Really weird thing happening with my Double...

  1. #1

    Thread Starter
    New Member MuscleShark88's Avatar
    Join Date
    Feb 2010
    Posts
    12

    Resolved [RESOLVED] Really weird thing happening with my Double...

    I have no idea why this is happening...very strange.

    Assume the following situation:


    Dim FirstPlacePercent(4) as Double
    Dim StackSum as Long
    Dim Stack(4) as Long

    txtstack1.text = 1
    txtstack2.text = 50000
    txtstack3.text = 50000
    txtstack4.text = 50000

    Stack(1) = txtstack1.text
    Stack(2) = txtstack2.text
    Stack(3) = txtstack3.text
    Stack(4) = txtstack4.text

    For i = 1 to 4
    StackSum = StackSum + Stack(i)
    next i

    For i = 1 to 4
    FirstPlacePercent(i) = (Stack(i)/StackSum) * 100
    next i

    ____________________


    ok, so since Stack(1) is VERY small relative to the others...it should yield

    FirstPlacePercent(1) = .0000066666666
    FirstPlacePercent(2) = 33.333
    FirstPlacePercent(3) = 33.333
    FirstPlacePercent(4) = 33.333



    BUT for some reason that is beyond my knowledge, it is actually outputting

    FirstPlacePercent(1) = 6.666666
    FirstPlacePercent(2) = 33.333
    FirstPlacePercent(3) = 33.333
    FirstPlacePercent(4) = 33.333


    anyone have any clue why this is happening? b/c i'm baffled.
    Last edited by MuscleShark88; Mar 9th, 2010 at 02:57 PM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Really weird thing happening with my Double...

    Why do you think that: FirstPlacePercent(1) = 6.6666666 ?
    stacksum totals to 50000*3 + 1 or 150001
    For FirstPlacePercent(1), you are dividing 1/150001 which would be 6.66662222251852E-06 or approx: 0.000006666622223
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member MuscleShark88's Avatar
    Join Date
    Feb 2010
    Posts
    12

    Re: Really weird thing happening with my Double...

    Quote Originally Posted by LaVolpe View Post
    Why do you think that: FirstPlacePercent(1) = 6.6666666 ?
    stacksum totals to 50000*3 + 1 or 150001
    For FirstPlacePercent(1), you are dividing 1/150001 which would be 6.66662222251852E-06 or approx: 0.000006666622223
    it shouldn't be yielding 6.66666.....BUT IT IS...this is my problem....this is what the screen is outputting

    i realize it should be 0.000006666 ...but it's not outputting that

    and it's screwing up my equations later on...

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Really weird thing happening with my Double...

    Double check again, do you see the E-06 at the end? If not, how are you displaying the results? Show us that.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    New Member MuscleShark88's Avatar
    Join Date
    Feb 2010
    Posts
    12

    Re: Really weird thing happening with my Double...

    i'm displaying it through a label

    lblP1FirstPlacePercent.caption = FirstPlacePercent(1)

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Really weird thing happening with my Double...

    Oh, what language are you using?
    VB6 Integers cannot hold a value of 50000. You should be getting an error & if you have On Error Resume Next in your routine that is your problem -- fix the error
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    New Member MuscleShark88's Avatar
    Join Date
    Feb 2010
    Posts
    12

    Re: Really weird thing happening with my Double...

    Quote Originally Posted by LaVolpe View Post
    Oh, what language are you using?
    VB6 Integers cannot hold a value of 50000. You should be getting an error & if you have On Error Resume Next in your routine that is your problem -- fix the error
    using vb6

    sorry about that, i actually typed out the situation wrong...

    in my program i actually have:

    Dim Stack(4) as Long (NOT integer like i had before)

    still not working tho


    also: if i had it:

    Stack(1) = 1
    Stack(2) = 400
    Stack(3) = 400
    Stack(4) = 400

    i get the same thing.....w/ FirstPlacePercent = 8.32 instead of = 0.000832



    really weird...b/c if i just type FirstPlacePercent = 0.000832 in the code , it works....but not when the code runs the program thru
    Last edited by MuscleShark88; Mar 9th, 2010 at 03:03 PM.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Really weird thing happening with my Double...

    Is your label too short to display the far right of the value?
    Tweak your routine like so and then open your immediate/debug window (Ctrl+G) to see what was printed out
    Code:
    For i = 1 To 4
    FirstPlacePercent(i) = (Stack(i) / StackSum) * 100
        Debug.Print i; Stack(i); StackSum, FirstPlacePercent(i)
    Next i
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    New Member MuscleShark88's Avatar
    Join Date
    Feb 2010
    Posts
    12

    Re: Really weird thing happening with my Double...

    Quote Originally Posted by LaVolpe View Post
    Is your label too short to display the far right of the value?


    i feel dumb

    rofl thanks for the help...greatly appreciated.

    i am new to VB, i assumed that it would adjust and squeeze in E-02

    bad assumption

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Really weird thing happening with my Double...

    You're welcome. Sometimes the easiest things are the hardest to see!
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Really weird thing happening with my Double...

    Quote Originally Posted by MuscleShark88 View Post
    [IMG]Assumed that it would adjust and squeeze in E-02

    bad assumption
    Labels do have an AutoSize property; you may want to play with that.
    Also, you may want to play with VB's Format function.
    Code:
    Label1.Caption = Format(someNumber, "Percent")
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Really weird thing happening with my Double...

    Quote Originally Posted by MuscleShark88 View Post


    i feel dumb
    rofl thanks for the help...greatly appreciated.
    i am new to VB
    Muscle

    Welcome to the Forums
    Glad LaVolpe got you squared away

    BTW - great image. Haven't seen Jean-Luc for a while

    Spoo

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