Skip to content

Instantly share code, notes, and snippets.

@onlyforbopi
onlyforbopi / Vba.FuncSub.vb
Last active January 29, 2018 14:30
1. Declare Variables / Global Variables / Initialize Global variables 2. Declare Functions / Subs with exit codes, and return values
' The main difference between functions and subs is that
' functions RETURN a value
' subs do not return a value.
' Functions are declared with:
' The return value is handled with assignment on the function name
Public Function FunctionName(ByVar var1 As String) As <ReturnType>
FunctionName = true
End Function
@onlyforbopi
onlyforbopi / Vba.CheckFileEmpty.vb
Last active January 31, 2018 13:02
1. Check if a file exists 2. Check if a dir exists 3. Find line in file (with/without cmd) 4. Retrieve full file name 5. Write to File / Close File 6. Check if Text File is Empty
' Using FileLen("path") function
If (FileLen(TempDir) = 0) Then
MsgBox ("COULD NOT FIND LINE IN FILE")
Find_Line_nocmd = "No Line Found"
Else
'MsgBox ("Found Line")
With CreateObject("Scripting.FileSystemObject")
strOutput = .OpenTextFile(TempDir).ReadAll()
.DeleteFile TempDir
@onlyforbopi
onlyforbopi / Vba.ReadStdout.vb
Last active January 29, 2018 14:37
1. Use Exec to run CMD commands and capture STDOUT 2. Use Run to run CMD commands and capture STDOUT. (no cmd blip) 3. Examples of reading STDOUT
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' First method reads STDOUT directly
' Uses exec, unavoidable cmd blip
Set WSH = New WshShell
Set oExec = WSH.Exec("cmd /C findstr " & spattern & Space(1) & File_in)
Set oOutput = oExec.StdOut
Dim s As String
Dim sLine As String
@onlyforbopi
onlyforbopi / Vba.CheckStringNull.vb
Last active January 29, 2018 15:14
1. Check length of string 2. Check if string is null 3. Trim string from trash 4. Find/Replace in String
Function NotNullOrEmpty(strTextToTest As Variant) As Boolean
' Function : NotNullorEmpty
' Work : Check if specific string is null or empty
' Called as: NotNullorEmpty(string)
' Called at: Main Form Checks
' Input : string to be checked
If IsNull(strTextToTest) Then
@onlyforbopi
onlyforbopi / Vba.TextBox.BgColor.vb
Last active January 29, 2018 15:06
1. Assign Value to Textbox / Clear Value of TextBox 2. Set Focus to TextBox 3. Change bg color
' Change color of textbox based on conditional (Frequest Use)
If DirExists(WorkDirectory) Then
MsgBox ("Work directory located.")
Me.LabelStatus.Value = "Initial Checks Successful."
Me.LabelStatus.BackColor = lngGreen
Else
MsgBox ("Work directory: " & WorkDirectory & " was not located. Please restart application.")
Me.LabelStatus.Value = "Initial Checks Unsuccesful. Work Directory not located"
Me.LabelStatus.BackColor = lngRed
@onlyforbopi
onlyforbopi / Vba.SaveRecTable.vb
Created January 29, 2018 15:19
1. Save current records to table
'' This will save record and move the counter to the next record.
DoCmd.RunCommand acCmdSaveRecord
'DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord acDataForm, "FProcessedForm", acNext, 1
@onlyforbopi
onlyforbopi / Vba.ClockRefresh.vb
Last active January 31, 2018 13:07
1. MessageBox with Prompt 2. Clock with refresh
' This will create a clock that refreshes normally on the form
' For static time instead use "=Time()" with no refresh
' 1. Insert new unbound textbox
' 2. In Format/Format set "Long Time"
' 3. In Data/Control source set "=Time()"
' 4. In Form_Load event set "Me.TimerInterval = 1000" to set it to 1 second
' 5. In Other/Name name it txtClock (Optional)
' 6. In vba:
@onlyforbopi
onlyforbopi / DateTime.vb
Last active January 29, 2018 15:26
1. DateTimeFunctions
' Using DateValue
Dim exampleDate As Date
exampleDate = DateValue("Jun 19, 2010")
MsgBox Year(exampleDate)
'Note: Use Month and Day to get the month and day of a date.
' Using DateAdd
'To add a number of days to a date, use the DateAdd function.
'The DateAdd function has three arguments. Fill in "d" for the first argument to add days.
' Fill in 3 for the second argument to add 3 days. The third argument represents the date
@onlyforbopi
onlyforbopi / JS.PDF.SearchPattern.js
Last active January 30, 2018 10:37
1. Search a PDF document for a specific string, print all pages containing it 2. Search a PDF document for a specific pattern, print all pages containing it.
/* Extract PDF based on Content */
// Initialize an array that will hold all the page values
var pageArray = [];
// Initialize the search string ΜΑΛΑΘΥΡΟΥ "ΜΑΛΑΘΥΡΟΥ"; ÊÉÓÓÁÌÏÕ
var stringToSearchFor = "ΜΑΛΑΘΥΡΟΥ";
//stringToSearchFor = app.response("Enter search word");
@onlyforbopi
onlyforbopi / py.permutations.py
Last active September 27, 2018 13:08
Python.Math.Permutations.Combinations #python #Python #permutations #combinations #itertools #PythonModules PERMUTATIONS AND COMBINATIONS - SORT
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 31 09:49:49 2017
@author: P.Doulgeridis
"""
import itertools
def permutations(iterable, r=None):