Basic percentage calculation help.

tengu

New member
Joined
Oct 20, 2006
Messages
4
Programming Experience
Beginner
First off, Hello.:D

I am just starting out in programming and am still finding my feet so if anyone can help with what I am sure are my pretty noobish questions It's probably best if they pitch their answers at a toddler type level.:eek:

The first problem I have is with construction of formula, I am trying to take a value (a) add 10% of (a) to (a) and then compare it to value (b).

I was trying to use
If a + a / 100 * 10 <= b Then

The message the formula then repeats using , IF Else, for 20%, 30% etc.

The problem is that the message I want out put for the 10% comparison is always returned regardless of the value of (a).

I realise that the above description is not the most succinct, but ihope you can help.

Tengu.
 
I'm not entirely sure what you mean by

VB.NET:
The problem is that the message I want out put for the 10% comparison is always returned regardless of the value of (a).

But when doing maths anywhere, not just in programming. To evaluate an expression inside an expression you need to enclose it in brackets.....

VB.NET:
If (a + (a / 100 * 10)) <= b Then
 
vis781,
Thanks for the reply, sorry it took me so long to get back to you about it, work got in the way.

As to the vagueness of my question, I can only put that down to the fact that I had been staring at the same piece of code for four hours trying to spot the fault. The old brain was starting to give up the ghost on all fronts.:rolleyes:

The answer turned out to be simple, my mathematical ability sucks!

I do however have a new question if anyone wants to help.

Textbox1 shows todays date and time. (TextBox1.Text = Date.Now)


Textbox2 recieves a date from the user.

How can I get rid of the time that is displayed in textbox1 so that it just displays the date.

And...


Is datediff the correct method to compare the two dates and give me the difference between them in days?

Thanks in advance.

Tengu.
 
Use .ToShortDateString or .ToLongDateString on the date instance to get only date parts of it. (Date.Now.ToLongDateString for example)

DateDiff should not be used. Instead use the Subtract method of the Date instance, it will return an instance of TimeSpan you can interrogate further for the info.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] date1 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2].Now[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] date2 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2].Now.AddDays(1)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] diffdate [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] TimeSpan = date2.Subtract(date1)[/SIZE]
[SIZE=2]MsgBox(diffdate.TotalHours.ToString)[/SIZE]
 
Thanks for that John.

The date from the systemclock is now in the correct format.

I am having a bit of trouble getting a third textbox to display the difference in days, but thats why I have a pile of books 3 foot high.

Thanks for pointing me in the right direction.

Tengu.
 
Back
Top