Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 12th, 2009, 09:31 PM
Authorized User
Join Date: Mar 2008
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Question A little optimization puzzle

I think some of you may have learned how to make the following nested If more compact, maybe in an algorithms discussion in school or some such place. If so I'd like to learn the trick. It is an example of a situation I run into occasionally. Or, maybe the code cannot be further reduced and I'm looking for something needlessly. (The code works fine as is.) I had one person give me an incorrect reduction but I'm still curious to see if anyone can teach me something.

bFileMissing = False ' Initialize
If (CantFindFile(sName)) Then
____If bCheckOtherPlace Then
________Call SwitchLocation(sName)
________If (CantFindFile(sName)) Then
____________bFileMissing = False
____________bFileMissing = True
________End If
________bFileMissing = True
____End If
____bFileMissing = False
End If

If bFileMissing Then MsgBox "Not Found"

(by the way, how do you overcome the whitespace eliminator and show indentation in examples without doing what I just did?)

Last edited by williamlove; October 12th, 2009 at 11:18 PM..
Old October 13th, 2009, 12:09 AM
Authorized User
Join Date: Mar 2009
Posts: 49
Thanks: 0
Thanked 8 Times in 8 Posts

see my answer to this Q in... http://www.xtremevbtalk.com/showthread.php?t=311144

Good Luck
Old October 18th, 2009, 02:17 AM
Registered User
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

set bFileMissing=true only when it satisfies the condition.
as bFileMissing=false is initialized prior to the execution of "nested if" filter, no need to set it again to false.

Similar Threads
Thread Thread Starter Forum Replies Last Post
puzzle for date ranges navjot C# 1 October 16th, 2008 02:21 PM
A small puzzle marianeeli C++ Programming 9 September 5th, 2006 12:02 AM
DataAdapter.Update puzzle wirerider ASP.NET 2.0 Basics 1 August 1st, 2006 06:57 PM
Join table puzzle... vanjamier SQL Language 1 November 26th, 2004 04:43 AM
Crossword Puzzle Euler C++ Programming 4 October 19th, 2004 02:08 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.