[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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

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
joesmow
Asked:
joesmow
  • 5
  • 4
  • 3
  • +1
1 Solution
 
DRRYAN3Commented:
Not aware of one through VB6.
0
 
hongjunCommented:
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
 
hongjunCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
DRRYAN3Commented:
Along the lines of more commentary that doesn't answer your question, you could always use vi.
0
 
rspahitzCommented:
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
 
andyclapCommented:
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
 
rspahitzCommented:
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
 
hongjunCommented:
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
 
andyclapCommented:
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
 
rspahitzCommented:
"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
 
andyclapCommented:
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
 
hongjunCommented:
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
 
rspahitzCommented:
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
 
hongjunCommented:
>>you can highlight and press tab to indent that particular IF.

That's is provided by my third comment.

hongjun
0
 
DRRYAN3Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now