473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to find the end of an 'If/End If' block like C# (vs2005)?

Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If / End
If blocks and have a hard time finding the end End If. How to do this?

Thanks,
Rich
Nov 6 '07 #1
8 1621
On Nov 6, 12:47 pm, Rich <R...@discussions.microsoft.comwrote:
Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If / End
If blocks and have a hard time finding the end End If. How to do this?

Thanks,
Rich
No, I don't believe so.

Personally, I would say if you have a if..then block that is that long
(or that deeply nested) you need to re-design it's functionality. I
would venture a guess that it would be a maintenance nightmare and the
cost of the rewrite would be much less than the cost of maintaining
that code. Is there any reason you can't simplify the logic, or even
wrap the various parts in separate methods?

Thanks,

Seth Rowe

Nov 6 '07 #2
Example:

If some condition is true then
Dim da As New SqlDataAdapter,...
da.SelectCommand = New SqlCommand
da.InsertCommand = New SqlCommand
...
da.InsertCommand.Parameters.Add(...)
...
da.InsertCommand.Parameters.Add(...)
....
If conn.State = ConnectionState.Closed Then conn.Open
...
da.SelectCommand.ExecuteNonQuery
...
da.Update(ds, "someTbl")
...
End If
...
If conn.State = ConnectionState.Open Then conn.Close
....
End If

I supposed I could write a bunch of little subs and functions to handle the
stuff, but that would be more stuff to maintain and bounce around when I have
to debug or update something. Some of these If blocks might have 50 lines
which isn't that bad except when you have a bunch of nested if statements.
Well, I guess I can use bookmarks.
"rowe_newsgroups" wrote:
On Nov 6, 12:47 pm, Rich <R...@discussions.microsoft.comwrote:
Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If / End
If blocks and have a hard time finding the end End If. How to do this?

Thanks,
Rich

No, I don't believe so.

Personally, I would say if you have a if..then block that is that long
(or that deeply nested) you need to re-design it's functionality. I
would venture a guess that it would be a maintenance nightmare and the
cost of the rewrite would be much less than the cost of maintaining
that code. Is there any reason you can't simplify the logic, or even
wrap the various parts in separate methods?

Thanks,

Seth Rowe

Nov 6 '07 #3

"Rich" <Ri**@discussions.microsoft.comwrote in message
news:6B**********************************@microsof t.com...
Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If /
End
If blocks and have a hard time finding the end End If. How to do this?

Thanks,
Rich
Have a look at a product called Refactor Pro from DevExpress. It graphicaly
connects all related blocks of code (as well as many other features). I find
this product indispensible
Nov 6 '07 #4
On Nov 6, 2:40 pm, Rich <R...@discussions.microsoft.comwrote:
Example:

If some condition is true then
Dim da As New SqlDataAdapter,...
da.SelectCommand = New SqlCommand
da.InsertCommand = New SqlCommand
...
da.InsertCommand.Parameters.Add(...)
...
da.InsertCommand.Parameters.Add(...)
....
If conn.State = ConnectionState.Closed Then conn.Open
...
da.SelectCommand.ExecuteNonQuery
...
da.Update(ds, "someTbl")
...
End If
...
If conn.State = ConnectionState.Open Then conn.Close
...
End If

I supposed I could write a bunch of little subs and functions to handle the
stuff, but that would be more stuff to maintain and bounce around when I have
to debug or update something. Some of these If blocks might have 50 lines
which isn't that bad except when you have a bunch of nested if statements.
Well, I guess I can use bookmarks.

"rowe_newsgroups" wrote:
On Nov 6, 12:47 pm, Rich <R...@discussions.microsoft.comwrote:
Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If / End
If blocks and have a hard time finding the end End If. How to do this?
Thanks,
Rich
No, I don't believe so.
Personally, I would say if you have a if..then block that is that long
(or that deeply nested) you need to re-design it's functionality. I
would venture a guess that it would be a maintenance nightmare and the
cost of the rewrite would be much less than the cost of maintaining
that code. Is there any reason you can't simplify the logic, or even
wrap the various parts in separate methods?
Thanks,
Seth Rowe- Hide quoted text -

