Solved

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

Posted on 2001-06-18
15
221 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
  • 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 50 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

770 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