Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Newbie General Programming ??

Hi; Just Wondering;

Does it really make a difference if you don't test for a previous condition
before making a change to a format etc. in VBA? For example, will I hurt
anything or endager anything if I just do:

'Make condition = True' no matter if the existing condition has already been
met, rather than:

'If condition = False Then make condition = True'

It seems sometimes I spend a lot of coding time look for the state of
conditions when I really don't care. I just want everything to be the same.

Regards Bill
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Newbie General Programming ??

specifics would be better, but in general, if you don't care what the current
condition is and you want the situation to be a specific condition
regardless, there is no reason to check.

Range("a1:B6").name = "MyName"

will create MyName if it didn't exist and redefine it if it did as an
example.

Another example. If I want to put a file in a subdirectory, if I know the
the higher level directory is there (C:\Data in the example), I can do

' ignore the error if it already exists
On error resume next
mkdir "C:\Data\Subdir"
On error goto 0
Activeworkbook.SaveAs "C:\Data\Subdir\MyFile.xls"

You then don't have to check if SubDir exists before doing this.

--
Regards,
Tom Ogilvy




"Bill Case" wrote:

Hi; Just Wondering;

Does it really make a difference if you don't test for a previous condition
before making a change to a format etc. in VBA? For example, will I hurt
anything or endager anything if I just do:

'Make condition = True' no matter if the existing condition has already been
met, rather than:

'If condition = False Then make condition = True'

It seems sometimes I spend a lot of coding time look for the state of
conditions when I really don't care. I just want everything to be the same.

Regards Bill

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Newbie General Programming ??

Thanks Tom;

Yes , that was the kind of gerneral answer I was looking for. You may
rember in one of my previous posts that I had some beginners general
programming questions. You suggested I could ask on this list. So I just
did. That question was one of them.

Regards Bill

"Tom Ogilvy" wrote:

specifics would be better, but in general, if you don't care what the current
condition is and you want the situation to be a specific condition
regardless, there is no reason to check.

Range("a1:B6").name = "MyName"

will create MyName if it didn't exist and redefine it if it did as an
example.

Another example. If I want to put a file in a subdirectory, if I know the
the higher level directory is there (C:\Data in the example), I can do

' ignore the error if it already exists
On error resume next
mkdir "C:\Data\Subdir"
On error goto 0
Activeworkbook.SaveAs "C:\Data\Subdir\MyFile.xls"

You then don't have to check if SubDir exists before doing this.

--
Regards,
Tom Ogilvy




"Bill Case" wrote:

Hi; Just Wondering;

Does it really make a difference if you don't test for a previous condition
before making a change to a format etc. in VBA? For example, will I hurt
anything or endager anything if I just do:

'Make condition = True' no matter if the existing condition has already been
met, rather than:

'If condition = False Then make condition = True'

It seems sometimes I spend a lot of coding time look for the state of
conditions when I really don't care. I just want everything to be the same.

Regards Bill

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Newbie General Programming ??

No problem.
It wasn't a criticism - just a caution that a general answer might not be
true in a specific situation - so if you had a specific situation in mind,
blah blah :-)

--
Regards,
Tom Ogilvy

"Bill Case" wrote in message
...
Thanks Tom;

Yes , that was the kind of gerneral answer I was looking for. You may
rember in one of my previous posts that I had some beginners general
programming questions. You suggested I could ask on this list. So I just
did. That question was one of them.

Regards Bill

"Tom Ogilvy" wrote:

specifics would be better, but in general, if you don't care what the
current
condition is and you want the situation to be a specific condition
regardless, there is no reason to check.

Range("a1:B6").name = "MyName"

will create MyName if it didn't exist and redefine it if it did as an
example.

Another example. If I want to put a file in a subdirectory, if I know
the
the higher level directory is there (C:\Data in the example), I can do

' ignore the error if it already exists
On error resume next
mkdir "C:\Data\Subdir"
On error goto 0
Activeworkbook.SaveAs "C:\Data\Subdir\MyFile.xls"

You then don't have to check if SubDir exists before doing this.

--
Regards,
Tom Ogilvy




"Bill Case" wrote:

Hi; Just Wondering;

Does it really make a difference if you don't test for a previous
condition
before making a change to a format etc. in VBA? For example, will I
hurt
anything or endager anything if I just do:

'Make condition = True' no matter if the existing condition has already
been
met, rather than:

'If condition = False Then make condition = True'

It seems sometimes I spend a lot of coding time look for the state of
conditions when I really don't care. I just want everything to be the
same.

Regards Bill



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
General programming help Erik Excel Programming 5 February 8th 06 08:41 PM
newbie needs help in Ezcel programming Amy Excel Discussion (Misc queries) 1 March 22nd 05 02:18 PM
newbie needs help in Ezcel programming Amy Excel Discussion (Misc queries) 0 March 22nd 05 02:17 PM
newbie programming Josh Ashcraft Excel Programming 1 July 16th 03 08:20 PM


All times are GMT +1. The time now is 09:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"