Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > How to slim down code...


Reply
 
Thread Tools Display Modes
  #1  
Old 09-25-2007, 12:25 PM
HowdyDooDee HowdyDooDee is offline
Regular
 
Join Date: Aug 2007
Posts: 56
Question Hey AtmaWeapon, How can I...


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.??????

Thx in advance.

Last edited by HowdyDooDee; 09-25-2007 at 02:24 PM.
Reply With Quote
  #2  
Old 09-25-2007, 02:28 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

The trouble is your logic requires a pattern like so:
Code:
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.
Code:
If Double.TryParse(tbOpeningWidth.Text, OpenWidth) Then
    DoorWidth = (OpenWidth + 2) / 3
End If
This 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.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 09-25-2007, 04:19 PM
HowdyDooDee HowdyDooDee is offline
Regular
 
Join Date: Aug 2007
Posts: 56
Default

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?

Last edited by HowdyDooDee; 09-25-2007 at 04:21 PM. Reason: add comments
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->