Sunday 31 July 2016

Hiding GetHashCode/Equals/ToString/GetType from Class

I get annoyed of these (by design) methods that appear in any class, because each class inherit from Object class, and they are part of the Object class.

Use This Code

#Region "Hide System Object"
    EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>
    <Browsable(False)> _
    Public  Shared Function Equals(ByVal obj As ObjectAs Boolean
        Return Nothing ' MyBase.Equals(obj)
    End Function

    EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
    <Browsable(False)> _
    Public Function GetHashCode() As Integer
        Return MyBase.GetHashCode
    End Function

    EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
    <Browsable(False)> _
    Public Function [GetType]() As Type
    End Function

    EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
    <Browsable(False)> _
    Public Overridable Function ToString() As [String]
        Return [GetType]().ToString()
    End Function

    EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
    <Browsable(False)> _
    Public Shared Function ReferenceEquals(objA As ObjectobjB As ObjectAs Boolean 
    End Function

#End Region




Tuesday 26 July 2016

imdb.dll (.NET version)

1- Register : the dll (only once is needed)

2- Login    : each time you will use the dll, you had to login with your account

3- SearchExact : Search for movie by its exact title

                 SearchExact("The Matrix") will return you many movies
                 SearchExact("The Matrix (1999)") will return 1 movie

                 Search also accept another parameter of how many movies to get                    back from search MAX is 10

4- depends on search, if one movie  : DownloadMovie then GetMovieInfo
                      If many movie : DownloadMovie(Title or Index) Then                                               GetMovieInfo

5- This is free DLL, you can use it in any personal software or commercial          software without prior notice.
        
6- There will be another version of imdb.dll (not free), where you can automate      the download without message interferance plus many other feature will be        avaliable only in the registered version.

7- There is imdb.xml file which must be in the same directory of imdb.dll
   in case of imdb changed its html layout, i don't had to create a imdb.dll to      match the new layout, neither the user/developer had to install new version      each time imdb.com changed the layout
    
   imdb.xml is the extract mechanism parameters I used to extract data from          imdb.com,so make sure to get the newest version of it.


8- Enjoy      

9- send email to samir.r.ibrahim@gmail(.)com for registered version and ask you      question in this blog so I can answer it.


Imports IMDb.IMDbEN
 
Public Class Form1
    Dim oIMDB As New IMDb.IMDb    
    Private Sub btn_Login_Click( sender As System.Object,  e As System.EventArgsHandles btn_Login.Click
        ' Login("Demo","Demo") is valid until 15/08/2016
        ' Please register it with yuor own "email" and "password". its free ;)
        Dim login_result = oIMDB.Login("Demo","Demo")
        If login_result = True
            btn_Search.Enabled = True
        Else
            btn_Search.Enabled = False
        End If
 
    End Sub
 
    Private Sub btn_Search_Click( sender As System.Object,  e As System.EventArgsHandles btn_Search.Click
        lst_1.Items.Clear
        lst_2.Items.Clear
        txt_FullInfo.Clear
        lvw.Items.Clear
        
        Dim search_result As IMDb_Search = oIMDB.SearchExact(txt_Search.Text,10)
        
        Select Case search_result
            'Check the result of the search. the search_result could be
            'IMDb_Search.Error      : IMDb_Search.ManyMovies  : IMDb_Search.NoInternet
            'IMDb_Search.NoResult   : IMDb_Search.NotLoggenIn : IMDb_Search.OneMovie
            Case IMDb_Search.OneMovie
                ' in case of one movie found, you should download the movie
                oIMDB.DownloadMovie()
                ' get the movie information such as (acter, director, writer, etc...)
                oIMDB.GetMovieInfo()
                ' get the full movie info in one place FullMovieInfo
                txt_FullInfo.Text = oIMDB.FullMovieInfo()
                ' get movie individual property by using [oIMDB.Movie]
                Call Me.sb_FillMovieProperty()
 
            Case IMDb_Search.ManyMovies
                ' in case of search result is ManyMovies, then you had to display the movies found
                ' so you can select which one you want to download
                Dim movies_found = oIMDB.GetFoundMovies()
                'the GetFoundMovie is a List of found movies as class
                'Public Class IMDBGetMovies_RETURN
                    'Property Title    As String
                    'Property TitleURL As String
                'End Class
                For i = 0 to movies_found.Count -1
                    lst_1.Items.add(movies_found(i).Title)
                    lst_2.Items.Add(movies_found(i).TitleURL)
                Next
 
            Case Else
                ' You can check for other error as mentions above and display a proper message.
                MsgBox(search_result.ToString)
        End Select                        
    End Sub
    
    Private Sub btn_DownloadByTitle_Click( sender As Object,  e As EventArgsHandles btn_DownloadByTitle.Click
        ' Download the movie from a list by its Title
        txt_FullInfo.Clear
        lvw.Items.Clear
        Dim dowbload_result = oIMDB.DownloadMovie(lst_1.SelectedItem.ToString)
        'the download result could be
        'IMDb_Download.Error        : IMDb_Download.Failed        : IMDb_Download.NoInternet
        'IMDb_Download.NotLogedIn   : IMDb_Download.SearchNotUsed : IMDb_Download.Success
        If dowbload_result = IMDb_Download.Success
            'If the download is success, get movie info
            oIMDB.GetMovieInfo()
            txt_FullInfo.Text = oIMDB.FullMovieInfo()
            Call Me.sb_FillMovieProperty()
        Else
            MsgBox(dowbload_result.ToString)
        End If
    End Sub
 
    Private Sub btn_DownloadByIndex_Click( sender As Object,  e As EventArgsHandles btn_DownloadByIndex.Click
        ' Download the movie from a list by index 
        txt_FullInfo.Clear
        lvw.Items.Clear
        Dim download_result = oIMDB.DownloadMovie(lst_2.SelectedIndex)        
        If download_result = IMDb_Download.Success
            oIMDB.GetMovieInfo()
            txt_FullInfo.Text = oIMDB.FullMovieInfo
            Call sb_FillMovieProperty()
        Else
            MsgBox(download_result.ToString)
        End If        
    End Sub
 
    Private Sub btn_RegisterIMDB_Click( sender As Object,  e As EventArgsHandles btn_RegisterIMDB.Click
        'Change below to register first, then you can use the dll
        'You can bypass register by using oIMDB.Login("demo","demo") until 15/08/2016
        oIMDB.Register("Your_User_Name","Your_Email_Address")
    End Sub
 
    Sub sb_FillMovieProperty()
 
        Dim Info As String() = <info>AspectRatio,Awards,Budget,Casting,CastingAs,
                                     Category,Color,Country,Director,Goofs,Gross,Language,
                                     Location,MPAA,Plot,PlotKeywords,ReleaseDate,Runtime,Score,
                                     SoundMix,StoryLine,Title,TitleOnly,Votes,Writers,Year</info>.Value.Split(",")
                         
 
        For i = 0 to Info.Length -1
            lvw.Items.Add(Info(i).TrimStart)
        Next
        For ix = 0 to lvw.Columns.Count -1
            lvw.Columns(ix).Width = -2
        Next
 
        lvw.Items(00).SubItems.Add(oIMDB.Movie.AspectRatio)
        lvw.Items(01).SubItems.Add(oIMDB.Movie.Awards)
        lvw.Items(02).SubItems.Add(oIMDB.Movie.Budget)
        lvw.Items(03).SubItems.Add(oIMDB.Movie.Casting)
        lvw.Items(04).SubItems.Add(oIMDB.Movie.CastingAs)
        lvw.Items(05).SubItems.Add(oIMDB.Movie.Category)
        lvw.Items(06).SubItems.Add(oIMDB.Movie.Color)
        lvw.Items(07).SubItems.Add(oIMDB.Movie.Country)
        lvw.Items(08).SubItems.Add(oIMDB.Movie.Director)
        lvw.Items(09).SubItems.Add(oIMDB.Movie.Goofs)
        lvw.Items(10).SubItems.Add(oIMDB.Movie.Gross)
        lvw.Items(11).SubItems.Add(oIMDB.Movie.Language)
        lvw.Items(12).SubItems.Add(oIMDB.Movie.Location)
        lvw.Items(13).SubItems.Add(oIMDB.Movie.MPAA)
        lvw.Items(14).SubItems.Add(oIMDB.Movie.Plot)
        lvw.Items(15).SubItems.Add(oIMDB.Movie.PlotKeywords)
        lvw.Items(16).SubItems.Add(oIMDB.Movie.ReleaseDate)
        lvw.Items(17).SubItems.Add(oIMDB.Movie.Runtime)
        lvw.Items(18).SubItems.Add(oIMDB.Movie.Score)
        lvw.Items(19).SubItems.Add(oIMDB.Movie.SoundMix)
        lvw.Items(20).SubItems.Add(oIMDB.Movie.StoryLine)
        lvw.Items(21).SubItems.Add(oIMDB.Movie.Title)
        lvw.Items(22).SubItems.Add(oIMDB.Movie.TitleOnly)    
        lvw.Items(23).SubItems.Add(oIMDB.Movie.Votes)
        lvw.Items(24).SubItems.Add(oIMDB.Movie.Writers)
        lvw.Items(25).SubItems.Add(oIMDB.Movie.Year)
 
    End Sub
 
    Private Sub Form1_Load( sender As System.Object,  e As System.EventArgsHandles MyBase.Load
        '1- Register : the dll (only once is needed)
 
        '2- Login    : each time you will use the dll, you had to login with your account
 
        '3- SearchExact : Search for movie by its exact title
                'SearchExact("The Matrix") will return you many movies
                'SearchExact("The Matrix (1999)") will return 1 movie
 
            'Search also accept another parameter of how many movies to get back from search MAX is 10
 
        '4- depends on search, if one movie  : DownloadMovie then GetMovieInfo
        '                      If many movie : DownloadMovie(Title or Index) : Then GetMovieInfo
 
        '5- This is free DLL, you can use it in any personal software or commercial software without prior notice.
        
        '6- There will be another version of imdb.dll (not free), where you can automate the download 
        ' without message interferance plus many other feature will be avaliable only in the registered version.
 
        '7- There is imdb.xml file which must be in the same directory of imdb.dll
        '   in case of imdb changed its html layout, i dont had to create a imdb.dll to match the new layout, neither the
        '   user/developer had to install new version each time imdb.com changed the layout
    
        '   imdb.xml is the extract mechanism parameters i used to extract data from imdb.com, so make sure to get the newst
        '   version or it
    
            
        '7- Enjoy
    End Sub
 
Private Sub Button1_Click( sender As System.Object,  e As System.EventArgsHandles btn_about.Click
        oIMDB.About
End Sub
End Class


Monday 8 December 2014

Filter datagridview from Datatable using LinqtoDataset, save the result

I got a situation where I have datagridview where its bindingsource is datatable from typed-dataset.

I want to make filter on 3 column, then add row to it.

I used this way

Filter the table and put the result in datagridview
Dim erc_Customer As EnumerableRowCollection(Of ds_northwind.CustomersRow)

erc_Customer = From t In Ds_northwind.Customers Where t.CompanyName.Contains("ou"Select t

dim dt as new ds_northwind.CustomersDataTable
dt.Merge(erc_Customer.CopyToDataTable)
bsCustomers.DataSource = dt

That for adding new Customer Row
bsCustomers.AddNew()

Save the new row
bsCustomers.EndEdit
taCustomers.Update(bsCustomers.DataSource)

Sunday 22 September 2013

Accept Only Integer in specific DatagridView Column or Cell

Public Class Form1
 
    Private Sub dgv1_EditingControlShowing(ByVal sender As ObjectByVal e As DataGridViewEditingControlShowingEventArgsHandles dgv1.EditingControlShowing
        If Me.dgv1.CurrentCell.ColumnIndex = 1 Then
            AddHandler e.Control.KeyPressAddressOf Handel_Column1_KeyPress
        End If
    End Sub
 
    Private Sub Handel_Column1_KeyPress(ByVal sender As System.Windows.Forms.DataGridViewTextBoxEditingControlByVal e As KeyPressEventArgs)
        If dgv1.CurrentCell.ColumnIndex = 1
            Dim valid_entry = "0123456789" + ChrW(Keys.Back)
            If valid_entry.Contains(e.KeyChar) Then
                e.Handled = False
            Else
                e.Handled = True
            End If
        End If
        
    End Sub
 
End Class

Wednesday 24 July 2013

VB Helper: HowTo: Get the values of fields (variables) declared in a form by their names in Visual Basic .NET

VB Helper: HowTo: Get the values of fields (variables) declared in a form by their names in Visual Basic .NET

Private private_value1 As String = "This is private value 1"
Private private_value2 As String = "This is private value 2"
Public public_value1 As String = "This is public value 1"
Public public_value2 As String = "This is public value 2"
Public arr1() As String = {"A", "B", "C"}
Public arr2() As String = {"1", "2", "3"}

Private Sub cboFields_SelectedIndexChanged(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    cboFields.SelectedIndexChanged
    Dim field_info As FieldInfo = _
        Me.GetType().GetField(cboFields.Text, _
        BindingFlags.Instance Or BindingFlags.NonPublic Or _
            BindingFlags.Public)
    If field_info Is Nothing Then
        lblValue.Text = ""
    ElseIf field_info.FieldType.IsArray() Then
        ' Join the array values into a string.
        lblValue.Text = Join(field_info.GetValue(Me))
    Else
        ' Just convert it into a string.
        lblValue.Text = field_info.GetValue(Me).ToString()
    End If
End Sub

Wednesday 26 June 2013

MS Access: DateDiff Function

MS Access: DateDiff Function

MS Access: DateDiff Function

In Microsoft Access, the DateDiff function returns the difference between two date values, based on the interval specified.

Syntax

The syntax for the DateDiff function is:
DateDiff ( interval, date1, date2, [firstdayofweek], [firstweekofyear])
interval is the interval of time to use to calculate the difference between date1 and date2. Below is a list of valid interval values.
IntervalExplanation
yyyyYear
qQuarter
mMonth
yDay of year
dDay
wWeekday
wwWeek
hHour
nMinute
sSecond
date1 and date2 are the two dates to calculate the difference between.
firstdayofweek is optional. It is a constant that specifies the first day of the week. If this parameter is omitted, Access assumes that Sunday is the first day of the week. This parameter can be one of the following values:
ConstantValueExplanation
vbUseSystem0Use the NLS API setting
vbSunday1Sunday (default)
vbMonday2Monday
vbTuesday3Tuesday
vbWednesday4Wednesday
vbThursday5Thursday
vbFriday6Friday
vbSaturday7Saturday
firstweekofyear is optional. It is a constant that specifies the first week of the year. If this parameter is omitted, Access assumes that the week containing Jan 1st is the first week of the year. This parameter can be one of the following values:
ConstantValueExplanation
vbUseSystem0Use the NSL API setting
vbFirstJan11Use the first week that includes Jan 1st (default)
vbFirstFourDays2Use the first week in the year that has at least 4 days
vbFirstFullWeek3Use the first full week of the year

Applies To

  • Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

For Example

DateDiff ("yyyy", #15/10/1998#, #22/11/2003#)would return 5
DateDiff ("m", #15/10/2003#, #22/11/2003#)would return 1
DateDiff ("d", #15/10/2003#, #22/11/2003#)would return 38

VBA Code

The DateDiff function can be used in VBA code. For example:
Dim LValue As Integer

LValue = DateDiff ("d", #15/10/2003#, #22/11/2003#)
In this example, the variable called LValue would now contain the value of 38.

SQL/Queries

You can also use the DateDiff function in a query.
Microsoft Access