|
-
Oct 15th, 2000, 04:28 AM
#1
Thread Starter
Junior Member
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
-----------------------------------
-
Oct 15th, 2000, 07:38 AM
#2
Addicted Member
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
-
Oct 15th, 2000, 01:16 PM
#3
Thread Starter
Junior Member
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
-----------------------------------
-
Oct 15th, 2000, 01:16 PM
#4
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
-
Oct 15th, 2000, 04:47 PM
#5
Thread Starter
Junior Member
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
-----------------------------------
-
Oct 15th, 2000, 05:09 PM
#6
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|