working on it ...

Filters

Explore Public Snippets

Sort by

Found 28 snippets

    public by p.kontalis modified Jan 13, 2017  1102  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 modified Mar 4, 2016  2818  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 modified Oct 29, 2015  1790  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 modified Oct 28, 2015  197061  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 modified Oct 28, 2015  2130  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 modified Oct 28, 2015  2326  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 modified Aug 30, 2015  2015  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 Mythikos modified May 24, 2018  1  0  2  0

    What is the .NET 4.6 equivalent of VB6 MSXML2 nodeTypedValue?

    I have been tasked with upgrading an ancient application that was written in VB6 to VB.NET/.NET Framework 4.6. The program does quite a bit of XML parsing, most of which I have been able to convert to using the System.Xml library however I can't seem to figure out how to handle typed node values. The following appears all over the code: ' VB6 Dim
    /* 
    To anyone wondering about this, in order to resolve my issue, I ended up using the XmlDocument class to get the node's value from the XML, and then converted the string value to the datatype needed. For example,
     */
    string sValue = xmlDoc.SelectSingleNode("//testint").InnerText
    int iValue = Integer.Parse(sValue)
    
    
    /* 
    Integer.TryParse() would also be a great option if you are concerned about the data that may be retrieved.
     */
    

    external by Cylian modified Apr 20, 2018  1  0  2  0

    Search certain value in descendants with LINQ to XML with VB.Net

    This is a summary of my the xml file I'm working &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Devoluciones&gt; &lt;Remesa&gt; &lt;Archivo&gt;PRE20180403140755376539AD95PSPTJ7E6&lt;/Archivo&gt; &lt;TxInfAndSts&gt; &lt;OrgnlInstrId&gt;PRE20180403140755376539AD95PSPTJ7E6&lt;/OrgnlInstrId&gt; &lt;OrgnlEndToEndId&gt;5099&lt;/O
    /* 
    Yes, your query could be simplified...here's a one-liner:
     */
    Dim q = xdoc...<TxInfAndSts>.Where(Function(c) c.<OrgnlInstrId>.Count > 0 And c.<OrgnlInstrId>.First.Value = archivoSEPA).Where(Function(c) c.<OrgnlEndToEndId>.Count > 0 And c.<OrgnlEndToEndId>.First.Value = RefAdeudo)
    
    
    /* 
    Below is the sample stub for scrutiny:
     */
    Dim xdoc As XDocument = <?xml version="1.0" encoding="utf-8"?>
                                        <Devoluciones>
                                            <Remesa>
                                                <Archivo>PRE20180403140755376539AD95PSPTJ7E6</Archivo>
                                                <TxInfAndSts>
                                                    <OrgnlInstrId>PRE20180403140755376539AD95PSPTJ7E6</OrgnlInstrId>
                                                    <OrgnlEndToEndId>5099</OrgnlEndToEndId>
                                                    <StsRsnInf>
                                                        <Rsn>
                                                            <Cd>MD01</Cd>
                                                        </Rsn>
                                                    </StsRsnInf>
                                                </TxInfAndSts>
                                            </Remesa>
                                            <Remesa>
                                                <Archivo>PRE201804031123897319287123098AC78C</Archivo>
                                                <TxInfAndSts>
                                                    <OrgnlInstrId>PRE201804031123897319287123098AC78C</OrgnlInstrId>
                                                    <OrgnlEndToEndId>2141</OrgnlEndToEndId>
                                                    <StsRsnInf>
                                                        <Rsn>
                                                            <Cd>MD01</Cd>
                                                        </Rsn>
                                                    </StsRsnInf>
                                                </TxInfAndSts>
                                                <TxInfAndSts>
                                                    <OrgnlInstrId>PRE201804031123897319287123098AC78C</OrgnlInstrId>
                                                    <OrgnlEndToEndId>2313</OrgnlEndToEndId>
                                                    <StsRsnInf>
                                                        <Rsn>
                                                            <Cd>AC04</Cd>
                                                        </Rsn>
                                                    </StsRsnInf>
                                                </TxInfAndSts>
                                            </Remesa>
                                        </Devoluciones>
                Dim archivoSEPA$ = "PRE201804031123897319287123098AC78C", RefAdeudo% = 2313
                Dim q = xdoc...<TxInfAndSts>.Where(Function(c) c.<OrgnlInstrId>.Count > 0 And c.<OrgnlInstrId>.First.Value = archivoSEPA).Where(Function(c) c.<OrgnlEndToEndId>.Count > 0 And c.<OrgnlEndToEndId>.First.Value = RefAdeudo)
                If q.Count > 0 Then
                    MsgBox(IIf(q.First...<Cd>.Count > 0, q.First...<Cd>.First.Value, "No such element found!"))
                End If
    
    
    /* 
    Hope this helps...
     */
    

    external by StackOverflow modified Jan 31, 2018  1  0  2  0

    JavaScript confirm in ASP.NET 4.0 VB.Net

    I have tried multiple things I have found on the web. What I am looking for is just to confirm the user is hitting cancel to NOT save changes. I need the code on the server side to get the result from the confirm. I have a master page and 1 content page. I am new to using clientside so any help is greatly appreciated. Here is what I tried but
    /* 
    
    
    function cancelButtonClicked(event) {
      if (confirm("Confirm you don't want to save changes?")) {
    
        event.preventDefault();
        event.stopPropagation();
      }
    }
    <button type="button" onclick="cancelButtonClicked(event)">Cancel</button>
    
    
    
     */
    
    • Public Snippets
    • Channels Snippets