PDA

View Full Version : Well I'm Impressed



Bob Phillips
10-25-2006, 02:04 AM
Discovered something whilst playing in VBA today that I was not aware of.

I often copy other people's code and then go and indent it. I don't use any indenting code/product, I do it manually. One technique I use regulalrly is to select a block, such as IF ... ENDIF, with many lines, and use tab to indent each row.

Today I accidentally used Shift as well as tab, and it removed indents :).

It's obvious now that I know it does, but it never occurred to me, and I think that is so handy, I know I will use it a lot.

johnske
10-25-2006, 03:15 AM
...I often copy other people's code and then go and indent it. I don't use any indenting code/product, I do it manually. One technique I use regulalrly is to select a block, such as IF ... ENDIF, with many lines, and use tab to indent each row...Bob, this part of your statement amazes me - haven't you tried Stephen Bullens "Smart Indenter (http://bmsltd.ie/Excel/SBXLPage.asp)" addin? It's just so fast and easy (it's the only addin I can't do without) - you can specify all your indenting preferences and it can also undo indenting :)

Bob Phillips
10-25-2006, 04:46 AM
John,

I do know about it, it was the product that I alluded to, but if you recall a thread somewhere else you will know that I don't like to install addins unless absolutely vital. If things go wrong, it increases the number of variables in the problem, so unless an addin is a must-have, it doesn't go on my machine. Whilst I acknowledge the usefuleness of the addin, as I am a conscientious indenter when developing my own code, it doesn't hit the must-have category for me.

johnske
10-25-2006, 05:28 AM
OK - that's your choice. :thumb... I just got sick of doing it by hand :)

Zack Barresse
10-25-2006, 08:07 AM
Yes, I've used that shortcut for a while now, it's quite invaluable if you do any moving/indenting of code in the VBEIDE. :yes

Ken Puls
10-25-2006, 10:21 AM
Interesting...

I use both Smart Indenter and MZ Tools. I'll hate working without either of them.

One of the reasons that I like Smart Indenter is that if I go back and start hacking up a project, inserting With blocks, If blocks, etc, or just moving them, a quick Smart Indent lines everything up and tells me immediately if I forgot to close a block. I try to be careful, but naturally mistakes do happen.

And MZ... John, you don't use it? Wouldn't live without that one. :)

mvidas
10-25-2006, 10:25 AM
I'm like Bob, I dont use any addins for indenting (though a friend of mine on another board constantly harasses me because of my 1-space indenting style). I love the tab/shift-tab, I always have to use it to convert vbax code for my eyes (as well as find/replace " " (4 spaces) with " " (1 space))
Anyone know a keyboard shortcut for the comment/uncomment block?

Jacob Hilderbrand
10-25-2006, 10:56 AM
I don't see a shortcut for comment / uncomment:

F7 - View Code window
F2 - View Object Browser
CTRL+F - Find
CTRL+H - Replace
F3 - Find Next
SHIFT+F3 - Find Previous
CTRL+DOWN ARROW - Next procedure
CTRL+UP ARROW - Previous procedure
SHIFT+F2 - View definition
CTRL+PAGE DOWN - Shift one screen down
CTRL+PAGE UP - Shift one screen up
CTRL+SHIFT+F2 - Go to last position
CTRL+HOME - Beginning of module
CTRL+END - End of module
CTRL+RIGHT ARROW - Move one word to right
CTRL+LEFT ARROW - Move one word to left
END - Move to end of line
HOME - Move to beginning of line
CTRL+Z - Undo
CTRL+Y - Delete current line
CTRL+DELETE - Delete to end of word
TAB - Indent
SHIFT+TAB - Outdent
CTRL+SHIFT+F9 - Clear all breakpoints
SHIFT+F10 - View shortcut menu

Ken Puls
10-25-2006, 10:58 AM
Does anyone use the Bookmark feature?

mvidas
10-25-2006, 11:01 AM
Bookmark feature?

Thanks, Jake. At quick glance I thought I knew all of them, but had never seen "CTRL+SHIFT+F2 - Go to last position" before. Could come in handy on those days where I check something quickly then forget where i was (though I don't know if I'd be able to remember the ctrl-shift-f2 then...).

Out of curiosity, does anyone NOT have a 104-key keyboard anymore (same as shift-f10)?

Jacob Hilderbrand
10-25-2006, 11:04 AM
Mine has 107 keys, not counting the special ones for media, volume etc.

mvidas
10-25-2006, 11:22 AM
Mine has 107 keys, not counting the special ones for media, volume etc.Interesting.. what do you have, like power/sleep/etc?
I guess I technically have a 105 key keyboard since my spacebar is divided in two (left half backspace, right have space)

Jacob Hilderbrand
10-25-2006, 11:25 AM
I have these extra keys:

Sleep
I never used these: Search, Clup HP, Internet, Info, E-Mail
Eject 1 & Eject 2
Burn CD/DVD, Prev, Play Pause, Next, Stop
Volume Down, Volume Up, Mute

Most of these are pretty useless to me, though I do use the volume and mute.

Ken Puls
10-25-2006, 01:41 PM
Bookmark feature?

On the 2003 menus it's under Edit|Bookmarks

I've never used it. Breakpoints I use all the time, but not bookmarks...

malik641
10-25-2006, 02:56 PM
I love shift+Tab...when I discovered that, I tried shift with everything :)

And I love the comment/uncomment block, I showed one of my friends that and he was so happy about it.


Does anyone use the Bookmark feature?I've used it a little (only when I have to jump from one procedure to the other in a bigger project...like if I'm working on a function or something).

