This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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. |
This file contains hidden or 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
| //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 | |
| { |
This file contains hidden or 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 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 | |
This file contains hidden or 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 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(); |
This file contains hidden or 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
| /*** 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: |
This file contains hidden or 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
| /**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; |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| '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 |
This file contains hidden or 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
| 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) |