Still a problem

WackoWolf

Active member
Joined
Jan 6, 2006
Messages
39
Location
Rhode Island
Programming Experience
Beginner
Why is it when I try to make it a Const it gives me the error that "Expression Expected" when I try to muply? Here is my code, I am trying to do this the right way but am have problems. I can do it without useing a Const and it works, but I want to set things as Const. I get the error on the * part only. Please could someone explain what I am doing wrong and the right way to do it, I also want to do it to "Children.

Thank You
WackoWolf

VB.NET:
[SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] Adult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 30
 
[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Children [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 10
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Night [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] NightlyRate [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Total [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2]TextAdult.Text * Adult
Children = (TextChildren.Text * Children)
Night = (Val(TextNight.Text))
NightlyRate = (Adult + Children) * Night
Total = (NightlyRate * 0.05) + NightlyRate
TextTotal.Text = FormatCurrency(Total)
 
[/SIZE]

 
this is a problem line:
VB.NET:
[COLOR=red]TextAdult.Text * Adult[/COLOR]
you have to assign that expression result somewhere:
VB.NET:
[COLOR=blue]dim adultresult as integer = TextAdult.Text * Adult[/COLOR]
from what I understand you tried to do this:
VB.NET:
[COLOR=red]Adult = TextAdult.Text * Adult[/COLOR]
and that is something you can not do with a constant, because it is a constant it can not change.
 
Thank You..I understand how it has to be done now. I do understand what the "Const" means and does just wasn't sure as to how to write it in code. But after the way you show me I was able to do it for "Children" also. This is what I now have and it work without a problem.

VB.NET:
[SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] Adult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 30
[/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] Children [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 10
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Night [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] NightlyRate [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Total [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] adultresult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = (Val(TextAdult.Text * Adult))
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Childrenresult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = (Val(TextChildren.Text * Children))
 
Night = (Val(TextNight.Text))
NightlyRate = (Adult + Children) * Night
Total = (NightlyRate * 0.05) + NightlyRate
TextTotal.Text = FormatCurrency(Total)
[/SIZE]

Later I will start with the third part, this is an on going project.
 
Dam...Now the calculations are wrong, what did I do. I didn't change anything else, I am haveing that much trouble just trying to make thing a "Const". HELP
 
I figure it out sorry. I forgot to add result to "Adult" and to "Children"
This is what I have now and everything works, I just ran it.

Thank You all for putting up with me.

VB.NET:
[SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] Adult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 30
[/SIZE][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][SIZE=2] Children [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 10
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Night [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Double
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] NightlyRate [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Total [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Decimal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] adultresult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = TextAdult.Text * Adult
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Childrenresult [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = TextChildren.Text * Children
 
Night = (Val(TextNight.Text))
NightlyRate = (adultresult + Childrenresult) * Night
Total = (NightlyRate * 0.05) + NightlyRate
TextTotal.Text = FormatCurrency(Total)
 
[/SIZE]


 
Back
Top