- Show quoted text -
Actually, looking at your code I can make three suggestions. First,
don't trust the ConnectionState property, it only returns what it
*thinks* it's state is. It may return that it is Open, and then throw
an exception because it's closed whenever you use it. I highly
recommend you ditch the if...then test and just use a try catch block
to make sure every succeeds. Secondly, I would remove the "If
conn.State = ConnectionState.Open Then conn.Close" block and wrap the
whole sucker in a using block. Then you can ensure that it will
properly close itself and release any non-managed resources. Lastly,
the other Db object should also be disposed of when you are finished
with them. I would recommend you use a Using block, but you could also
use a try...finally structure too. Disposing is a hotly debated topic,
but in my opinion is what you should do to ensure smooth and
performant execution of your code.

Thanks,

Seth Rowe

Nov 6 '07 #5
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11********************@d55g2000hsg.googlegrou ps.com...
On Nov 6, 2:40 pm, Rich <R...@discussions.microsoft.comwrote:
>Example:

If some condition is true then
Dim da As New SqlDataAdapter,...
da.SelectCommand = New SqlCommand
da.InsertCommand = New SqlCommand
...
da.InsertCommand.Parameters.Add(...)
...
da.InsertCommand.Parameters.Add(...)
....
If conn.State = ConnectionState.Closed Then conn.Open
...
da.SelectCommand.ExecuteNonQuery
...
da.Update(ds, "someTbl")
...
End If
...
If conn.State = ConnectionState.Open Then conn.Close
...
End If

I supposed I could write a bunch of little subs and functions to handle
the
stuff, but that would be more stuff to maintain and bounce around when I
have
to debug or update something. Some of these If blocks might have 50
lines
which isn't that bad except when you have a bunch of nested if
statements.
Well, I guess I can use bookmarks.

"rowe_newsgroups" wrote:
On Nov 6, 12:47 pm, Rich <R...@discussions.microsoft.comwrote:
Is it possible to find the end of an If block in VB2005 -- similar to
C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long
If / End
If blocks and have a hard time finding the end End If. How to do
this?
Thanks,
Rich
No, I don't believe so.
Personally, I would say if you have a if..then block that is that long
(or that deeply nested) you need to re-design it's functionality. I
would venture a guess that it would be a maintenance nightmare and the
cost of the rewrite would be much less than the cost of maintaining
that code. Is there any reason you can't simplify the logic, or even
wrap the various parts in separate methods?
Thanks,
Seth Rowe- Hide quoted text -

- Show quoted text -

Actually, looking at your code I can make three suggestions. First,
don't trust the ConnectionState property, it only returns what it
*thinks* it's state is. It may return that it is Open, and then throw
an exception because it's closed whenever you use it. I highly
recommend you ditch the if...then test and just use a try catch block
to make sure every succeeds. Secondly, I would remove the "If
conn.State = ConnectionState.Open Then conn.Close" block and wrap the
whole sucker in a using block. Then you can ensure that it will
properly close itself and release any non-managed resources. Lastly,
the other Db object should also be disposed of when you are finished
with them. I would recommend you use a Using block, but you could also
use a try...finally structure too. Disposing is a hotly debated topic,
but in my opinion is what you should do to ensure smooth and
performant execution of your code.

Thanks,

Seth Rowe
Well stated, Seth. The "Using" block is a great friend. Clean and efficient.
In interviewing five different developers for a position in our development
team, none were familiar with this construct. For those who are interested,
even in a "Try/Catch" block, when an error occurs, the "End Using" statement
is always executed (like a "Finally" statement). The only caveat to using a
"Using" block, is that the object needs to implement IDsposable.

For the newbies (like me?) IDisposable is eay to implement. Just put the
line "Implements IDisposable" at the beginning of your class and press
enter. The necessary code is added to your class automatically.

e.g.

Using myObject as New FixEverything(DB_Connect_String, pointer)
With myObject
.NewDataA = "Bloody beautiful"
.Save 'call the save method
End With
End Using

