Results 1 to 10 of 10

Thread: Stuck on a no brainer

  1. #1

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11

    Question Stuck on a no brainer

    ok im trying to write programs to help friends of mine with a game (they are not hacks for they game)

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim a As Integer
    3. Dim b As Double
    4. Dim c As Double
    5.  
    6. a = Text1.Text
    7. Label1.Caption = b
    8. Label2.Caption = c
    9.  
    10. b = a * a * a * 8000
    11. c = a * a * a * 8400
    12. End Sub

    I read what other people posted on similar topics and it couldnt work.
    if there is help out there please... let me have it.
    Johnny Tsunami

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    It might be me, but I have no idea what your after???

  3. #3
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    What exactly do you want to achieve?
    What should the value held in b and c be?

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You may get an overflow error (depending on the value of a). Just cast one of your values to a different datatype.

    b = a * a * a * CLng(8000)
    c = a * a * a * CLng(8400)

  5. #5

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11
    what i am trying to do is write a multiplication program that does a number cubed, times 8000 and sends it to one label and cubes the same number and multiplies it by 8400 and sends it to the other label.
    Johnny Tsunami

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    You need to change the datatype of variable 'a' to a Long (or Single, or Double). VB is wierd that way - I think it has to do with implicit conversion while it does "a * a * a * 8000", a becomes a value that is too big for an integer so it crashes. But don't quote me

    Also, don't you want to set your captions AFTER you determine b and c?

    This should work:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim a As Double
    3.     Dim b As Double
    4.     Dim c As Double
    5.    
    6.     a = Val(Text1.Text)
    7.    
    8.     b = a * a * a * 8000
    9.     c = a * a * a * 8400
    10.    
    11.     Label1.Caption = b
    12.     Label2.Caption = c
    13. End Sub
    ~seaweed

  7. #7

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11

    Arrow still stuck

    thanks for the help guys. now i know how to do the other program that is a companion for this one.
    Johnny Tsunami

  8. #8
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I read what other people posted on similar topics and it couldnt work.
    Does this mean you haven't actually tested the code.

    have you tried using brackets
    Code:
    b = (((a * a) * a) * 8000)
    I would certainly be using Long instead of Double for variable declaration.

  9. #9
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    This also works...

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim a As Integer
    3.     Dim b As Double
    4.     Dim c As Double
    5.    
    6.     a = Val(Text1.Text)
    7.    
    8.     b = CDbl(a) * a * a * 8000
    9.     c = CDbl(a) * a * a * 8400
    10.    
    11.     Label1.Caption = b
    12.     Label2.Caption = c
    13. End Sub

    PS: I always test my code unless I say otherwise!
    PPS: Speaking of testing code, this gives an overflow also:
    b = (((a * a) * a) * 8000)
    ~seaweed

  10. #10
    Fanatic Member
    Join Date
    Dec 2002
    Location
    North Carolina
    Posts
    734
    Eh... I know he has it figured out but wouldn't using a line such as "a^3" been much easier?

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