# Thread: Calculations in VB (Word 97/VBA)

1. ## Calculations in VB (Word 97/VBA)

I have a project that I thought was working fine. I had declared the variables as integers. In one text box, the user will type a number. The macro then checks to see if the number is higher than 3. If it is, it subtracts 3 from that number and creates a variable called "IndExtra". Sounds simple enough. However, the macro works fine if the number is 1-9 or anything higher than 29....but won't calculate anything from 10-29 inclusive, this is extremely puzzling.

I have declared an variable called "Individual" as an integer.
Individual = frmPTO1390.TextBox2.Text
I have even tried:
Individual = Int(frmPto1390.TextBox2.Text)

I then have a statement similar to:
If Individual > 3 Then
do this routine
End If

What am I doing wrong here??? As always, thanks for your excellent advice.

2. ## Re: Calculations in VB (Word 97/VBA)

Just a very quick guess (and I mean guess). What happens if you change .text to .value?

3. ## Re: Calculations in VB (Word 97/VBA)

You're going to have to tell us what you mean by it not calculating values in that range. Do you get an error message or what happens? I would suspect the logic you're using in your macro if it isn't calculating that range properly. Something like this should work:

Dim Individual as Integer
Dim IndExtra as Integer

Individual = Val(frmPT01390.TextBox2.Text)
If Individual > 3 Then
IndExtra = Individual - 3
End If

You could also use CInt instead of Val since you're working with an integer value anyhow. If it doesn't work, then the problem is the way you're referencing the textbox. I assumed here that your reference to the form name was correct.

4. ## Re: Calculations in VB (Word 97/VBA)

Bless you Charlotte! What a simple thing...when I changed Int to Val -- it worked perfectly. This novice very much appreciates your assistance!

5. ## Re: Calculations in VB (Word 97/VBA)

The following nuggets are gleaned from "VB&VBA In a Nutshell" (O'Reilly) - in case they are useful:

CInt rounds any fractional portion of the number.