You can also nest "Using"
Nov 7 '07 #6
Agreed,

If any method has much more than a screenfull of code it needs to be looked
at...

Guy

"rowe_newsgroups" wrote:
On Nov 6, 12:47 pm, Rich <R...@discussions.microsoft.comwrote:
Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If / End
If blocks and have a hard time finding the end End If. How to do this?

Thanks,
Rich

No, I don't believe so.

Personally, I would say if you have a if..then block that is that long
(or that deeply nested) you need to re-design it's functionality. I
would venture a guess that it would be a maintenance nightmare and the
cost of the rewrite would be much less than the cost of maintaining
that code. Is there any reason you can't simplify the logic, or even
wrap the various parts in separate methods?

Thanks,

Seth Rowe

Nov 7 '07 #7
You can also nest "Using"

As well as list two, or more, IDisposable objects in one statement:

/////////
Using conn As new SqlConnection, com As SqlCommand =
conn.CreateCommand()

End Using
/////////

When you have multiple IDisposable objects the above provides a bit
"cleaner" way (imo) for using Using statements (pun intended). Not to
mention it prevents having to scroll sideways to view a deeply nested
Using block.

Thanks,

Seth Rowe

Nov 7 '07 #8
Rich,

I go in VB.Net mostly much deeper in blocks then in C#.

I never needed any tool to find the end of an If, a for loop or whatever in
VB.Net, something that I have often trouble with in C# while busy.

The way as the C# syntax is build and (although better now) the lack of
automatic build in features, make in my idea this kind of all not to
remember gadgets in C# needed.

If it is in VB.Net then I probably would never use it as I seldom use
gadgets. I never have problems to find the end of such a block in VB.Net
even if it is 20 or more deep.

And as you can see, I am against all that building of one time used private
methods, in my idea does it make programs less readable.

Cor
"Rich" <Ri**@discussions.microsoft.comschreef in bericht
news:6B**********************************@microsof t.com...
Is it possible to find the end of an If block in VB2005 -- similar to C#
where in C# if you place your cursor next to a bracket and press ctrl
something it highlights the ending bracket? I have some fairly long If /
End
If blocks and have a hard time finding the end End If. How to do this?

Thanks,
Rich
Nov 8 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rob Dob | last post by:
Hi, I have a VS2003 C# asp.net project that has been converted into a VS2005 project. Everything seemed to work well until I make a modification to anything within the Component Designer...
5
by: GaryDean | last post by:
(my original post was inaccurate but this post accurately describes what I think is a very bad vs2005 bug) short description... Deleting a dataset and recreating it from the dataadapter causes...
7
by: Frank Rizzo | last post by:
Is it me or is the speed of VS2005 actually slower than VS2003? The startup is pretty bad - even though I changed VS to display an empty environment. When I create a new form and want to change...
6
by: **Developer** | last post by:
I can't find how to search an entire solution for a string, say "Sub (ByRef" Nor how to search the entire solution using Regular Expressions. These were my favorite things - please don't tell me...
5
by: peter | last post by:
Hello all, I'm looking for an advice. Example (one block in ascii file): $------------------------ NAME='ALFA' CODE='x' $------------------------
43
by: Frodo Baggins | last post by:
Hi all, We are using strcpy to copy strings in our app. This gave us problems when the destination buffer is not large enough. As a workaround, we wanted to replace calls to strcpy with strncpy....
2
by: moondaddy | last post by:
I had to repost this because I had to update and change my msdn alias. I will re-ask the question and clarify a few things that were not clear before. This code is all executed on my dev...
8
by: Dennis | last post by:
How do you comment out a block of VB.Net code in VS2005? It seems to me in an earlier version of VS I just ran the CommentRegion macro from the Macro Explorer. But in VS2005 that does nothing. ...
0
by: =?Utf-8?B?Si4gUmF5bW9uZA==?= | last post by:
Hi, Is it possible to specify a configuration file other than the default «ABC.exe.config»? In others words, I would like the application logging block to use a customized configuration...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.