PDA

View Full Version : # range


Inugami
09-26-2006, 10:13 PM
what do i put in the source code so that for example: value 0-4.4 will only work in a textbox when entered? Im learning visual basic.net atm... The book i am using is probably known by alot... "An introduction to Programming" --->Lawrenceville Press~ If you have it its 4-24, exercise1. The question is:


The height of an object at any given time dropped from a starting height of 100meters is given by the equation h=100-4.9*t[2] where t is the time in seconds. Create an object height application that prompts the user for a time less than 4.5 seconds and then displays the height of the object at that time when Height is clicked. The application should look similar to:.... well you cant see it since its in the book, but thats the question anyways.

Eriond
09-26-2006, 11:06 PM
Do you want them not to be able to enter it, or do you want a message box to pop up when they click ok, saying that they must enter a number between 0 - 4.4?

FlawedSin
09-26-2006, 11:14 PM
I dont understand your question either.

Inugami
09-26-2006, 11:14 PM
could you show me both please? I really want to know :p

I dont understand your question either.

Im asking how do i make it so that you can only enter/calculate if the value entered in the textbox is 0 to 4.4

Eriond
09-27-2006, 01:21 AM
Lol, well... I've never used VB, but I have worked with the Win32 API...

So, I only know how to do the messagebox one.

First, get the value from the textbox (GetWindowText in C), and then convert it to a float (atof in C). Then check if


float var = atof(string);
if ( var > 0.0f && var <= 4.4 )
<Actions>
else
MessageBox(<Window Handle>,<App Name>,"You must enter a value between 0.0 and 4.4!", MB_OK);

That's how I'd do it in C. Hope that helps you. It should be similar in VB.

Inugami
09-27-2006, 01:27 AM
well its a lil complicated but i can understand some parts of that.

FlawedSin
09-27-2006, 04:42 AM
why not just do this

when you click there have it check if

If NUMBER < 4.5 Then

NUMBER is the variable you have it set it to.

Then it checks if your number is from 4.4 to 0.

Eriond
09-27-2006, 09:19 PM
That's basically what I said, but it's a bit more complciated than that, because message box stuff is in the format of a character string, so it has to be converted. But yeah, absicaly that's it.

FlawedSin
09-27-2006, 10:40 PM
no making a message box is pretty simple in VB

im not sure whats all different in .net but I think they are similar

if you want to know how to make a message box let me know and I will post the code