Ken Puls
10-25-2006, 10:18 PM
I've used [Bookmarks] a little (only when I have to jump from one procedure to the other in a bigger project...like if I'm working on a function or something).

I've never actually used that feature before... (nor has Matt, LOL!). It looks like it could be quite handy though... I wonder if there are keyboard shortcuts for it?

Jacob Hilderbrand
10-25-2006, 11:54 PM
They should be listed in the VBE help. I pulled the list above from there, but I don't have access to 2003 at the moment.

mvidas
10-26-2006, 06:07 AM
I've never actually used that feature before... (nor has Matt, LOL!). It looks like it could be quite handy though... I wonder if there are keyboard shortcuts for it?
I dont even have 2003 so I wouldnt know about it :) I doubt i'd use it anyways, if I have to change modules regularly I just close everything but the ones i'll need then just use ctrl-f6 to flip between

Maybe I'll make an addin simply to assign the (un)comment block a shortcut key.. unless I need to comment out more than 10 lines I'll often just do it by hand so I don't have to reach for the mouse :shifty:

Ken Puls
10-26-2006, 11:03 AM
Ah! Didn't realize that the bookmark was a 2003 feature. :)

mvidas
10-26-2006, 11:34 AM
Ah! Didn't realize that the bookmark was a 2003 feature. :)i think it was your wording "On the 2003 menus..." and my lack of reading fully that made me think that

I do have that, though I never looked at it.
As for keyboard shortcuts :shifty:
Alt-e-b-t Toggle Bookmark
Alt-e-b-n Next bookmark
Alt-e-b-p Previous bookmark
Alt-e-b-c Clear all bookmarks

I could see a use, but I'll never use it

ADDED: Re: comment/uncomment block, you can customize the menus, change the comment/uncomment icons to show image and text, and add a & to make them alt-key friendly :)

Norie
10-26-2006, 11:55 AM
Ken

Bookmarks isn't a 2003 feature.

Well I've got it in 2000 anway, right at the bottom of the VBA edit menu.

Ken Puls
10-26-2006, 12:10 PM
I could see a use, but I'll never use it

Okay, I'll bite. Why not?

Norie
10-26-2006, 12:14 PM
Ken

I can't actually see much use for it either, but I quite like the pretty blue rounded square.:)

Brightens the VBE up a bit.

mvidas
10-26-2006, 01:04 PM
Okay, I'll bite. Why not?
Better question is, why?
Ok, I guess I can't say I'll never use it. I can remember a time a couple months ago when I wanted to remember where I was so I commented a random word I knew wouldnt be in the code so i could do a Find and return there later. But now that I know about the 'return to last position', I wont even have to do that again. But I could have used the bookmark

I suppose the best answer to your question is 'because im stubborn and like doing things the way i do now' :)

malik641
10-26-2006, 09:34 PM
Better question is, why?What about if you have a loop that calls a function, and you're sending the function a different type of variable(s) each loop. You could toggle back and forth to understand how each different variable is handled by the function. This is assuming that you have a lot of code in your module and would become tedious to scroll to the function...then use 'return to last position'...then scroll again, then use 'return to last position'.


...unless there's a feature of 'return to last position' that I don't know yet :)

I hope this was a decent example....It seems like bookmarks might be more for newbies I guess.

Bob Phillips
10-27-2006, 12:55 AM
Isn't that what the watch window is for?

malik641
10-27-2006, 07:35 AM
Isn't that what the watch window is for?Haven't used that....

Bob Phillips
10-27-2006, 09:40 AM
Haven't used that....

Time to start. And the Immediate window, and the Locals window, and Debug.Alert, etc. etc.

Bob Phillips
10-27-2006, 09:41 AM
BTW how van you develop any sizable VBA without using the watch window?

mvidas
10-27-2006, 10:16 AM
debug.alert?

I can count the number of times ive used the watch window on one finger

malik641
10-27-2006, 12:17 PM
BTW how van you develop any sizable VBA without using the watch window?Break points for me....(maybe it's cause I haven't made projects as big as you have :dunno )

I'll be doing my research this weekend on how to use Debug.Alert, watch window, and the locals window (I use Immediate window ALL the time). Thanks for the heads up :)

Bob Phillips
10-27-2006, 04:31 PM
debug.alert?

I can count the number of times ive used the watch window on one finger

Well I guess njot all of us write error-free code first time, every time like you.

mvidas
10-27-2006, 05:10 PM
Well I guess njot all of us write error-free code first time, every time like you. I just hover the mouse over the variables to see the values, just another way of doing it I guess. sorry if what I said sounded arrogant, i definitely write error-full code
what does debug.alert do?

Bob Phillips
10-27-2006, 06:17 PM
I just hover the mouse over the variables to see the values, just another way of doing it I guess. sorry if what I said sounded arrogant, i definitely write error-full code

True, but by putting a watch on a variable, you can step quickly through code watching the watch window until it changes to the value you are looking for.did not expect. I find that very handy.


what does debug.alert do?

A typo, meant debug.assert.

Ken Puls
10-27-2006, 06:37 PM
Well I guess njot all of us write error-free code first time, every time like you.

:rotflmao:

Zack Barresse
10-30-2006, 02:25 PM
I use the Watch window and (even more) the Locals Window. They are as valuable as the Immediate window, IMHO. :yes

Ken Puls
10-30-2006, 11:11 PM
I use the watch window occasionally, and should use it more. The locals window I use constantly though. As much, if not more, than the immediate window, in fact. :)