Skip to content

Instantly share code, notes, and snippets.

@Phuseos
Phuseos / LockControls.vb
Last active June 2, 2016 06:42
Lock controls on Main and Subforms (Access / VBA)
sub LockSubFormControl()
'if called, locks all controls present on main and subform
'where frmMain is the currently active main form
'and frmSubForm the subform, located inside the main form
For Each ctl in Forms!frmMain.Controls 'Loop through the controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acCheckBox, acCommandButton 'Select the most used controls to lock
ctl.Enabled = False 'Lock the controls
@Phuseos
Phuseos / NestedConditionalOperator.cs
Last active June 2, 2016 10:30
Nested Conditional (?:) Operator (C#)
void NestedConditionalOperator() {
//This is an example to show what you can do with nested Conditional operators
//For this example we'll use int A and TestBool to demonstrate
//Assuming the page we're working with has TextBox1 as a TextBox on it
int A = 1;
bool TestBool = false;
//Below you'll see that we'll be testing for the value of both TestBool and A.
@Phuseos
Phuseos / PrintArrayValues.cs
Last active June 6, 2016 12:34
Loop through an array and print the values (C#)
//Simple little loop that prints the dynamic values of the following decimals
public static decimal DeciValueOne { get; set; }
public static decimal DeciValueTwo { get; set; }
void GetArrayValue() {
decimal[] ItemsToNone = new decimal[] { DeciValueOne, DeciValueTwo }; //Declare array
for (int i = 0; i < ItemsToNone.Length; i++) //Loop over the arrays
{
@Phuseos
Phuseos / FilePicker.vbs
Created June 7, 2016 08:58
FilePicker (VBA)
Private Sub FilePicker()
''''''''''''''
'The filepicker is made for images at the moment, you change this by changing the allowed extentions after .Add.
''''''''''''''
Dim dlgPickFiles As Office.FileDialog
Dim strList As String
Dim FileN As String
@Phuseos
Phuseos / ConnstrConnect.cs
Last active June 21, 2016 11:32
Easy ConnectionString usage in C#
public partial class Home : System.Web.UI.Page
{
//Assuming the connectionstring "YourConnectionString" has been build properly in web.config, set up a public MySqlConnection to use called 'con'.
public MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
using (con) //replaces using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString))
{
if (con.State != ConnectionState.Open) con.Open();
@Phuseos
Phuseos / ExpressBodyExample.cs
Created June 22, 2016 07:27
Expression bodies on method-like members (C#)
/*** Expression bodies on method-like members example ***/
/**This example shows how voids that only return methods or statements can be build using the 'lambda arrow'
The void below takes a string and returns it as a JavaScript alert window to the user **/
void CreateMessage(string Message)
{
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('" + Message + "');", true);
}
//With the new expression body, the void will look like this:
@Phuseos
Phuseos / NullCondExample.cs
Created June 22, 2016 07:43
Null-conditional operators example (C#)
/**Null-conditional operators example**/
//If the Text in txtBox1 is null, return 0, else return the length of the string of txtBox1.
int RunMe;
RunMe = txtBox1?.Text.Length ?? 0;
//The above statement is the equivalent of the if statement below
if (txtBox1.Text.Length != 0) RunMe = txtBox1.Text.Length;
@Phuseos
Phuseos / UserLog.bas
Created August 15, 2016 09:17
Capture user login (VBA / Access)
Option Compare Database
Public gstrInlogNaam As String 'Saves the login name, set this with a lookup in the table.
''Checks when a user logs off / in and sets this in the table
Sub CaptureInlog()
On Error GoTo err_mw
Dim rstL As ADODB.Recordset 'For logging inlog time / user / comp name
@Phuseos
Phuseos / IIfNestedConditional.vb
Last active August 26, 2016 09:27
Using the IIf() function as a Nested Conditional (?:) Operator (VBA / C#)
'Using the IIf() function as a Nested Conditional (?:) Operator
'Quick view of how you can use the iif function as the nested conditional operator, used in C#
'In C#
string TestString;
//string = Condition == true ? if true -> TestString = "Value" : else (false) -> TestString = null;
TestString = Condition ? "Value" : Convert.ToString(null);
'In VBA
dim TestString As String
@Phuseos
Phuseos / AddAppointmentToOutlook.cls
Created September 5, 2016 10:13
(VBA) Add appointments into Outlook from Ms Access / Excel
Option Compare Database
Option Explicit
' This Gist shows you how to add appointments to an Outlook Agenda
' It's based on the following user input:
' ApptDate (textbox, shortdate)
' ApptTime (textbox, short time)
' Duration (textbox, integer)
' Subject (textbox, string)
' ApptNotes (textbox, string)