Friday, 6 June 2014

Date Time Format of date

CONVERT(VARCHAR(19),GETDATE())
CONVERT(VARCHAR(10),GETDATE(),10)
CONVERT(VARCHAR(10),GETDATE(),110)
CONVERT(VARCHAR(11),GETDATE(),6)
CONVERT(VARCHAR(11),GETDATE(),106)
CONVERT(VARCHAR(24),GETDATE(),113)
===========================================

return:

Nov 04 2011 11:45 PM
11-04-11
11-04-2011
04 Nov 11
04 Nov 2011
04 Nov 2011 11:45:34:243

For particular column then:

select convert(varchar(10),enter_date,110),college_name_removesc from affidavitdata

''enter_date is column

Thursday, 5 June 2014

Remove Duplicates from String

 Function rduplicatestring(ByVal str As String) As String
        rduplicatestring = ""
        Dim myarr() As String = Split(str, Space(1))
        myarr = myarr.Distinct().ToArray
        myarr = myarr.DefaultIfEmpty().ToArray
        rduplicatestring = Replace(Join(myarr, Space(1)), Space(2), Space(1))
        Return rduplicatestring
    End Function

Alphabetical Sorting Of any String Using vb.net

 Function alphabetsorting(ByVal str As String) As String
        alphabetsorting = ""
        Dim arrayLetters As Array = str.ToCharArray()
        Array.Sort(arrayLetters)
        For i As Integer = 0 To arrayLetters.Length - 1
            If alphabetsorting = "" Then
                alphabetsorting = arrayLetters(i)
            Else
                alphabetsorting = alphabetsorting & arrayLetters(i)
            End If
        Next
        Return alphabetsorting
    End Function

Wednesday, 4 June 2014

Add Images in Listbox and copy from one directory to another directory using vb.net

 Dim path1 As String = "D:\scan"
                My.Computer.FileSystem.CreateDirectory(path1)
                Dim info As New DirectoryInfo(path1)
                If (info.Exists) Then
                    Dim file As FileInfo = Nothing
                    file = info.GetFiles.Last
                    If (file.Extension = ".png") Then
                        ListBox1.Items.Add(file.FullName)
                    End If
                    PictureBox1.ImageLocation = fileName
                    i = 0
====================================================

For index As Integer = 0 To ListBox1.Items.Count - 1
            Dim src1 As String = ListBox1.Items(index.ToString())
            If Directory.Exists("D:MyScan\") Then
                Dim f1 As String = Path.GetFileName(src1)
                dest1 = Convert.ToString("D:\MyScan\") & f1
                File.Copy(src1, dest1)
                PictureBox1.Image = Nothing
            Else
                Directory.CreateDirectory("D:\MyScan\")
                Dim f1 As String = Path.GetFileName(src1)
                dest1 = Convert.ToString("D:\MyScan\") & f1
                File.Copy(src1, dest1)
                PictureBox1.Image = Nothing
            End If

Stop Sorting In Data Grid View using vb.net

Private Sub gridshot_ColumnAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles gridshot.ColumnAdded
        gridshot.Columns.Item(e.Column.Index).SortMode = DataGridViewColumnSortMode.NotSortable
    End Sub

How to count files in Specific Folder using vb.net

Imports System.IO
=====================
Public Class Form2
    Dim Files() As String
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim path1 As String = "D:\scan"
        Dim dr As New DirectoryInfo(path1)
        If dr.Exists Then
            Dim res As Integer = FileCount(path1)
            For i As Integer = 0 To res - 1
                Dim st As String = (Replace(Files(i), path1 & "\", ""))
                Dim re As String = Replace(st, ".jpg", "")
            Next
        End If
    End Sub
    Public Function FileCount(ByVal FolderName As String) As Integer
        Files = IO.Directory.GetFiles(FolderName)
        Return Files.Length
    End Function
End Class




rs return:1,2,3


Friday, 16 May 2014

Validate Phone number

 Shared Function removestdextra(ByVal phoneno As String, Optional ByVal stdcode As String = "", Optional ByVal compphno As String = "") As String
        If phoneno = "" Or phoneno Is Nothing Then Exit Function
        While phoneno.ToUpper.Contains("EXT") = True
            Dim expos = InStr(phoneno.ToUpper, "EXT")
            Dim expi = Mid(phoneno, expos, Len(phoneno))
            Dim expose1 = InStr(expi, ",")
            If expose1 = 0 Then expose1 = Len(expi) + 1
            phoneno = Replace(phoneno, Mid(phoneno, expos, expose1), ",")
        End While
        phoneno = Replace(phoneno.ToUpper, "+91", "")
        phoneno = phoneno.Replace("-", ",").Replace("/", ",")
        Dim newphoneno(Len(phoneno)) As String
        Dim j As Integer = 0
        For inct As Integer = 1 To Len(phoneno)
            If IsNumeric(Mid(phoneno, inct, 1)) Then
                newphoneno(j) = Mid(phoneno, inct, 1).Trim
                j = j + 1
            ElseIf Mid(phoneno, inct, 1) = "," Then
                newphoneno(j) = Mid(phoneno, inct, 1).Trim
                j = j + 1
            End If
        Next
        phoneno = Join(newphoneno, "")
        If phoneno.Contains("123456") Then phoneno = ""
        Dim extractno As String = ""
        Dim newvalid As String = ""
        newvalid = phoneno.Replace("-", ",").Replace("/", ",")
        Dim abc() As String
        abc = newvalid.Split(",")
        removestdextra = compphno
        Dim actualph As String = ""
        Dim lstno As String = ""
        Dim newno As String = ""
        For icnt As Integer = 0 To abc.Length - 1
            If abc(icnt).StartsWith(stdcode) And stdcode <> "" Then
                actualph = Val(Replace(abc(icnt), stdcode, "", 1).Trim)
            Else
                actualph = Val(abc(icnt))
            End If
            If Len(actualph) >= 6 Then
                extractno = validintergerphne(actualph).Trim
                If removestdextra = "" And extractno <> "" Then
                    removestdextra = extractno
                ElseIf removestdextra <> "" And extractno <> "" And InStr(removestdextra, extractno) = 0 Then
                    removestdextra = removestdextra & "," & extractno
                End If
            ElseIf Len(actualph) = 2 And icnt >= 1 And removestdextra <> "" And extractno <> "" Then
                If removestdextra <> "" Then
                    removestdextra = removestdextra & "," & Mid(extractno, 1, Len(extractno) - 2) & abc(icnt)
                End If
            ElseIf Len(actualph) = 3 And icnt >= 1 And removestdextra <> "" And extractno <> "" Then
                If removestdextra <> "" Then
                    removestdextra = removestdextra & "," & Mid(extractno, 1, Len(extractno) - 3) & abc(icnt)
                End If
            End If
        Next
        Return removestdextra
    End Function
=============================

   Shared Function validintergerphne(ByVal phno As String) As String
        validintergerphne = ""
        Dim newno As String = ""
        For validi As Integer = 1 To Len(phno)
            newno = Mid(phno, validi, 1)
            If IsNumeric(newno) Then
                validintergerphne = validintergerphne & newno
            End If
        Next
        If Len(validintergerphne) < 6 Then
            validintergerphne = ""
        ElseIf Val(validintergerphne) = 0 Then
            validintergerphne = ""
        End If
    End Function

Followers