Skip to content

Instantly share code, notes, and snippets.

Option Explicit
#If VBA7 And Win64 Then
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As LongPtr, ByVal dwFlags As LongPtr) As LongPtr
#Else
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
on play_evil_laugh(filePath)
do shell script "afplay '" & filePath & "'"
end play_evil_laugh
Option Explicit
Private Sub Worksheet_Calculate()
On Error GoTo ExitSub
Dim rng As Range
Set rng = Windows(1).VisibleRange.Cells.SpecialCells(xlCellTypeFormulas, xlErrors)
Dim cell As Range
Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Source As Range)
On Error GoTo ExitSub
Application.EnableEvents = False
Dim rng As Range
Set rng = Windows(1).VisibleRange.Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
Public Function LEFT(text As String, Optional num_of_chars As Long = 1) As String
LEFT = MID(text, 1, num_of_chars)
End Function
Public Function RIGHT(text As String, Optional num_of_chars As Long = 1) As String
RIGHT = MID(text, Len(text) - num_of_chars, num_of_chars)
End Function
Public Function MID(text As String, start_num As Long, num_of_chars As Long) As String
' Actual Implementation
Option Explicit
Public Function GetSummary(text As String, num_of_words As Long) As String
If (num_of_words <= 0) Then
GetSummary = ""
Exit Function
End If
Dim words() As String
words = Split(text, " ")
// a = { "a", "A", "B" }
// b = { "b" }
// set = {}
//
// first, add items from `b` into a new set using the Comparer given
// (in this case, StringComparer.OrdinalIgnoreCase)
//
// 1. Can "b" go into the set? Yes, because it doesn't exist.
// set = { "b" }
//
static IEnumerable<TSource> ExceptIterator<TSource>(
IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer)
{
Set<TSource> set = new Set<TSource>(comparer);
foreach (TSource element in second) set.Add(element);
foreach (TSource element in first)
if (set.Add(element)) yield return element;
}
public static IEnumerable<TSource> Except<TSource>(
this IEnumerable<TSource> first,
IEnumerable<TSource> second)
{
if (first == null) throw Error.ArgumentNull("first");
if (second == null) throw Error.ArgumentNull("second");
return ExceptIterator<TSource>(first, second, null);
}
var a = new object();
var b = new object();
var aList = new List<object> { a, a, b };
var bList = new List<object> { b };
var aExceptB = aList.Except(bList);
Console.WriteLine(aExceptB.ToList().Count());