How to slim down code...

HowdyDooDee
09-25-2007, 12:25 PM
Slim down this part of my code?

You helped me learn about parsing input to make sure it was in the right format when entered. But now I have these lines all over my script page, which is about 650 lines long now. Is the following possible, I am sure it is.

Thanks for all of your help.

I have several subs in my program, have tried to make a function to do the following, but couldn't get it to work. I tried the .parse extension and the .tryparse extension, neither one worked. I'm sure it is just something I don't understand yet about the code.

If Not Double.TryParse(tbOpeningWidth.Text, OpenWidth) Then
Return
End If
DoorWidth = (OpenWidth + 2) / 3

If Not Double.TryParse(tbOpeningHeight.Text, OpenHeight) Then
Return
End If

DoorHeight = OpenHeight + 1


I have this in appx. four subroutines, common sense tells me there has to be a way to send the values to a single function, parse them there,
and either:

1) send them to their destination on the Form directly from the Function or,
2) send them back to the subroutine they originated from for further manipulation.


I have another question about data entry and functions that none of my books seem to have an answer to. I have looked on the internet as well. It concerns resetting radiobuttons after doing a calculation when hitting the clear fields button to enter new figures.??????:huh:

Thx in advance.:confused:

AtmaWeapon
09-25-2007, 02:28 PM
The trouble is your logic requires a pattern like so:Parse the double.
If the parse succeeded, then
Save the value in this variable.
Evaluate this expression that uses the variable.
Otherwise, if the parse failed then
Do nothing.While the pattern itself is easy to define, it's difficult to implement a function that lets you define the expression that will be executed. There are solutions to this, but they are rather advanced and are probably overkill for your application.

The only thing I can suggest is that relying on the negative structure isn't really required, you could write the code like this and get the same results so long as that Return isn't to stop some code you haven't posted from running.If Double.TryParse(tbOpeningWidth.Text, OpenWidth) Then
DoorWidth = (OpenWidth + 2) / 3
End IfThis is still difficult to implement as a function, because passing the DoorWidth = (OpenWidth + 2) / 3 part into that function is an issue. I'm really drawing a blank on how you could do this via a function because even considering delegates you'd end up doing more work than you're already doing.

You probably just have to repeat the pattern.

HowdyDooDee
09-25-2007, 04:19 PM
Must use Return or it will let the user type in anything in the input boxes, although it will not finish the program...

BTW, was the last part of your post concerning the last question I asked?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum