?
Solved

Is there a keyboard shortcut to display the end of a statement?

Posted on 2001-06-18
15
Medium Priority
?
226 Views
Last Modified: 2010-05-02
Is there a keyboard shortcut to display the end of a statement in Visual Basic?  For example, if I highlight "If" is there a shortcut that will show me which "End If" matches it?
0
Comment
Question by:joesmow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6204372
Not aware of one through VB6.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6204456
I don't think it is possible with Visual Basic. I know it is possible with Visual C++ like if we place our cursor at the { and we just have to hit Ctrl-] to move the cursor to the close }.

if true
{
     printf("S");
}

hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6204463
I know that it is possible to use a shortcut key to navigate through procedures or functions but hitting the Ctrl-Up or Ctrl-Down. Place your cursor at the Private Sub point and then hit Ctrl-Up to move the the function or procedure above this procedure or Ctrl-Down to move to the next procedure or function.

hongjun
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6204768
Along the lines of more commentary that doesn't answer your question, you could always use vi.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6206970
If you're looking for a way to simplify your code and make it more readable, I suggest the following:

1) Indent all IF/FOR/SELECT-CASE/WITH blocks (and even SUB/FUNCTION) such as:

private sub qqq(abc as boolean)
....dim xxx as integer
....'
....if abc then
........for xxx=1 to 10
............debug.print xxx
........next xxx
....else
........for xxx=10 to 1 step -1
............debug.print xxx
........next xxx
....end if
end sub

2) When an if block gets nested too deeply, or has a excess number of commands, consider converting part of it into a new procedure (which may require passing variable values or creating module-level variables):

if abc then
    if def or ghi then
        if jkl and mno then
           debug.print 1
        else
           debug.print 2
        end if
    else
        if pqr and stu then
           debug.print 3
        else
           debug.print 4
        end if
    endif
elseif vwx then
   debug.print 5
end if

This could be re-written as:

if abc then
   NewProcedure
elseif vwx then
   debug.print 5
end if

...
Private Sub NewProcedure()
    if def or ghi then
        if jkl and mno then
           debug.print 1
        else
           debug.print 2
        end if
    else
        if pqr and stu then
           debug.print 3
        else
           debug.print 4
        end if
    endif
end sub

3) Use a tool which will automatically indent your code for you.
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6207947
rspahitz - do you know of any good code prettifiers out there?

joesmow - it wouldn't be too hard to write an IDE add-in to do this, but I don't know of any out there. Manual indentation and a sharp eye is what I use.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6208062
I seem to remember VB Advantage doing something like this, but I'm not sure.

And I'd written such a tool for a different version of Basic I was using ten years ago.

It shouldn't really be too hard to write a decent one:

* request a .frm/.cls/.bas file
* scan through the code for specific keywords
* If they're found, either add to an indent variable (If/For/Select Case/Sub/Function), or subtract (End/next/end select/end sub/end function)

The "gotchas" will be single-line IF statements, maybe continuation lines, keywords after the first word (Private Sub), and maybe comments.  Also, make sure to search through the file until you find the code portion, which comes after the form definition for .frm.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6208634
You can always indent your coding when you are coding in the code window along the way. Isn't it? That would be a good programming practice, isn't it? For your information, you can always select/highlight multiple lines of code and then do a tab to indent.

hongjun
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6209712
rspahitz - thanks, I wrote a prettifier for pascal many moons ago in college, but I might have a look into doing a quick add-in at some point for VB.
I obsessively indent while coding, but if I have to look at somebody else's code, I run through the code first indenting it correctly before I even start to look at what it's doing.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6211037
"I run through the code first indenting it correctly before I even start"

Me too.  I can't stand code that is sloppily organized...it implies that the code is self is sloppy and waiting to break...
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6211622
I remember my old 'team leader' getting his hands dirty with a chunck of code. Yep, you guessed it, all down the left of the screen - I did not hold back with my sarcasm ;)
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6217800
So I conclude there's really nothing that can be done in VB but can be in VC. Indent it along the way.

hongjun
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 200 total points
ID: 6219068
Well...not nothing.
From a given IF, you can always "find" the next END IF.  As long as it's the innermost IF block, then you can highlight and press tab to indent that particular IF.

Also, a tip from my co-worker:

Any time you end a long block, add a comment that references back to the starting block.  Ex.:

Private Sub XYZ()
'... lots of code
End Sub XYZ

If XXX=1 then
'... lot of code
End If ' XXX=1

Select Case ZYX
   '... lots of cases
End Select ' ZYX
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6220409
>>you can highlight and press tab to indent that particular IF.

That's is provided by my third comment.

hongjun
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6220760
Hey JoeSmow did you abandon this discussion?  Not a peep from you since the question and I think we've pretty much beat this one to death.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question