working on it ...


Explore Public Snippets

Sort by

Found 29 snippets

    public by p.kontalis  1217  0  6  0

    Replace Assembly.LoadWithPartialName with Assembly.Load

    The Assembly.LoadWithPartialName has been deprecated. From now on you have to use Assembly.Load
    '###Till .NET Framework 2.0 you can Load an assembly by its name
    Dim FormsAssembly As Reflection.Assembly = Reflection.Assembly.LoadWithPartialName("System.Windows.Forms")
    '###After .Net Framework 2.0 you have to use Assembly.Load
    '###Therefore you have to give all the assembly information but the public token is not the same per pc
    Dim FormsAssembly As Reflection.Assembly = Reflection.Assembly.Load("System.Windows.Forms, Version =, Culture = neutral, PublicKeyToken = 7a84f7ac56134e3a")
    '###In order to bypass this wall either you retrieve it from the registry or you use the GetType(Form) for the retrieval.
    Dim AssemblyLoadString As String = GetType(Form).AssemblyQualifiedName.ToString.Substring(GetType(Form).AssemblyQualifiedName.ToString.IndexOf(",") + 2)
    Dim FormsAssembly As Reflection.Assembly = Reflection.Assembly.Load(AssemblyLoadString)                        

    public by p.kontalis  2896  0  4  0

    Batch Control Style

    Example regarding the control styling. This example applies a new color on all the buttons of your current form.
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      btn = Me.Controls.OfType(Of Button)().Where(Function(c) c.Name.Contains("")).ToArray()
    End Sub
    Private Sub Recolor()
      Dim i As Integer = 0
      While i < btn.Count
        btn(i).Enabled = True
        btn(i).BackColor = Color.Yellow
        i += 1
      End While
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    End Sub

    public by zonaro  1876  3  8  0

    Hide URL Parameters after PageLoad

    Add a StartupScript to the page. This snippet hide the parameters of URL after PageLoad
    Response.Write("<script>setTimeout(function () { history.replaceState({ foo: \"bar\" }, \"RemoveParam\", location.pathname) }, 300);</script>");

    public by zonaro  197143  0  8  0

    Sum (Excel port for VB.NET)

    Like in Excel, this method sum the numbers of a ParamArray
    Function Sum(ByVal ParamArray Nums As Decimal()) As Decimal
            Dim s = 0
            For Each i As Decimal In Nums
                s += i
            Return s
        End Function            

    public by zonaro  2196  1  6  0

    Toggle Method for Integer and Boolean Types (Extension Method)

    Allow you to use Variable.Toggle() to invert the current value of a Boolean Variable. Also works with Integer type too!
    Public Module Toggles
        Public Sub Toggle(ByRef Bool As Boolean)
            Bool = Not Bool
        End Sub
        Public Sub Toggle(ByRef Int As Integer)
            If Int > 0 Then
                Int = 0
                Int = 1
            End If
        End Sub 
    End Module

    public by zonaro  2390  0  7  0

    Greeting or farewell according to the current time (Saudação ou despedida de acordo com o horário atual)

    Returns a text containing the greeting or farewell to the specified language (English, Portuguese or Spanish. Default language is Portuguese) Retorna um texto contendo a saudação ou despedida de acordo com o idioma especificado (Português, Inglês ou Espanhol. Idioma padrão é português)
    //see this and other methods compiled 
    //into a DLL in
    Public Function Greeting(Optional Language As String = "pt", Optional Farewell As Boolean = False) As String
           Dim bomdia As String = "Bom dia"
           Dim boatarde As String = "Boa tarde"
           Dim boanoite As String = "Boa noite"
           Dim boanoite_despedida As String = boanoite
           Dim seDespedidaManha As String = "tenha um ótimo dia"
           Dim seDespedidaTarde As String = "tenha uma ótima tarde"
           Select Case Language.ToLower()
               Case "en", "eng", "ingles", "english"
                   bomdia = "Good morning"
                   boatarde = "Good afternoon"
                   boanoite = "Good evening"
                   boanoite_despedida = "Good night"
                   seDespedidaManha = "have a nice day"
                   seDespedidaTarde = "have a great afternoon"
                   Exit Select
               Case "es", "esp", "espanhol", "espanol", "español", "spanish"
                   bomdia = "Buenos días"
                   boatarde = "Buenas tardes"
                   boanoite = "Buenas noches"
                   boanoite_despedida = boanoite
                   seDespedidaManha = "que tengas un buen día"
                   seDespedidaTarde = "que tengas una buena tarde"
                   Exit Select
           End Select
           If DateTime.Now.Hour > 6 AndAlso DateTime.Now.Hour < 12 Then
               Return If(Farewell, seDespedidaManha, bomdia)
           ElseIf DateTime.Now.Hour >= 12 AndAlso DateTime.Now.Hour < 18 Then
               Return If(Farewell, seDespedidaTarde, boatarde)
               Return If(Farewell, boanoite_despedida, boanoite)
           End If
       End Function

    public by Uriahs  2109  0  5  0

    Simple MySQL database connection with select statement

    This snippet has coode to pull the rows from the db in a while loop.
      'Import this to the very top of your code, make sure you have the mysql connector installed for VS
      Dim conn As New MySqlConnection
            Dim cmd As New MySqlCommand
            Dim read As MySqlDataReader
    			'default root would have no pw...simply remove the password part if you have no pw
                conn.ConnectionString = "server=;user id=root; password=yourpw; database=mydb"
                cmd.Connection = conn
                cmd.CommandText = "SELECT id, name FROM mydb.table"
                read = cmd.ExecuteReader
                If read.HasRows Then
                    While read.Read
    					'name this variable anything you want
                        Dim id = read.GetInt32("id")
                        'for getting a string value:
                        Dim sName = read.GetString("name")
    					'make the pvname and pvid public(global) variables so you could use them outside while loop,
    					'this might not be needed in some cases
                        pvname = sName 
                        pvid = id
                    End While
                End If
            Catch ex As Exception
            End Try

    external by StackOverflow  1  0  2  0

    System.Data.SqlClient assembly not found .net 3.5

    I am trying my hand at converting a application over to C#, and I got to the part where I was doing the database portion with the SqlClient, and it just isn’t there. most of the posts I’ve found say I should use the nuget package, but when I did that, it failed because I am targeting .net 3.5 This is a requirement because until we get ri
    If you're targeting .NET 3.5, you can use a framework reference to System.Data, which gives you SqlClient. However, you probably shouldn't still keep trying to work with .NET 3.5. You won't be able to use the nuget package, because it doesn't go back that far. In csproj terms, this is:
      <Reference Include="System.Data" />

    external by Kamal Desai  1  0  2  0

    Include files marked as "Copy to Output Directory" with Installshield LE

    I'm building a Windows Service in VB.NET with Visual Studio 2012. I included log4net in my project to deal with logging information about the service execution. I created a log4net.config file, which I marked Copy if newer in its Copy to Output Directory property. I added an Installshield LE Setup project to my solution, and selected Myproject.Pri
    How about adding loggly related configuration in App.config file like below.
    I am using it for hosting WCF service within Window Service and it works fine for me.
            <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
              <level value="ALL" />
              <appender-ref ref="LogglyAppender" />
            <appender name="LogglyAppender" type="log4net.loggly.LogglyAppender, log4net-loggly">
              <rootUrl value="" />
              <inputKey value="abcdefgh" />
              <tag value="log4net" />

    external by gchq  1  0  2  0 MVCGridConfig.vb example

    Are there any examples available of using VB.NET? Tried a number of methods, like this... MVCGridDefinitionTable.Add("EmployeeGrid", New MVCGridBuilder(Of Person)().WithAuthorizationType(AuthorizationType.AllowAnonymous).AddColumns(Sub(cols) cols.Add("Id").WithValueExpression(Function(p) p.Id.ToString()) cols.Add("FirstName").WithHea
    Have figured out part of it
    MVCGridDefinitionTable.Add(Of GridModal)("CurrentBalanceGrid", New MVCGrid.Models.MVCGridBuilder(Of GridModal)().WithAuthorizationType(MVCGrid.Models.AuthorizationType.AllowAnonymous).AddColumns(Sub(cols)
                                                                                                                                                                                                               cols.Add("Id").WithValueExpression(Function(p) p.TransactionID.ToString())
                                                                                                                                                                                                               cols.Add("DebitAmount").WithHeaderText("Debit").WithValueExpression(Function(p) p.DebitAmount)
                                                                                                                                                                                                               cols.Add("CreditAmount").WithHeaderText("Credit").WithValueExpression(Function(p) p.CreditAmount)
    Just need to wire up the data now
    • Public Snippets
    • Channels Snippets