Richard Schollar
MrExcel MVP
- Joined
- Apr 19, 2005
- Messages
- 23,707
Yep that's cool.
Don't mean to be a party-pooper, but this seems to be getting off topic (and you would never catch me doing that ). Helpful as things such as F9 are, they are hardly guru tricks, not in the manner that conditional compilation is I would venture. <Big Snip>
...generating RC style formulae and ... changing the setting - via tools, options, general - to R1C1 style then copying the formula from the formula bar and pasting it into the VBE...
-fazza
Sub ToggleA1toR1()
'// use of DataObject object requires reference to MSForms library
Dim doNew As DataObject
If KeyPressed(VK_Control) Then
Set doNew = New DataObject
With doNew
.SetText ActiveCell.FormulaR1C1
.PutInClipboard
End With
Else
With Application
.ReferenceStyle = IIf(.ReferenceStyle = xlA1, xlR1C1, xlA1)
End With
End If
End Sub
No worries, Bob...Don't mean to be a party-pooper, but this seems to be getting off topic (and you would never catch me doing that ). Helpful as things such as F9 are, they are hardly guru tricks, not in the manner that conditional compilation is I would venture.
Is this not obvious for a read/write Boolean Property toggle?Code:With ActiveWindow .DisplayGridlines = Not .DisplayGridlines End With
Shorter, easier to understand, and no messy Ifs which alwasy break the flow IMO. And then there is And, Or, ...
' Regarding code quality:
' 1) The following code does a lot of string manipulation by
' concatenating short strings together with the "&" operator.
' Since string concatenation is expensive, this is a very
' inefficient way to write code. However, it is a very
' maintainable way to write code, and is used here because this
' program performs extensive disk operations, and because the
' disk is much slower than the memory operations required to
' concatenate the strings. Keep in mind that this is demonstration
' code, not production code.
So, often times it makes a lot more sense, performance-wise to work with arrays, whether it's String & Byte Arrays, which directly coerce, or Array->String via Join().What Are Common Heap Performance Problems?
Here are the most common obstacles you will encounter when working with the heap:
- Slowdown as a result of frequent allocs and reallocs. This is a very common phenomenon when you use scripting languages. The strings are repeatedly allocated, grown with reallocation, and freed up. Don't do this. Try to allocate large strings, if possible, and use the buffer. An alternative is to minimize concatenation operations.
{snip}
Rethink algorithms and data structures
- If you make extensive use of Automation structures, consider factoring out Automation BSTRs from your mainline code, or at least avoid repeated operations on BSTR. (BSTR concatenation leads to excessive reallocs and alloc/free operations.)
{snip}
Is this not obvious for a read/write Boolean Property toggle?
If object.boolean_property = TRUE then
Option Explicit
Sub DoIHaveItRight()
Dim strVal(0 To 3) As String
strVal(0) = 0
strVal(1) = 1
strVal(2) = 2
strVal(3) = 3
'Do this:
Faster strVal
'Not this:
Slower strVal
End Sub
Sub Faster(strVal() As String)
Debug.Print VBA.Join(strVal, Empty)
End Sub
Sub Slower(strVal() As String)
Debug.Print strVal(0) & strVal(1) & strVal(2) & strVal(3)
End Sub
You don't really want to know!Nate get's all hard-core when you least expect it. Sort of makes me wonder what else is stored in his head
It can be... Concatenation may or may not be fast or slow... Join() with your posted code looks to me like it's slightly slower, and using a Mid$() loop with a buffered string looks slightly faster, to me:I actually wasn't aware that concatenation was bottleneck. Just to make sure I understand... Does the code below represent what you are saying correctly?
Public Declare Function QueryPerformanceFrequency _
Lib "kernel32.dll" ( _
lpFrequency As Currency) As Long
Public Declare Function QueryPerformanceCounter _
Lib "kernel32.dll" ( _
lpPerformanceCount As Currency) As Long
Sub Faster(strVal() As String)
Dim tmpStr As String, i As Long
Let tmpStr = Space$(UBound(strVal) + 1)
For i = LBound(strVal) To UBound(strVal)
Mid$(tmpStr, i + 1, 1) = strVal(i)
Next
End Sub
Sub Slower(strVal() As String)
Dim tmpStr As String
Let tmpStr = strVal(0) & strVal(1) & strVal(2) & strVal(3)
End Sub
Sub foo()
Dim Ctr1 As Currency, Ctr2 As Currency, Freq As Currency
Dim Overhead As Currency
Dim i As Long
Dim strVal(0 To 3) As String
strVal(0) = 0
strVal(1) = 1
strVal(2) = 2
strVal(3) = 3
QueryPerformanceFrequency Freq
QueryPerformanceCounter Ctr1
QueryPerformanceCounter Ctr2
Overhead = Ctr2 - Ctr1 ' determine API overhead
QueryPerformanceCounter Ctr1 ' time loop
For i = 1 To 100000
'Call Faster(strVal)
Call Slower(strVal)
Next
QueryPerformanceCounter Ctr2
Debug.Print (Ctr2 - Ctr1 - Overhead) / Freq
End Sub
Good Stuff Nate
Here is one from Dave Hawley that I found today looking around for something else. You can take a screen shot of just the selected area of a worksheet by selecting what you want a shot of, holding down the Shift key, select the edit menu then Copy Picture.