Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calculations in VB (Word 97/VBA)

    Just a very quick guess (and I mean guess). What happens if you change .text to .value?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    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.
    Charlotte

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    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.
    Int discards any fractional portion.

    CInt casts the number passed to it as an Integer.
    Int returns the same data type that was passed to it.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •