Solved

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

Posted on 2001-06-18
15
219 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now