|
-
Mar 26th, 2003, 06:18 PM
#1
Thread Starter
New Member
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:
Private Sub Command1_Click()
Dim a As Integer
Dim b As Double
Dim c As Double
a = Text1.Text
Label1.Caption = b
Label2.Caption = c
b = a * a * a * 8000
c = a * a * a * 8400
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.
-
Mar 26th, 2003, 06:32 PM
#2
It might be me, but I have no idea what your after???
-
Mar 26th, 2003, 06:33 PM
#3
Fanatic Member
What exactly do you want to achieve?
What should the value held in b and c be?
-
Mar 26th, 2003, 06:39 PM
#4
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)
-
Mar 26th, 2003, 07:40 PM
#5
Thread Starter
New Member
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.
-
Mar 26th, 2003, 07:48 PM
#6
Frenzied Member
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:
Private Sub Command1_Click()
Dim a As Double
Dim b As Double
Dim c As Double
a = Val(Text1.Text)
b = a * a * a * 8000
c = a * a * a * 8400
Label1.Caption = b
Label2.Caption = c
End Sub
-
Mar 26th, 2003, 07:49 PM
#7
Thread Starter
New Member
still stuck
thanks for the help guys. now i know how to do the other program that is a companion for this one.
-
Mar 26th, 2003, 07:51 PM
#8
Fanatic Member
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.
-
Mar 26th, 2003, 07:53 PM
#9
Frenzied Member
This also works...
VB Code:
Private Sub Command1_Click()
Dim a As Integer
Dim b As Double
Dim c As Double
a = Val(Text1.Text)
b = CDbl(a) * a * a * 8000
c = CDbl(a) * a * a * 8400
Label1.Caption = b
Label2.Caption = c
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)
-
Mar 26th, 2003, 08:07 PM
#10
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|