ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba calcs are acting funny (https://www.excelbanter.com/excel-programming/320765-vba-calcs-acting-funny.html)

Papa Jonah

vba calcs are acting funny
 
I have a process with 42 pages of code. There are a boatload of calcs in it
that seem to be working.
However there is one that is giving me a hard time and I can't figure it out.
I have declarations: public overallscore as integer, public allscore as
integer, and public totalscore as integer, and public dataset as integer
I do not have any declarations for x.

OverAllScore = totalscore / dataset 'OverAllScore =0
x = totalscore / dataset ' x=-0.5
allscore = x 'allscore =0
If OverAllScore = 0.5 Then . . .

I am getting a value of -2 for totalscore and 4 for dataset. However
overallscore =0.
On the contrary x=-0.5 which is as expected. Then allscore ends up =0
instead of equal to x.

What am I possibly overlooking?

TIA



Fredrik Wahlgren

vba calcs are acting funny
 

"Papa Jonah" wrote in message
...
I have a process with 42 pages of code. There are a boatload of calcs in

it
that seem to be working.
However there is one that is giving me a hard time and I can't figure it

out.
I have declarations: public overallscore as integer, public allscore as
integer, and public totalscore as integer, and public dataset as integer
I do not have any declarations for x.

OverAllScore = totalscore / dataset 'OverAllScore =0
x = totalscore / dataset ' x=-0.5
allscore = x 'allscore =0
If OverAllScore = 0.5 Then . . .

I am getting a value of -2 for totalscore and 4 for dataset. However
overallscore =0.
On the contrary x=-0.5 which is as expected. Then allscore ends up =0
instead of equal to x.

What am I possibly overlooking?

TIA



Use Double rather than integer. And declare x as Double, too. If you divide
an integer value with another integer, the result will be an integer.

/Fredrik



Papa Jonah

vba calcs are acting funny
 
I am not sure I understand. Do you want me to decla
public x as double?
I understand that if I divide an integer by an integer, I get an integer -
so why don't I declare the result as an integer?

"Fredrik Wahlgren" wrote:


"Papa Jonah" wrote in message
...
I have a process with 42 pages of code. There are a boatload of calcs in

it
that seem to be working.
However there is one that is giving me a hard time and I can't figure it

out.
I have declarations: public overallscore as integer, public allscore as
integer, and public totalscore as integer, and public dataset as integer
I do not have any declarations for x.

OverAllScore = totalscore / dataset 'OverAllScore =0
x = totalscore / dataset ' x=-0.5
allscore = x 'allscore =0
If OverAllScore = 0.5 Then . . .

I am getting a value of -2 for totalscore and 4 for dataset. However
overallscore =0.
On the contrary x=-0.5 which is as expected. Then allscore ends up =0
instead of equal to x.

What am I possibly overlooking?

TIA



Use Double rather than integer. And declare x as Double, too. If you divide
an integer value with another integer, the result will be an integer.

/Fredrik




Fredrik Wahlgren

vba calcs are acting funny
 

"Papa Jonah" wrote in message
...
I am not sure I understand. Do you want me to decla
public x as double?


Yes. totalscore and dataset too

I understand that if I divide an integer by an integer, I get an integer -
so why don't I declare the result as an integer?


Becuse it doesn't make sense to compare an integer value with a decimal
value. That's what you do with "If OverAllScore = 0.5 Then . . . "

/Fredrik


"Fredrik Wahlgren" wrote:


"Papa Jonah" wrote in message
...
I have a process with 42 pages of code. There are a boatload of calcs

in
it
that seem to be working.
However there is one that is giving me a hard time and I can't figure

it
out.
I have declarations: public overallscore as integer, public allscore

as
integer, and public totalscore as integer, and public dataset as

integer
I do not have any declarations for x.

OverAllScore = totalscore / dataset 'OverAllScore =0
x = totalscore / dataset ' x=-0.5
allscore = x 'allscore =0
If OverAllScore = 0.5 Then . . .

I am getting a value of -2 for totalscore and 4 for dataset. However
overallscore =0.
On the contrary x=-0.5 which is as expected. Then allscore ends up =0
instead of equal to x.

What am I possibly overlooking?

TIA



Use Double rather than integer. And declare x as Double, too. If you

divide
an integer value with another integer, the result will be an integer.

/Fredrik






Papa Jonah

vba calcs are acting funny
 
I don't understand what "double" is supposed to represent, but it works.
Thanks

"Fredrik Wahlgren" wrote:


"Papa Jonah" wrote in message
...
I am not sure I understand. Do you want me to decla
public x as double?


Yes. totalscore and dataset too

I understand that if I divide an integer by an integer, I get an integer -
so why don't I declare the result as an integer?


Becuse it doesn't make sense to compare an integer value with a decimal
value. That's what you do with "If OverAllScore = 0.5 Then . . . "

/Fredrik


"Fredrik Wahlgren" wrote:


"Papa Jonah" wrote in message
...
I have a process with 42 pages of code. There are a boatload of calcs

in
it
that seem to be working.
However there is one that is giving me a hard time and I can't figure

it
out.
I have declarations: public overallscore as integer, public allscore

as
integer, and public totalscore as integer, and public dataset as

integer
I do not have any declarations for x.

OverAllScore = totalscore / dataset 'OverAllScore =0
x = totalscore / dataset ' x=-0.5
allscore = x 'allscore =0
If OverAllScore = 0.5 Then . . .

I am getting a value of -2 for totalscore and 4 for dataset. However
overallscore =0.
On the contrary x=-0.5 which is as expected. Then allscore ends up =0
instead of equal to x.

What am I possibly overlooking?

TIA



Use Double rather than integer. And declare x as Double, too. If you

divide
an integer value with another integer, the result will be an integer.

/Fredrik







stanshoe

vba calcs are acting funny
 
Double is one of the many data types that VBA and Excel understand. A
variable defined as an integer will only accept whole numbers between -32,762
and 32,767. If you try to assign the number 40,000 to an "interger" variable
you will have a problem. A variable defined as "double" accepts a much
larger range of numbers including decimals. There are many other variable
types also. You can look up VBA Data Types to find more details.

By the way, an integer divided by an integer is not always an integer. 5 /
2 = 2.5 which is not an integer.

Stan Shoemaker
Palo Alto, CA

"Papa Jonah" wrote:

I don't understand what "double" is supposed to represent, but it works.
Thanks

"Fredrik Wahlgren" wrote:


"Papa Jonah" wrote in message
...
I am not sure I understand. Do you want me to decla
public x as double?


Yes. totalscore and dataset too

I understand that if I divide an integer by an integer, I get an integer -
so why don't I declare the result as an integer?


Becuse it doesn't make sense to compare an integer value with a decimal
value. That's what you do with "If OverAllScore = 0.5 Then . . . "

/Fredrik


"Fredrik Wahlgren" wrote:


"Papa Jonah" wrote in message
...
I have a process with 42 pages of code. There are a boatload of calcs

in
it
that seem to be working.
However there is one that is giving me a hard time and I can't figure

it
out.
I have declarations: public overallscore as integer, public allscore

as
integer, and public totalscore as integer, and public dataset as

integer
I do not have any declarations for x.

OverAllScore = totalscore / dataset 'OverAllScore =0
x = totalscore / dataset ' x=-0.5
allscore = x 'allscore =0
If OverAllScore = 0.5 Then . . .

I am getting a value of -2 for totalscore and 4 for dataset. However
overallscore =0.
On the contrary x=-0.5 which is as expected. Then allscore ends up =0
instead of equal to x.

What am I possibly overlooking?

TIA



Use Double rather than integer. And declare x as Double, too. If you

divide
an integer value with another integer, the result will be an integer.

/Fredrik








All times are GMT +1. The time now is 11:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com