working on it ...

Filters

Explore Public Snippets

Sort by

Found 29 snippets

    public by p.kontalis modified Jan 13, 2017  863  0  5  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  2675  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  1637  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  196896  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  2004  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  2191  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  1859  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 omajid modified Friday at 9:03:55 PM  1  0  2  0

    .NET Core 2.0 and VB - Is it available on the Mac OS ecosystem?

    I've been searching around and it seems like I can develop in C# on .NET Core 2 freely using Visual Studio Code. It looks like VB only comes with Microsoft's paid edition of Visual Studio (and I don't even know if VB is supported on MacOS). Is there a feasible way for me to develop a VB.NET app on MacOS using open source tools? Thanks!
    /* 
    The .NET Core stack itself is completely cross platform. So you can certainly write Visual Basic (.NET) code and build it using dotnet on Linux, macOS or Windows.
    
    For example, on my Linux box, I can do:
     */
    dotnet new console --language vb
    dotnet run
    
    
    /* 
    To see a working "Hello World!" application in Visual Basic.
    
    But for a nicer editing experience (with IntelliSense and so on) the open source tool would be VSCode. Unfortunately, it looks like VB Support is still not implemented in VSCode.
     */
    

    external by StackOverflow modified May 5, 2017  1  0  2  0

    First link to internal page works. Subsequent attempt causes Http 404 Error in ASP.net 2.0

    I am using ASP.net 2.0 in VS 2008 with Framework 3.5, VB.net codebehind I plan to build a website that would have a stationary menu on the left made with a TreeView in a fixed position div. A second div on the right would be for content. I have made a small test app to see if the concept works using Master / Content pages. I want the menu to be h
    /* 
    I was able to solve this by using the same concept in a single aspx form, rather than Master/Content. The menu is now in that single form and the codebehind pulls the data for the content. I do not know what was causing the Http 404 error, but using the single aspx form resolved it. Also, the URL must include a querystring, in the form of www.example.com?s=values, not www.example.com/keyword1-keyword2. The latter syntax also threw the 404 error.
     */
    

    external by Nelson-Chinedu modified Mar 25, 2017  1  0  1  0

    i'm having a problem on how to retrieve saved picture from mysql db to picture box and datagridview using vb.net 2010

    i'm having a problem on how to retrieve saved picture from mysql db to picture box and datagridview using vb.net 2010 : vb.net 2010
    Imports MySql.Data.MySqlClient
    Imports System.IO
    Imports System.Drawing
    
    Public Class children
        Dim conString As String = "server=localhost;database=foursquaredb;uid=root;password=;"
        Dim con As New MySqlConnection(conString)
        Dim cmd As MySqlCommand
        Dim adapter As MySqlDataAdapter
        Dim dt As New DataTable()
    
        Private Sub children_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView1.ColumnCount = 13
    
            DataGridView1.Columns(0).Name = "ID"
            DataGridView1.Columns(1).Name = "SurName"
            DataGridView1.Columns(2).Name = "FirstName"
            DataGridView1.Columns(3).Name = "LastName"
            DataGridView1.Columns(4).Name = "Sex"
            DataGridView1.Columns(5).Name = "Date Of Birth"
            DataGridView1.Columns(6).Name = "State Of Origin"
            DataGridView1.Columns(7).Name = "Residential Address"
            DataGridView1.Columns(8).Name = "Occupation"
            DataGridView1.Columns(9).Name = "Nationality"
            DataGridView1.Columns(10).Name = "Phone Number"
            DataGridView1.Columns(11).Name = "E-mail Address"
            DataGridView1.Columns(12).Name = "picture"
    
            DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        End Sub
        Private Sub cleartxt()
            surTxt.Text = ""
            firstTxt.Text = ""
            lastTxt.Text = ""
            sexTxt.Text = ""
            dobTxt.Text = ""
            stateTxt.Text = ""
            addressTxt.Text = ""
            occTxt.Text = ""
            natTxt.Text = ""
            phoneTxt.Text = ""
            emailTxt.Text = ""
    
        End Sub
        Private Sub populate(ByVal id As String, ByVal sur As String, ByVal first As String, ByVal last As String, ByVal sex As String, ByVal dob As String, ByVal state As String, ByVal address As String, ByVal occ As String, ByVal nat As String, ByVal phone As String, ByVal email As String, ByVal picture As String)
            Dim row As String() = New String() {id, sur, first, last, sex, dob, state, address, occ, nat, phone, email, picture}
    
            DataGridView1.Rows.Add(row)
        End Sub
        Private Sub retrieve()
            DataGridView1.Rows.Clear()
    
            Dim sql As String = "SELECT * FROM childrentb"
            cmd = New MySqlCommand(sql, con)
    
            Try
                con.Open()
                adapter = New MySqlDataAdapter(cmd)
                adapter.Fill(dt)
    
                For Each row In dt.Rows
                    populate(row(0), row(1), row(2), row(3), row(4), row(5), row(6), row(7), row(8), row(9), row(10), row(11), row(12))
                Next
                con.Close()
    
                dt.Rows.Clear()
            Catch ex As Exception
                MsgBox(ex.Message)
                con.Close()
            End Try
        End Sub
        Private Sub add()
            '
            Dim mstream As New System.IO.MemoryStream()
            PictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim arrImage() As Byte = mstream.GetBuffer()
            mstream.Close()
            '
            Dim sql As String = "INSERT INTO childrentb(Surname,Firstname,Lastname,Sex,Date_Of_Birth,State_Of_Origin,Residential_Address,Occupation,Nationality,Phone_Number,Email_Address,picture) VALUES(@surname,@firstname,@lastname,@sex,@dob,@state,@address,@occ,@nat,@phone,@email,@picture)"
    
            cmd = New MySqlCommand(sql, con)
    
            cmd.Parameters.AddWithValue("@surname", surTxt.Text)
            cmd.Parameters.AddWithValue("@firstname", firstTxt.Text)
            cmd.Parameters.AddWithValue("@lastname", lastTxt.Text)
            cmd.Parameters.AddWithValue("@sex", sexTxt.Text)
            cmd.Parameters.AddWithValue("@dob", dobTxt.Text)
            cmd.Parameters.AddWithValue("@state", stateTxt.Text)
            cmd.Parameters.AddWithValue("@address", addressTxt.Text)
            cmd.Parameters.AddWithValue("@occ", occTxt.Text)
            cmd.Parameters.AddWithValue("@nat", natTxt.Text)
            cmd.Parameters.AddWithValue("@phone", phoneTxt.Text)
            cmd.Parameters.AddWithValue("@email", emailTxt.Text)
            '
            cmd.Parameters.AddWithValue("@picture", arrImage)
            '
    
            Try
                con.Open()
                If cmd.ExecuteNonQuery() > 0 Then
                    MsgBox("RECORD SAVED", MsgBoxStyle.OkOnly, "MESSAGE")
                    cleartxt()
                End If
                con.Close()
                retrieve()
            Catch ex As Exception
                MsgBox(ex.Message)
                con.Close()
            End Try
        End Sub
        Private Sub updateDG(ByVal id As String)
            Dim sql As String = "UPDATE childrentb SET Surname='" + surTxt.Text + "' ,Firstname='" + firstTxt.Text + "', Lastname='" + lastTxt.Text + "',Sex='" + sexTxt.Text + "', Date_Of_Birth='" + dobTxt.Text + "', State_Of_Origin='" + stateTxt.Text + "', Residential_Address='" + addressTxt.Text + "', Occupation='" + occTxt.Text + "', Nationality='" + natTxt.Text + "', Phone_Number='" + phoneTxt.Text + "', Email_Address='" + emailTxt.Text + "' WHERE ID='" + id + "'"
    
            Try
    
                con.Open()
                adapter.UpdateCommand = con.CreateCommand
                adapter.UpdateCommand.CommandText = sql
    
                If adapter.UpdateCommand.ExecuteNonQuery() > 0 Then
                    MsgBox("successfully updated")
                    cleartxt()
                End If
                con.Close()
                retrieve()
            Catch ex As Exception
                MsgBox(ex.Message)
                con.Close()
            End Try
        End Sub
        Private Sub delete(ByVal id As String)
            Dim sql As String = "DELETE FROM childrentb WHERE ID='" + id + "'"
            cmd = New MySqlCommand(sql, con)
    
            Try
                con.Open()
                adapter.DeleteCommand = con.CreateCommand()
                adapter.DeleteCommand.CommandText = sql
    
                If MessageBox.Show("YOU ARE ABOUT TO REMOVE A RECORD", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.OK Then
                    If cmd.ExecuteNonQuery() > 0 Then
                        MsgBox("successfully Deleted")
                        cleartxt()
                    End If
                End If
                con.Close()
                retrieve()
            Catch ex As Exception
                MsgBox(ex.Message)
                con.Close()
            End Try
        End Sub
        Private Sub DataGridView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
            Dim surname As String = DataGridView1.SelectedRows(0).Cells(1).Value
            Dim firstname As String = DataGridView1.SelectedRows(0).Cells(2).Value
            Dim lastname As String = DataGridView1.SelectedRows(0).Cells(3).Value
            Dim sex As String = DataGridView1.SelectedRows(0).Cells(4).Value
            Dim dob As String = DataGridView1.SelectedRows(0).Cells(5).Value
            Dim state As String = DataGridView1.SelectedRows(0).Cells(6).Value
            Dim address As String = DataGridView1.SelectedRows(0).Cells(7).Value
            Dim occ As String = DataGridView1.SelectedRows(0).Cells(8).Value
            Dim nat As String = DataGridView1.SelectedRows(0).Cells(9).Value
            Dim phone As String = DataGridView1.SelectedRows(0).Cells(10).Value
            Dim email As String = DataGridView1.SelectedRows(0).Cells(11).Value
            Dim picture As Image = DataGridView1.SelectedRows(0).Cells(12).Value
    
            surTxt.Text = surname
            firstTxt.Text = firstname
            lastTxt.Text = lastname
            sexTxt.Text = sex
            dobTxt.Text = dob
            stateTxt.Text = state
            addressTxt.Text = address
            occTxt.Text = occ
            natTxt.Text = nat
            phoneTxt.Text = phone
            emailTxt.Text = email
            'PictureBox1.Image = picture
    
    
        End Sub
    
        Private Sub AddNewRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewRecordToolStripMenuItem.Click
            add()
        End Sub
    
        Private Sub DeleteRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteRecordToolStripMenuItem.Click
            Dim id As String = DataGridView1.SelectedRows(0).Cells(0).Value
                delete(id)
        End Sub
    
        Private Sub UpdateRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateRecordToolStripMenuItem.Click
            Dim id As String = DataGridView1.SelectedRows(0).Cells(0).Value
            updateDG(id)
        End Sub
    
        Private Sub RetrieveRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetrieveRecordToolStripMenuItem.Click
            retrieve()
        End Sub
    
        Private Sub ChildrenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChildrenToolStripMenuItem.Click
            Me.Show()
        End Sub
    
        Private Sub TeenagersToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TeenagersToolStripMenuItem.Click
            teenagers.Show()
            Me.Hide()
        End Sub
    
        Private Sub YouthToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YouthToolStripMenuItem.Click
            youth.Show()
            Me.Hide()
        End Sub
    
        Private Sub AdultToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdultToolStripMenuItem.Click
            adults.Show()
            Me.Hide()
        End Sub
    
        Private Sub OpenSavedRecordsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenSavedRecordsToolStripMenuItem.Click
            GroupBox2.Show()
        End Sub
    
        Private Sub CloseSavedRecordsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseSavedRecordsToolStripMenuItem.Click
            GroupBox2.Hide()
        End Sub
    
        Private Sub LogoutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogoutToolStripMenuItem.Click
            home.Show()
            Me.Hide()
            home.txtpass.Text = ""
            home.txtuser.Text = ""
        End Sub
    
        Private Sub phoneTxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles phoneTxt.KeyPress
            If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
                MsgBox("please enter numbers only from 0-9 and must not exceed 11 digits", MsgBoxStyle.Information, "MESSAGE")
                e.Handled = True
            End If
        End Sub
    
    
        Private Sub ChangePasswordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChangePasswordToolStripMenuItem.Click
            change_password.Show()
            Me.Enabled = False
        End Sub
    
        Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
            Dim resp As String
            resp = MsgBox("YOU ARE ABOUT TO CLOSE THIS PROGRAM", vbYesNo, "ALERT MESSAGE")
            If resp = vbYes Then
                End
            Else
                Exit Sub
            End If
        End Sub
    
        Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
            help.Visible = True
            Me.Enabled = False
        End Sub
    
        Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
            about.Visible = True
            Me.Enabled = False
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            OpenFileDialog1.Title = "please choose an image"
            OpenFileDialog1.InitialDirectory = "c:"
            OpenFileDialog1.ShowDialog()
            PictureBox1.ImageLocation = OpenFileDialog1.FileName.ToString
            PictureBox1.Visible = True
        End Sub
    End Class
    
    
    • Public Snippets
    • Channels Snippets