Results 1 to 6 of 6

Thread: Need Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Unhappy

    Hello I'm new to this forum. I do however have one that I visit on a regular basis. But, it has nothing to do with VB. First I'm a college student trying to earn his degree in computer science. I'm also kinda new to VB. I'm working on this class project called the Calorie Counter. I'm having probs with it when I press the Calculate button. What it it says is this "Compile Error, Variable not Defined" I am confused and frustrated with doing these darn Calculators. If some one would be kind enough to possibly help me out with this little prob, I would be greatfull.

    Thanx Neo1008
    Free Your Creative Spirit
    -----------------------------------

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132

    Wink

    Hi Neo1008!!!

    I'm sure you have a typo.
    This error message says that you have not declared a variable before you using it. (see also VB-HELP "DIM")

    -cu TheOnly

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Cool VB ?

    Thanx TheOnly. I just do not like coding Calculators. I hate having to do the math. HEHEHEHEHEHEHEHEHE. I do not know of very many that do.

    Neo1008
    Free Your Creative Spirit
    -----------------------------------

  4. #4
    Guest
    You probably have the Option Explicit statement in your code. In such case, you must declare all your variables.
    Code:
    Dim MyVar As Integer    'Declare our variable first
    
    MyVar = 5 + 5

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    OptionExplicit

    Yep, That's how our instuctor wants it. If she does not see that in our code, We get a fail for the project. Anyway here is the code.

    Code:
    ---------------------------------------------------------
    'Project            Chapter 3.1 Sample Calorie Counter
    'Date               10-11-2000
    'Programmer         Brian Kidd
    'Description        This project calculates the fat and
    '                   carbohydrates , proteins and gives
    '                   total in the oppropiate fields.
                        
                        
                        
                    
    Option Explicit
        'Dimension module-level variables
        
        Dim mintItems_Entered As Integer
        Dim mintTotal_Calories As Integer
        
    Private Sub cmdCalculate_Click()
        'Calculates the fats, proteins, carbohydrates
        
           Const intFats As Integer = 9
           Const intProteins As Integer = 4
           Const intCarbohydrates As Integer = 4
           Dim intSum_Of_Calories As Integer
           Dim intCountCalories As Integer
        
        'Convert input values to numeric Variables
        
        intFats = Val(txtFats.Text)
        intProteins = Val(txtProteins.Text)
        intCarbohydrates = Val(txtCarbohydrates.Text)
    
        
        'Calculate Values
        
    
        intItems_Entered.Caption = (intFats * 9) + (intProteins * 4) + (intCarbohydrates * 4)
        intSum_Of_Calories = mintTotal_Calories + intSum_Of_Calories
        intTotal_Calories = mintItems_Entered + 1
        
        
        'Format and display Sum and Total, Number of Items
        
        lblItems_Entered.Caption = Format(mintItems_Entered)
        lblSum_Of_Calories.Caption = Format(intSum_Of_Calories)
        lblTotal_Calories.Caption = Format(mintTotal_Calories)
        
        
    End Sub
    
    Private Sub cmdExit_Click()
        'Exit and quit program
        
        End
    End Sub
    
    Private Sub cmdPrint_Click()
        'Prints the form
        
        PrintForm
    End Sub
    
    Private Sub cmdReset_Click()
        'Clears the Text areas and Label areas
        
        txtFats.Text = ""
        txtProteins.Text = ""
        txtCarbohydrates.Text = ""
        lblItems_Entered.Caption = ""
        lblSum_Of_Calories.Caption = ""
        lblTotal_Calories.Caption = ""
        
        'Sets cursor focus back to tab 0
        
        txtFats.SetFocus
    End Sub
    I am not sure what's wrong here.
    Free Your Creative Spirit
    -----------------------------------

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    First of all I get an error message that you can't assign values to constants (think that's true!)

    second:
    intTotal_Calories = mintItems_Entered + 1
    is not defined.
    You say mintTotal_Calories!

    In the VB IDE press CTRL + F5 to catch all compile errors!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

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



Click Here to Expand Forum to Full Width