working on it ...

Filters

Explore Public Snippets

Sort by

Found 56 snippets

    public by p.kontalis  1225  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 = 4.0.0.0, 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  2903  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
      Recolor()
    End Sub

    public by zonaro  1883  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  197150  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
            Next
            Return s
        End Function            

    public by zonaro  2198  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
         
        <Extension()>
        Public Sub Toggle(ByRef Bool As Boolean)
            Bool = Not Bool
        End Sub
        
        <Extension()>
        Public Sub Toggle(ByRef Int As Integer)
            If Int > 0 Then
                Int = 0
            Else
                Int = 1
            End If
        End Sub 
    End Module

    public by zonaro  2393  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 http://github.com/kaizonaro/innerlibs.net/releases/
    
    
    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)
           Else
               Return If(Farewell, boanoite_despedida, boanoite)
           End If
       End Function
       
                            

    public by Uriahs  2117  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
      
      Imports mysql.data.mysqlclient
      
      Dim conn As New MySqlConnection
            Dim cmd As New MySqlCommand
            Dim read As MySqlDataReader
    
    
    
            Try
    			'default root would have no pw...simply remove the password part if you have no pw
                conn.ConnectionString = "server=127.0.0.1;user id=root; password=yourpw; database=mydb"
    
    
                cmd.Connection = conn
    
    
                conn.Open()
                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
                MsgBox(ex.Message)
            End Try
            
            

    external by R.J. Dunnill  1  0  2  0

    Convert async Task from c# to vb.net

    I try convert this code using code C# to VB.NET converter, have some error. private async Task OnRequestBlockResourceEventHandler(object sender, SessionEventArgs e) =&gt; await Task.Run( () =&gt; { if (e.HttpClient.Request.RequestUri.ToString().Contains("analytics"))
    /* 
    You need to change the lambda function to a sub:        
     */
    Private Async Function OnRequestBlockResourceEventHandler(ByVal sender As Object, ByVal e As SessionEventArgs) As Task
       ' *** Change to Sub() ***
       Return Await Task.Run(Sub()
    
                                      If e.HttpClient.Request.RequestUri.ToString().Contains("analytics") Then
                                          Dim customBody As String = String.Empty
                                          e.Ok(Encoding.UTF8.GetBytes(customBody))
                                      End If
                                  ' *** Change to End Sub ***
                                End Sub)
        End Function
    
    
    /* 
    FYI there is a free Visual Studio extension called Code Converter to/from VB.NET . "Based on Roslyn, this converter allows you to convert C# code to VB.NET and vice versa.
     */
    

    external by StackOverflow  1  0  2  0

    converting from c# to vb.net byte

    i had tried to convert c# code to vb.net code. the c# code is : int m = 300; byte h = (byte)m; my vb code is : dim m as integer = 300 dim h as byte = cbyte(m) the error is: Message=Arithmetic operation resulted in an overflow. the expected value is: h value is 44 byte.
    /* 
    Your size cannot be more than 255
    
    
      Byte.MinValue (0) through Byte.MaxValue (255) (unsigned); fractional parts are rounded.1
      
      Starting with Visual Basic 15.8, Visual Basic optimizes the performance of floating-point to byte conversion with the CByte function; see the Remarks section for more information. See the CInt Example section for an example.
     */
    

    external by Oleg  1  0  2  0

    How to translate from C# to VB.net

    For a project written in VB.net I want to use the PropertyChangeNotifier class from this article, at least I'd like to try if it can help. Since the original class is written in C# I tried to translate this class to VB.net, but one function I can'T get to compile and I don't know why, maybe you can help. The original function in C# is: private s
    /* 
    
     */
      Private Shared Sub OnPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
          Dim notifier As PropertyChangeNotifier = CType(d, PropertyChangeNotifier)
          If notifier.ValueChanged IsNot Nothing Then RaiseEvent notifier.ValueChanged(notifier, EventArgs.Empty)
      End Sub
    
    
    /* 
    
     */
    
    • Public Snippets
    • Channels Snippets