working on it ...

Filters

Explore Public Snippets

Sort by

Found 15 snippets

    public by p.kontalis  2761  1  5  0

    Numeric Validation on TextFields

    Imports System.Globalization
    Public Class Form 1
    
      Private Sub SheetFromWeight_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim YourPreferableCulture as String = "en-US"
        CultureInfo.DefaultThreadCurrentCulture = New CultureInfo(YourPreferableCulture)
        CultureInfo.DefaultThreadCurrentUICulture = New CultureInfo(YourPreferableCulture)
      End Sub
      
      Private Sub Numbers_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged,
                                                                                   TextBox2.TextChanged,
                                                                                   TextBox3.TextChanged
         If Not IsNumeric(sender.Text) Then sender.text = ""
         If sender.Text.contains(",") Then
              sender.text = sender.text.replace(",", ".")
              sender.select(sender.text.length, 0)
         End If
      End Sub                                  
    End Class

    public by p.kontalis  99038  2  5  0

    VTiger Extraction Customers' Data by City

    Extract from Vtiger Customers' List with address and to whom they have been assigned
    SET @city = '[CITY NAME]'; #Replace [CITY NAME] with your preferable city name
    SET @db_name='[DATABASE NAME]'; #Replace [DATABASE NAME] with your database name
    SET @myquery = CONCAT('
    SELECT	', @db_name, '.vtiger_account.accountid AS \'Company Code\',
    		', @db_name, '.vtiger_account.accountname AS \'Company\', 
    		', @db_name, '.vtiger_account.phone AS \'Phone 1\', 
    		', @db_name, '.vtiger_account.otherphone AS \'Phone 2\', 
    		', @db_name, '.vtiger_account.email1 AS \'Email 1\', 
    		', @db_name, '.vtiger_account.email2 AS \'Email 2\', 
    		', @db_name, '.vtiger_account.website AS \'Website\', 
    		', @db_name, '.vtiger_account.fax AS \'Fax\',
    		', @db_name, '.vtiger_accountbillads.bill_city AS \'City\',
    		', @db_name, '.vtiger_accountbillads.bill_code AS \'TK\',
    		', @db_name, '.vtiger_accountbillads.bill_country AS \'Country\',
    		', @db_name, '.vtiger_accountbillads.bill_state AS \'State\',
    		', @db_name, '.vtiger_accountbillads.bill_street AS \'Street\',
    		', @db_name, '.vtiger_accountbillads.bill_pobox AS \'TK\', 
    		', @db_name, '.vtiger_users.last_name AS \'Αssignment το\'
    FROM ', @db_name, '.vtiger_account
    INNER JOIN ', @db_name, '.vtiger_accountbillads 
    ON ', @db_name, '.vtiger_account.accountid = ', @db_name, '.vtiger_accountbillads.accountaddressid
    INNER JOIN ', @db_name, '.vtiger_crmentity
    ON ', @db_name, '.vtiger_account.accountid = ', @db_name, '.vtiger_crmentity.crmid	
    LEFT JOIN ', @db_name, '.vtiger_users
    ON ', @db_name, '.vtiger_crmentity.smownerid = ', @db_name, '.vtiger_users.id
    WHERE ', @db_name, '.vtiger_accountbillads.bill_city=@city
    AND ', @db_name, '.vtiger_crmentity.setype=\'Accounts\' 
    ');
    PREPARE stmt FROM @myquery;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
                
    

    public by p.kontalis  3263  1  5  0

    Retrieve System Characteristics

    Windows System Information Function
    Public Function RetrievePCInfo() As DataTable
        Dim DT As New DataTable
        DT.Columns.Add("Class")
        DT.Columns.Add("Name")
        DT.Columns.Add("Value")
        Dim search3 As New ManagementObjectSearcher("SELECT * FROM meta_class")
        Dim info3 As New ManagementObject
        For Each info3 In search3.Get
            Dim search4 As New ManagementObjectSearcher("SELECT * FROM " & info3("__CLASS").ToString)
            Dim Squerysearch4 As String = search4.Query.QueryString.ToString
            Dim info4 As New ManagementObject
            For Each info4 In search4.Get
                For Each Prop As PropertyData In info4.Properties
                    DT.Rows.Add(info3("__CLASS").ToString, Prop.Name, Prop.Value)
                Next
            Next
        Next
        Return DT
    End Function
    
    ' Beware this of code requires a large amount of RAM.
    ' Recommended to Extract all classes first and then for each class retieve the values.
    ' info class from motherboard is Win32_Bios
    ' info class from CPU is Win32_Prosessor

    public by p.kontalis  3514  1  5  0

    Hotkey for Application

    Hotkey or Combination that can effect everywhere inside the application
    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Add the following line in order to enable the capability to capture the keyboard events before any other element in the form.
        Me.KeyPreview = True
    End Sub
    
    Private Sub Hotkeys_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        ' The Alt + P Hotkey raise the event Button1.Click
        If (e.Alt AndAlso (e.KeyCode = Keys.P)) Then RaiseEvent Button1.Click
    End If

    public by p.kontalis  3322  1  5  0

    Use parameters with the executable file

    Run your application in different modes
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            For Each arg As String In My.Application.CommandLineArgs
                Select Case Trim(LCase(arg))
                    Case "a"
                    	'Do something
                    Case "b"
                    	'Do something else
                    Case Else
                    	'Run the app without parameters (arguments)
                End Select
            Next
        End Sub
    End Class

    public by p.kontalis  2612  2  5  0

    Return Multiple Type Values from a Function

    Structure MyResults
        Public Success As Boolean
        Public Result As String
    End Structure
    
    Public Function TrySomething(ByVal Parameter As String) As MyResults
        Dim NewResult As New MyResults
    	Try
        	' Do something and calculate My Result
            NewResult.Success=True
            NewResult.Result="My Result"
        Catch ex As Exception
        	NewResult.Success=False
            NewResult.Result=""
        End Try
        Return NewResult
    End Function

    public by p.kontalis  4023  1  5  0

    Loading Screen

    Animated or Static Loading Screen (Form) that appears during (re)loading state of your application.
    '######## 1. Create a Form with name "LoadingScr" ###########################################
    '######## 2. Place a picture box and import a gif file (for laoding animation) ##############
    '--------------------------------------------------------------------------------------------
    Public Class LoadingScr
        Private Sub LoadingScr_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		LoadingRun = True
            Me.Show()
            Do Until LoadingRun = False
                Application.DoEvents()
            Loop
            Me.Close()
        End Sub
    End Class
    '######## 3. Create a module for global variables as "Globals" ##############################
    '--------------------------------------------------------------------------------------------
    Module Globals
        Public LoadingRun As Boolean = False
    End Module
    '--------------------------------------------------------------------------------------------
    '######## 4. Place around the heavy duty work... ############################################
    '       ........
            Dim NewThread As New Threading.Thread(AddressOf LoadingScr.Show)
            NewThread.Start()
            '###### Code with your Heavy Duty Work........
            LoadingRun = False
    '       ........

    public by p.kontalis  3607  1  5  0

    Check whether two lines are crossed

    ' XA1: is the The X coordinate of the Start Point of the First Line
    ' YA1: is the The Y coordinate of the Start Point of the First Line
    ' XB1: is the The X coordinate of the End Point of the First Line
    ' YB1: is the The Y coordinate of the End Point of the First Line
    ' XA1: is the The X coordinate of the Start Point of the Second Line
    ' YA1: is the The Y coordinate of the Start Point of the Second Line
    ' XB1: is the The X coordinate of the End Point of the Second Line
    ' YB1: is the The Y coordinate of the End Point of the Second Line
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Module CrossedLinesValidation
        Public Function CrossedLines(XA1 As Long, YA1 As Long, XB1 As Long, YB1 As Long, XA2 As Long, YA2 As Long, XB2 As Long, YB2 As Long) As Boolean
    
            If (YA1 - YB1) * (XA2 - XB2) = (YA2 - YB2) * (XA1 - XB1) Then
                Return vbNull
                Exit Function
            End If
    
            Dim CrossedPointX As Double = ((XB1 * YA1 - XA1 * YB1) * (XA2 - XB2) - (XB2 * YA2 - XA2 * YB2) * (XA1 - XB1)) / ((YA1 - YB1) * (XA2 - XB2) - (YA2 - YB2) * (XA1 - XB1))
            If CrossedPointX <= Math.Max(XA1, XB1) And CrossedPointX >= Math.Min(XA1, XB1) Then Return True Else Return False
        End Function
    
        Public Sub RunMe()
            Select Case CrossedLines(1, 2, 3, 4, 1, 8, 3, 7)
                Case True
                    MsgBox("The lines ARE Crossed", MsgBoxStyle.Information, "Crossed Lines Validation")
                Case False
                    MsgBox("The lines ARE NOT Crossed", MsgBoxStyle.Information, "Crossed Lines Validation")
                Case vbNull
                    MsgBox("There is an ERROR in coordinates", MsgBoxStyle.Information, "Crossed Lines Validation")
            End Select
        End Sub
    End Module

    public by p.kontalis  1257  1  5  0

    Benchmark VB Code (Speed Test)

    3 ways to measure the execution time of your code
    ' #####################################################################################################################################
    ' ############################################# Method 1: Through Visual Studio Profiler ##############################################
    ' #####################################################################################################################################
    ' You can measure how fast the code is running through Visual Studio by applying the following test.
    ' 1. In the "Solution Configurations" drop down menu you choose "Release"
    ' 2. In the "Debug" Menu select "Start Diagnostic Tools without debugging"
    ' 3. On the next screen tick the "Performance Wizard" checkbox and then click "Start" button.
    ' 4. After that select "CPU Sampling (recommended)" and click "Finish".
    ' 5. Run any part of the application for testing and then terminate (exit) the app as used to. 
    ' 6. On the "Prformance Explorer" click on the Report in order to see the measurements.
    ' #####################################################################################################################################
    ' ############################################# Method 2: QPC (Query Performance Counter) #############################################
    ' #####################################################################################################################################
    ' Reference from: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408%28v=vs.85%29.aspx
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    ' Create a Button on the From designer
    Imports System.Diagnostics
    Public Class Form1
        Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef X As Long) As Short
        Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef X As Long) As Short
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    ''''''''If the debug returns errors remove the next four lines'''''''''''''''''''''''
            Process.GetCurrentProcess().ProcessorAffinity = New IntPtr(3) 'IntPtr(3) is the fourth Core of a QuadCore CPU
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime
            Process.GetCurrentProcess().PriorityBoostEnabled = True
            Thread.CurrentThread.Priority = ThreadPriority.Highest
            
            Dim StartTimer, StopTimer, Duration, Freq As Int64
            QueryPerformanceCounter(StartTimer) 			'Timestamp
            Dim StringToMemory As String = "A"				'Code that needs to be measured
            QueryPerformanceCounter(StopTimer)				'Timestamp
            Duration = StopTimer - StartTimer
            QueryPerformanceFrequency(Freq)					'CPU Clock Frequency
            Console.WriteLine("The Duration of the code is: " & Duration & Environment.NewLine & "The CPU Clock Frequency is: " & Freq)
        End Sub
    End Class
    ' #####################################################################################################################################
    ' ########################################################## Method 3: RDTSC ##########################################################
    ' #####################################################################################################################################
    ' This dll file has 3x functions available to use in your applications.
    ' rdtsc - This function makes a single call to rdtsc and returns the time stamp value.
    ' rdtsc2 - This function calls CPUID to serialize and then a single call to rdtsc, and then returns the timestamp value.
    ' rdtsc3 - This function makes 3x continuous calls to the rdtsc counter and then returns the value.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' I added the rdtsc2/rdtsc3 functions because it could help with consistancy. The first one seems to do ok for me, but maybe some 
    ' computers will be very busy when querying the counter that it will not get to the rdtsc code at the exact time you need it. 
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' This dll works only with 32bit emulation.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Make sure the .dll is in the bin directory (of the project) or system/system32 directory.
    ' Download dll from: https://www.dropbox.com/s/9p3f9pnhxxp4xc0/csRdtsc.dll?dl=0
    ' Thanks to Jason for RDTSC Library: http://www.vbforfree.com/what-counterstimers-are-available-to-the-vb-programmer/
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''    
    ' Create a Button on the From designer
    
    Imports System.Diagnostics
    
    Public Class Form1
        Private Declare Auto Function rdtsc Lib "csRdtsc.dll" () As Int64
        Private Declare Auto Function rdtsc2 Lib "csRdtsc.dll" () As Int64
        Private Declare Auto Function rdtsc3 Lib "csRdtsc.dll" () As Int64
        
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    ''''''''If the debug returns errors remove the next four lines'''''''''''''''''''''''
            Process.GetCurrentProcess().ProcessorAffinity = New IntPtr(3) 'IntPtr(3) is the fourth Core of a QuadCore CPU
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime
            Process.GetCurrentProcess().PriorityBoostEnabled = True
            Thread.CurrentThread.Priority = ThreadPriority.Highest
                    
            Dim StartTimer, StopTimer, Duration, Freq As Int64
            Dim StartTimer = rdtsc							'Timestamp     		
            Dim StringToMemory As String = "A"				'Code that needs to be measured
            Dim StopTimer = rdtsc							'Timestamp
            Duration = StopTimer - StartTimer
            Console.WriteLine("The Duration of the code execution is: " & Duration)
        End Sub
    End Class
    ' #####################################################################################################################################
    ' ######################################################## Method 4: StopWatch ########################################################
    ' #####################################################################################################################################
    ' Reference from: https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch%28v=vs.110%29.aspx
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    ' Create a Button on the From designer
    Imports System.Diagnostics
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            
    ''''''''If the debug returns errors remove the next four lines'''''''''''''''''''''''
            Process.GetCurrentProcess().ProcessorAffinity = New IntPtr(3) 'IntPtr(3) is the fourth Core of a QuadCore CPU
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime
            Process.GetCurrentProcess().PriorityBoostEnabled = True
            Thread.CurrentThread.Priority = ThreadPriority.Highest
                
            Dim StartTimer, StopTimer, Duration, Freq As Int64
            Dim StartTimer = Stopwatch.GetTimestamp()		'Timestamp     		
            Dim StringToMemory As String = "A"				'Code that needs to be measured
            Dim StopTimer = Stopwatch.GetTimestamp()		'Timestamp
            Duration = StopTimer - StartTimer
            Console.WriteLine("The Duration of the code execution is: " & Duration)
        End Sub
    End Class
    ' #####################################################################################################################################
    ' If you are not satisfied with the results of the above methods you can try C++ with Assepmly
    ' Read the conversation there: http://stackoverflow.com/questions/13772567/get-cpu-cycle-count         

    public by p.kontalis  2080  0  5  0

    SQL Join with Static Columns

    Identifies the origin of each row after the join of two tables.
    DROP TABLE IF EXISTS signed_A;
    DROP TABLE IF EXISTS signed_B;
    CREATE TEMPORARY TABLE signed_A AS (SELECT 'TableA' AS STATUS, A.col1, A.col2 FROM A);
    CREATE TEMPORARY TABLE signed_B AS (SELECT 'TableB' AS STATUS, hostings.col3 FROM B);
    SELECT * FROM A LEFT JOIN B ON A.col2=B.col3;
    • Public Snippets
    • Channels Snippets