Skip to content

Instantly share code, notes, and snippets.

@Phuseos
Phuseos / TranslateToSQL.bas
Created September 6, 2016 07:13
Translate JetSQL to SQL (VBA)
Public Function TranslateToSQL(ByVal jSQL As String) As String
If (Application.CurrentProject.ProjectType = acADP) Then
' Operators, constants, delimiters and wildcard characters
jSQL = Replace$(jSQL, "#", "'")
jSQL = Replace$(jSQL, """", "'")
jSQL = Replace$(jSQL, "&", "+")
jSQL = Replace$(jSQL, "?", "_")
jSQL = Replace$(jSQL, "*", "%")
@Phuseos
Phuseos / InputBox.cls
Created September 8, 2016 07:22
(VBA) InputBox for user input
Private sub GetName()
On Error GoTo err_mw
Dim strName As String ' Name to be obtained
strName = InputBox(Prompt:="What is your name?", _
Title:="Name", Default:="Name") ' Get the name and save it to strName
If strName = Null Or strName = Nothing Then Exit Sub ' If the response is empty exit sub
@Phuseos
Phuseos / .htaccess
Created October 5, 2016 10:43
.htaccess Complete (gzip, expire headers and deflation)
<IfModule mod_expires.c>
ExpiresActive on
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Media: images, video, audio
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
@Phuseos
Phuseos / CreateMessage.aspx.cs
Created December 15, 2016 08:40
CreateMessage (ASP / C#)
using System;
using System.Web.UI;
public partial class CreateAMessage : Page
{
protected void Page_Load(object sender, EventArgs e)
{
//This page creates an example messagebox on load.
CreateMessage("Hello world!");
protected void TextBoxNullCatcher(object sender, EventArgs e)
{//Code to makes sure all controls that are textboxes have at least a '1' value.
if (sender is Control)
{
var usedControl = sender as Control; //Declare the control
if (usedControl is TextBox)
{
TextBox txtType = usedControl as TextBox; //Set the control as a textbox
if (string.IsNullOrEmpty(Convert.ToString(txtType.Text)))
Private Sub CleanFormTextboxes()
'Empty textboxes in the current form
'Loop through the controls
Dim ctrl As Control
Dim txt As TextBox
'If a textbox is found in the loop and the text is more then 1 character, empty it
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
@Phuseos
Phuseos / FormatAndSaveWordDocument.cs
Created February 27, 2017 08:57
Format and save information from a textbox to a Word document. Snippet of the Label-Printer-DYMO Project.
using Microsoft.Office.Interop.Word;
using Microsoft.VisualBasic;
using System;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
//Snippet of the Label-Printer-DYMO Project (https://github.com/Phuseos/Label-Printer-DYMO)
@Phuseos
Phuseos / AddXMLToZIP.cs
Last active March 7, 2017 07:05
Create a XML file and add this to a ZIP archive.
protected void AddXMLToZIP(object Sender, EventArgs e)
{
string ZIPName = "TestZIP";
using (ZipFile zip = ZipFile.Create(MapPath + "ZIP" + ZIPName + ".zip"))
{
//Allow the zipfile to be updated
zip.BeginUpdate();
//Set the folder on the server
@Phuseos
Phuseos / KeepSessionAlive.ashx
Created March 22, 2017 08:03
Handler + JavaScript that keep the session from timing out (C#)
<%@ WebHandler Language="C#" Class="KeepSessionAlive" %>
using System;
using System.Web;
using System.Web.SessionState;
//Handler that checks the session, when called from the Master page (see below) it will keep the session from idle time-out.
public class KeepSessionAlive : IHttpHandler, IRequiresSessionState
{
@Phuseos
Phuseos / SplitTextUsingRegex.cs
Created April 10, 2017 12:16
Split text using Regex
using System.Text.RegularExpressions;
public static string spliceText(string text, int lineLength)
{
return Regex.Replace(text, "(.{" + lineLength + "})", "$1" + Environment.NewLine);
}
/*
How to use