This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub ChangeFormControlEnabledState(Of T As Control)(f As Form, state As Boolean) | |
Dim c As Control | |
For Each c In f.Controls | |
If TypeOf c Is T Then | |
CType(c, T).Enabled = state | |
End If | |
Next | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<ctype.h> | |
#include<cs50.h> // Can be commented out if using test word | |
//char c[] = "hello"; // Uncomment these lines to use test word "hello". | |
//char *p = &c[0]; | |
int main(int argc, char * argv[]) { | |
char k=(argc>1)?k=atoi(*++argv):0; | |
if((argc<2)||(k<=0)){printf("Bad number.\n");return 1;} | |
else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void CAP_setPrescale(CAP_Handle capHandle, const CAP_Prescale_e prescale) | |
{ | |
CAP_Obj *cap = (CAP_Obj *)capHandle; | |
/* clear the bits */ | |
cap->ECCTL1 &= (~CAP_ECCTL1_PRESCALE_BITS); | |
/* Set the new value */ | |
cap->ECCTL1 |= (uint16_t)prescale; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Note: 'x' and 'y' arguments must be modifiable lvalues. | |
* Example usage: | |
* int16_t a = 5, b = 5; | |
* TEST_EQUAL_INT_T(int16_t, a, b); | |
*/ | |
#include <stdint.h> /* Needed for uintmax_t */ | |
#define TEST_EQUAL_INT_T(T, x, y) { uintmax_t _x = (x), _y = (y); /* Save values to temp vars */ \ | |
if (((x) == (y)) /* Check if values are equal*/ \ | |
&& (sizeof(x) == sizeof(T)) /* Check if type sizes match */ \ | |
&& (sizeof(y) == sizeof(T)) \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class HaltGoBox | |
Inherits TextBox | |
Enum HaltGoState | |
Go = 0 | |
Halt = 1 | |
End Enum | |
Private _state As HaltGoState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class HaltGoLabel | |
Inherits Label | |
Enum HaltGoState | |
Go = 0 | |
Halt = 1 | |
End Enum | |
Private _state As HaltGoState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.ComponentModel | |
Imports System.Diagnostics.Contracts | |
' The FindIndex methods use code converted from the MSDN C# reference source as of 2015 Aug 17 13:34 GMT at: | |
' http://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs,cadc26eb4ba974e4 | |
Public Class BetterBindingList(Of T) | |
Inherits BindingList(Of T) | |
Public Function FindIndex(match As Predicate(Of T)) As Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: Form1.Controls.UnBold(Of GroupBox) 'Un-emboldens all control.Font perperties, except for GroupBox | |
Imports System.Runtime.CompilerServices | |
Module Extensions | |
<Extension()> | |
Public Sub UnBold(Of T As Control)(cc As Control.ControlCollection) | |
For Each c As Control In cc | |
If Not TypeOf c Is T AndAlso c.GetType.GetProperty("Font") IsNot Nothing Then | |
Dim RegularFont As New Font(c.Font.FontFamily, c.Font.Size, FontStyle.Regular) | |
c.Font = RegularFont | |
ElseIf c.HasChildren Then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: Form1.Controls.Enabled(Of Button)(False) | |
Imports System.Runtime.CompilerServices | |
Module Extensions | |
<Extension()> | |
Public Sub Enabled(Of T As Control)(cc As Control.ControlCollection, state As Boolean) | |
For Each c As Control In cc ' Iterate through every object in the container | |
If TypeOf c Is T Then ' Check if the object matches the type to set the state on | |
CType(c, T).Enabled = state ' Set the state on the matching object | |
ElseIf c.HasChildren Then ' Check if control is a parent ("Congratulations, omg look at that cute semi-colon!") | |
Enabled(Of T)(c.Controls, state) ' Recurse to handle the children (else maybe get a nanny) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Usage: | |
' Dim MyBytes() As Byte = {0, &HA5} | |
' Console.WriteLine(MyBytes.ToHexString) | |
' 'Prints "00 A5" | |
Imports System.Runtime.CompilerServices | |
Public Module Extensions | |
<Extension()> | |
Public Function ToHexString(a As Byte(), offset As Integer, length As Integer) As String | |
Dim RetVal As New System.Text.StringBuilder((length * 3) - 1) | |
Dim ByteStr As String |
OlderNewer