It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Simple Calculation Error i think

Moderator: dafunkymunky

Simple Calculation Error i think

Postby Moulieg on Sat Mar 24, 2007 10:55 am

Hey, i'm writing a simple program, which happens to use a similar coding as a calculator. I was writing my code when i noticed i was getting a problem when i went to calculate my information. It was the addition of my the numbers i was using, instead of calculating like this say:

1 + 4 = 5

I am getting the problem:

1 + 4 + 6 = 146

Which all the program has done is placed the numbers against eachother.
Heres Some of my code not all of it, just the calculating.

Code: Select all
num1 = Attack1.Text
num2 = Attack2.Text
num3 = Defence1.Text
num4 = Defence2.Text
num5 = Average1.Text
num6 = Average2.Text
num7 = Bonus1.Text
num8 = Bonus2.Text

answer1 = num1 + num3 + num5 + num7
answer2 = num2 + num4 + num6 + num8


total1.Text = answer1
total2.Text = answer2

Whats going wrong ?

Any Help Would Be Much Appreciated!

Moulieg
Moulieg
 
Posts: 2
Joined: Sat Mar 24, 2007 10:48 am
Location: Mitta

Postby AnthraX1 on Sat Mar 24, 2007 6:15 pm

answer1 = cdbl(num1 + num3 + num5 + num7)
answer2 = cdbl(num2 + num4 + num6 + num8)
your answers output are comming out as a string so it would obviously not add them, you must convert them to a number type cdbl if there are decimals, or cint if they do not have decimals.
AnthraX1
 
Posts: 12
Joined: Wed Mar 21, 2007 6:47 pm

Still Not working

Postby Moulieg on Sun Mar 25, 2007 10:00 am

I tried using cdbl but still i am recieving the same problem, the numbers are plusing together like strings rather than integers ? I am not all that good at programing you see, lol. Any way, i am still having problems, is there anything else that might work ?

Could any of this be incorrect ?

Code: Select all
Private Sub Command2_Click()
On Error Resume Next

num1 = Attack1
num2 = Attack2
num3 = Defence1
num4 = Defence2
num5 = Average1
num6 = Average2
num7 = Bonus1
num8 = Bonus2

answer1 = CDbl(num1 + num3 + num5 + num7)
answer2 = CDbl(num2 + num4 + num6 + num8)

total1.Text = answer1
total2.Text = answer2

If total1 > total2 Then
    Winner = Team1
Else
    Winner = Team2
End If

If total1 > total2 Then
Points = total1 - total2
Else
Points = total2 - total1
End If

   
End Sub


Thanks For All your help thus far!

Moulieg
Moulieg
 
Posts: 2
Joined: Sat Mar 24, 2007 10:48 am
Location: Mitta

Postby SPIRO_DT on Fri Dec 14, 2007 5:14 pm

ypu can also declare a variables of the integer type
dim a as integer
a = text1.text
SPIRO_DT
 
Posts: 3
Joined: Thu Dec 13, 2007 8:19 pm
Location: Tetovo , Macedonia

Postby bimal on Thu Jan 17, 2008 4:51 am

Code:


you should use following code to correct ur mistake in it:

dim num1 as integer

num1=int(text1.text)
& so on.....

i hope u will get ur solution...
for more info regarding vb.net you can visit at :

http://webdesigningcompany.net
bimal
 
Posts: 7
Joined: Wed Jan 16, 2008 5:46 am


Who is online

Users browsing this forum: No registered users and 5 guests