Programming guides for beginner...
Any comments are welcomed....
I hope it helps!!! Thanks for drop by...

Tuesday, November 29, 2011

Simple Color Picker

I had been lazy to update this blog for few months. Today, I will be showing one of my simple project. I had been doing web design for the last few months and I found out that picking a color is quite a difficult job. I design a simple color picker application.
This application is quite simple but might be a bit lagging when moving the mouse around to pick color. I am lazy to fix some of the bugs since it didn't cause any error.

I will show the step of using the program and for those who interested, you can download the program at here.

Step 1:
Start the program.


The program will look like the above picture.

Set your shortcut keys by checking the checkbox and choosing your key from the combo box.
Press the set button to Set it.
Then press Stand by button to start monitoring.

Step 2:

Press the shortcut keys you set before. In this example was (Alt +1 ). After that, you can start clicking on anywhere you want on your desktop.

The color that show in the panel above the picture was the color that you pick. You may move your mouse around (might cause lagging) and when you got your color, press enter.
If you check on the checkbox for "Copy Color Picker Code to Clipboard", then the color code (as what you can see from the picture "Color[A=255, R=104, G=165, B=64]") will be copy.
You can also press escape to stop picking. Nothing will be copied to the clipboard when escape was press.

Hope you enjoy the program. Please report any bug to me if you want it to be solved.
I will try to solve if possible.

For those who want to download, please visit my website at here.



Saturday, July 30, 2011

Some simple features of css3

I believe that there are many people whom designing their blog or website using CSS.

1) What is CSS
  • CSS stands for Cascading Style Sheets.

2) What does CSS use for?
  • CSS is use to design web page. Previously, the styling of html webpage is done internally with the html coding. With CSS, these styling coding can be done externally which save a lot of works and make html coding cleaner in view.

3) What is CSS3?
  • CSS3 is the latest standard for CSS. It has new interesting features which cannot be done in older standard of CSS.
Here is some examples of CSS3: (* CSS3 might not works with old version of internet browser. In order to view these features perfectly, get the latest internet browser. )

1)Text Transform
Text Transform 50 degree.


Coding:
{
transform:rotate(50deg);
-ms-transform:rotate(50deg); /*IE*/
-moz-transform:rotate(50deg); /*Firefox*/
-webkit-transform:rotate(50deg); /*Chrome and Safari*/
-o-transform:rotate(50deg); /*Opera*/
}



2)Rounded Corner

ROUND CORNER AT THE BRODER


Coding:
{
border:2px green solid;
border-radius:25px;
-moz-border-radius:25px;/*Firefox*/
}



3)Shadow

Shadow of the box


Coding:
{
box-shadow: 10px 10px 5px #888888;
-moz-box-shadow: 10px 10px 5px #888888; /*Firefox*/
-webkit-box-shadow: 10px 10px 5px #888888; /*Safari*/
}



Shadow of Text



Coding:
{
text-shadow: 10px 10px 3px #FF0000;
}


4) Box re-size


This box is re-sizable but the minimum size is fixed.


Coding:
{
resize: both;
}



With these few css3 features, I believe that it will make your webpage looks more nicer.
There are still a lot of new features in css3 which you can refer to here.



Tuesday, June 14, 2011

Modified Tic Tac Toe with computer player

    

     As “bluedot” ask me for guides to create a computer player in Tic Tac Toe, I make a decision to create the AI user. Previously, I had created a two player Tic Tac Toe game in Visual Basic 2008 and also posted a video in YouTube. Due to my slow upload speed, I had decided not to upload videos this recent. So, I will just show some pictures on the my Tic Tac Toe with computer player.

7

This is the default Tic Tac Toe with two players.

8

       There are options for player vs player, player vs easy com, and player vs normal com. The difference between easy and normal com is that easy com will click randomly while normal com will try to win first before blocking player from wining. Playing with normal com might get more draws than winning or losing. Following are some pictures:

910115

 

     For those who want to try this game, please feel free to download at my website (will be available soon). Please comment on any bugs and improvements that can be done.  For those who want to have the source, please leave your email at the comment. I will send it to you asap.

Sudoku game with 9x9 and 16x16 by VB.Net

Recently, I am quite lazy to update this blog. I had done this Sudoku game since last month. This Sudoku game will randomly create and user is provided with option for 9x9 and 16x16. For 9x9 Sudoku game, the apps will generate in just few seconds. For 16x16 game, I am still figuring out how to make the game generate faster. It might took up to 2-3 minutes to generate for 16x16 Sudoku (sometimes just few seconds).

At here I will show so picture of the game and I will upload the game for downloading in my website asap.

imageThe interface for 9x9 Sudoku game

image image

The interface for 16x16 Sudoku game without and with solution shown.

Please comment and also for those who want to have a look in this source code, please leave me your email at the comment so that I can send you the sources.

Sunday, May 1, 2011

Another Google AdWords Free Voucher to share.

 

          Here, I would like to share my Google AdWords voucher which given free by Google to me. This voucher can be used for advertising. The voucher value is RM125 and might be useful to those who planned to start out a small business. Since I had nothing to advertise, I shared it here for someone who need it. This voucher can only be claimed once so FIRST COME FIRST GET.

          Reminder, this voucher is for those who don’t have Google AdWords account. You will need to sign up here. This may require you to pay a minimum of RM20* activation fee.

When you sign up, there is a called ‘Promotional Code’ field where you can enter unique voucher code(including dashes). You can enter the following code to claim free RM125.

5NHR-HG6A-VPSK-3GVD-5TQS

The voucher expires on 15th May 2011.

 

*The activation fee might not be the latest. Refer to Google AdWords for confirmation.

Saturday, April 16, 2011

Picture Editor for inserting Text in VB.Net

 

      It had been few weeks after my last post. In this post, I will show a simple application that might be useful to some of you. A picture editor that only use for inserting text. As “picture speaks a thousand words”, I will show picture rather than explaining too much.

 

3First, open a picture from file menu.

12

Move your mouse cursor to where you want the text to be written to.
Notice that there are X and Y. X is to show mouse position X and Y is to show mouse position Y. After decide with the position, press enter and a textbox will appear at the top left. Enter the text you wish to. The font of the text can be changed by selecting from the option above.

15

The color of the text can also be changed by selecting from the option above.

9

After finish typing and changing text option, to write the string to the picture, just click on the yellow color button at the bottom right. The text will show and the button will turn green.

10

This is the result of the text. If you wish to save the picture, just click on the green button. If you wish to continue, you can return to above steps or you can actually insert your own X and Y position and press enter to insert text.

 

This picture editor will be uploaded in my website soon and I hope that it will helps someone who needs it.

Saturday, March 19, 2011

My simple way of XML serialization and deserialization in VB.net

 

         XML (Extensible Markup Language) is a language that designed to transport and store data. It is an universal language that can be used in many programming languages to store data. XML serialization is the method to import data into XML file while XML deserialization is the method to export data from XML file. I had created a method of serialization and deserialization of XML which might be used by most of the people but still, there are some people that don’t know how these works in VB.net.

        Here I included a sample test for my method. I put 11 checkboxes , 5 radiobuttons and 1 combobox in a form shown in the picture below.

image

Then insert the coding as following into this form source code.

Public Class Form1
Public str_filesavepath As String
Dim obj As New XML
Private Sub Form1_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
obj.submit()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
str_filesavepath = Environment.CurrentDirectory & "\Setting.xml"
If Not IO.File.Exists(str_filesavepath) Then
obj.submit()
End If
obj.getsetting()
End Sub
End Class

Create a class from Project>Add Class. Insert the following coding into the class.

Imports System.IO
Imports System.Xml.Serialization

Public Class XML

Public Sub submit()
Dim setting As New Properties()
setting.RadioButton1 = Form1.RadioButton1.Checked.ToString
setting.RadioButton2 = Form1.RadioButton2.Checked.ToString
setting.RadioButton3 = Form1.RadioButton3.Checked.ToString
setting.RadioButton4 = Form1.RadioButton4.Checked.ToString
setting.RadioButton5 = Form1.RadioButton5.Checked.ToString
setting.checkbox1 = Form1.CheckBox1.CheckState
setting.checkbox2 = Form1.CheckBox2.CheckState
setting.checkbox3 = Form1.CheckBox3.CheckState
setting.checkbox4 = Form1.CheckBox4.CheckState
setting.checkbox5 = Form1.CheckBox5.CheckState
setting.checkbox6 = Form1.CheckBox6.CheckState
setting.checkbox7 = Form1.CheckBox7.CheckState
setting.checkbox8 = Form1.CheckBox8.CheckState
setting.checkbox9 = Form1.CheckBox9.CheckState
setting.checkbox10 = Form1.CheckBox10.CheckState
setting.checkbox11 = Form1.CheckBox11.CheckState
setting.combobox1 = Form1.ComboBox1.Text
setting.Savefilepath = Form1.str_filesavepath
SerializeToXML(setting)
End Sub
Public Sub SerializeToXML(ByVal setting As Properties)
Dim serializer As New XmlSerializer(GetType(Properties))
Dim textWriter As TextWriter = New StreamWriter(Environment.CurrentDirectory _
& "\Setting.xml")
serializer.Serialize(textWriter, setting)
textWriter.Close()
End Sub


Public Sub getsetting()
Dim deserializer As New XmlSerializer(GetType(Properties))
Dim textReader As TextReader = New StreamReader(Environment.CurrentDirectory _
& "\Setting.xml")
Dim setting As Properties
setting = DirectCast(deserializer.Deserialize(textReader), Properties)
textReader.Close()
getData(setting)
End Sub

Public Sub getData(ByVal setting As Properties)
Form1.RadioButton1.Checked = setting.RadioButton1.ToString
Form1.RadioButton2.Checked = setting.RadioButton2.ToString
Form1.RadioButton3.Checked = setting.RadioButton3.ToString
Form1.RadioButton4.Checked = setting.RadioButton4.ToString
Form1.RadioButton5.Checked = setting.RadioButton5.ToString
Form1.CheckBox1.Checked = setting.checkbox1
Form1.CheckBox2.Checked = setting.checkbox2
Form1.CheckBox3.Checked = setting.checkbox3
Form1.CheckBox4.Checked = setting.checkbox4
Form1.CheckBox5.Checked = setting.checkbox5
Form1.CheckBox6.Checked = setting.checkbox6
Form1.CheckBox7.Checked = setting.checkbox7
Form1.CheckBox8.Checked = setting.checkbox8
Form1.CheckBox9.Checked = setting.checkbox9
Form1.CheckBox10.Checked = setting.checkbox10
Form1.CheckBox11.Checked = setting.checkbox11
Form1.ComboBox1.Text = setting.combobox1
Form1.str_filesavepath = setting.Savefilepath
End Sub

End Class

And add another class with the following coding.


Public Class Properties
Private Radiobutton(4) As String
Private Checkbox(10) As String
Private combobox(0) As String
Private filepath(1) As String
Public Property RadioButton1()
Get
Return Radiobutton(0)
End Get

Set(ByVal Value)
Radiobutton(0) = Value
End Set
End Property
Public Property RadioButton2()
Get
Return Radiobutton(1)
End Get

Set(ByVal Value)
Radiobutton(1) = Value
End Set
End Property

Public Property RadioButton3()
Get
Return Radiobutton(2)
End Get

Set(ByVal Value)
Radiobutton(2) = Value
End Set
End Property
Public Property RadioButton4()
Get
Return Radiobutton(3)
End Get

Set(ByVal Value)
Radiobutton(3) = Value
End Set
End Property
Public Property RadioButton5()
Get
Return Radiobutton(4)
End Get

Set(ByVal Value)
Radiobutton(4) = Value
End Set
End Property
Public Property checkbox1()
Get
Return Checkbox(0)
End Get
Set(ByVal value)
Checkbox(0) = value
End Set
End Property

Public Property checkbox2()
Get
Return Checkbox(1)
End Get
Set(ByVal value)
Checkbox(1) = value
End Set
End Property

Public Property checkbox3()
Get
Return Checkbox(2)
End Get
Set(ByVal value)
Checkbox(2) = value
End Set
End Property

Public Property checkbox4()
Get
Return Checkbox(3)
End Get
Set(ByVal value)
Checkbox(3) = value
End Set
End Property
Public Property checkbox5()
Get
Return Checkbox(4)
End Get
Set(ByVal value)
Checkbox(4) = value
End Set
End Property
Public Property checkbox6()
Get
Return Checkbox(5)
End Get
Set(ByVal value)
Checkbox(5) = value
End Set
End Property

Public Property checkbox7()
Get
Return Checkbox(6)
End Get
Set(ByVal value)
Checkbox(6) = value
End Set
End Property
Public Property checkbox8()
Get
Return Checkbox(7)
End Get
Set(ByVal value)
Checkbox(7) = value
End Set
End Property

Public Property checkbox9()
Get
Return Checkbox(8)
End Get
Set(ByVal value)
Checkbox(8) = value
End Set
End Property

Public Property checkbox10()
Get
Return Checkbox(9)
End Get
Set(ByVal value)
Checkbox(9) = value
End Set
End Property
Public Property checkbox11()
Get
Return Checkbox(10)
End Get
Set(ByVal value)
Checkbox(10) = value
End Set
End Property
Public Property combobox1()
Get
If combobox(0) = Nothing Then
Return "F5"
Else
Return combobox(0)
End If

End Get
Set(ByVal value)
combobox(0) = value
End Set
End Property
Public Property Savefilepath()
Get
Return filepath(1)
End Get
Set(ByVal value)
filepath(1) = value
End Set
End Property

End Class


With this, the XML serialization and deserialization will works. You might be thinking how to test whether it is working or not….


   To the the coding, just simply run the program and check or uncheck any checkbox and radiobutton. Beside that, you can also change the text in combobox. The default text in combobox is “F5” which is hard-coded in the coding. When you close the program, a Setting.xml file will be created in the directory where the .exe file is. You can open it with notepad or other text editor and you will see that any changes you makes will save inside the file. When you rerun the program, you can see that all changes had been saved.


    This is how xml file works nowadays. It used to stored data and then restores it back when you need it.

Sunday, March 13, 2011

My first Android apps–Bit Converter

 

   As my friend, Meng Suan and I planned to write a program for Bit Converter in android since October 2010, he had actually completed his program on 7th November 2010 and posted on his blog while I completed mine but not for android. Mine is in Visual Basic (posted at another blog of mine which is not updated for quite a long time) while he had done it using Google App Inventor within a day but as I mentioned in my previous post that I started to work at November 2010, I had no time for new programming language and at that time, I think that Java is a very hard programming language.

   The thought changes after I had been works for 3+ months. I had learnt from my supervisor that most of the languages are almost the same. The differences between programming languages is just the syntax. He said that, if you know the concept, it won’t be difficult at all. With this kind of thinking, I try to explore more about Eclipse and Java. I had downloaded some video tutorials from here. These videos are very useful for beginner in Eclipse and Java.

The following are pictures from my emulator showing my Bit Converter apps.

1

The interfaces with radio buttons selection for one kilo = 1024 or one kilo = 1000.

2

When click on the buttons, a dialog with radio buttons will shows.

3

The continue of the dialog. The conversion till Petabytes (same as my bit converter in visual basic)

4

The output after you select the unit you wish to convert to.

To download this apps, please visit my website. Please leave comments on any curiosity.

The Earth or the World going to the end?

    As the Moon is getting nearer to the Earth, rumors say that this “SuperMoon” might be the cause to Japan Earthquake. There are few scientists stated that “SuperMoon” is not the cause of Japan Earthquake. As the Earthquake occurs, it cause tsunami and effecting about 52 countries in the Earth (correct me if I am wrong).

   Previously, an independent Christian group in the U.S. predicted that 21st May 2011 is the End. With the Earthquake in Japan and the “SuperMoon” that coming soon in 19th March 2011, many might believe that doomsday is coming. I believed that there were many that asked a similar question before, “One thing that you want to do when you going to die.” May be those who view this post might want to share your wanted to do thing before doomsday. You are welcome to leave comment. As for me, I would like to learn more things before doomsday.

   As from my post title, I am actually curious about the saying of doomsday. Many said that doomsday == the end of World. As from here, I would like to ask, is the “World” here means the Earth, or the Universe? Does it include the Galaxy? Is doomsday apply to the Earth only or it is actually apply to the Universe?

Hope I will get my answer and hope everyone will pray for the World or may be the Earth.

Sunday, March 6, 2011

Polls for my blog

 

  As I am busy since I started to work last year November, I have not much time to spend in my blog. As from the title, I would like to inform anyone who visited my blog, I had created a polls provided by Nuffnang. I hope to get some response from you who is reading this now.

I would like to know is my tutorials help you…?

How much does it help you…?

Do you ever download any programs from my website…?

Just three simple questions. I hope to get responds so that I would know whether should I often update more tutorials…

If I got good responds, I would try my best to update more of tutorials in other languages such as C#, or C# with asp.net. Thanks for voting.

Sunday, February 20, 2011

Getting all files in directory include sub directories in vb.net

 

     As from my previous tutorial on Simple Music Player, I had mentioned that the function that I wrote to getting all songs in the directory is not possible. Now, I had found out a method by using VB.Net Stack. VB.Net Stack is a collection that stores items that being push in. It uses the concept of Last In First Out (LIFO). Although this method list out all the files in directory, as for its’ LIFO system, it will list the files from the last. (Means the last to come will be the first to out.)

Here I includes the coding that need to be changes and also a function that used to get all files.

Private Sub ListView1_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles ListView1.DragDrop
Dim colFiles() As String = e.Data.GetData(DataFormats.FileDrop, True)
For i = 0 To colFiles.Count - 1
Dim list As List(Of String) = GetAllFiles.GetFileList(colFiles(i))
For Each path In list
ListView1.Items.Add(System.IO.Path.GetFileName(path))
ListView2.Items.Add(path)
Next
Next
End Sub

I use loop for data that drop into listview1 is to handle when there is more than one directory being drag into listview1.


 


And here, I includes the function that used to get all files in a directory which include all sub directories.

Public Class GetAllFiles

Public Shared Function GetFileList(ByVal Dirpath As String) As List(Of String)
Dim result As New List(Of String)
Dim store As New Stack(Of String)
store.Push(Dirpath)

Do While (store.Count > 0)
Dim dir As String = store.Pop
Try
result.AddRange(Directory.GetFiles(dir, "*.mp3*"))

'change here to load music file in other formats. Not all formats are supported.
Dim directoryName As String
For Each directoryName In Directory.GetDirectories(dir)
store.Push(directoryName)
Next
Catch ex As Exception
End Try
Loop
Return result
End Function

End Class

Credited to this site where I found this method. Thanks a lot.

Wednesday, February 9, 2011

Enhanced version of print screen program from previous post.

 

       When I am doing step-by-step tutorial on Simple Music Player, I used my previous print screen program. When using the program, I found out that there are still improvement that need to be done.

       I had added a new function which is editing the picture after the print screen with Microsoft Paint. This function can be activated by checking on the menu. Besides that, I have added features to auto save function. User will able to enter an integer for the saved pictures to be named.

For those who want to download and test the enhanced version, please visit http://programmingbeginner.zxq.net/download.php.

Tuesday, February 8, 2011

My first step-by-step tutorial on Simple Music Player (VS2008) Part III

 

     Continue from my previous post of Part I & Part II, this will be the last part of Simple Music Player. When you completed this part, you will be able to use the Music Player to play songs.

     The following coding in the “Check next songs” region is a function that used to check for next songs when current songs finish played. It also stops play when the playlist reached the end. The region for “timer start” is a function when a timer start ticking. The coding can also be approach by double click on timer1 that being added to the interface in Part I.

31

Your code should look like the above picture.

#Region "Check next songs"
    Private Sub Check_Next_Media()
        If int_currplayindex >= ListView1.Items.Count - 1 Then
            Timer1.Stop()
            objAudio.Stop()
            Button1.Text = "Play"
            b_musicEnding = True
            b_musicplaying = False
            Exit Sub
        End If
        b_musicEnding = False
        int_currplayindex += 1
        str_filepath = CStr(ListView2.Items.Item(int_currplayindex).Text)
        objAudio = New Audio(str_filepath, False)
        objAudio.Play()
    End Sub
#End Region

#Region "timer start"
    Private Sub Timer1_Tick(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs) _
                            Handles Timer1.Tick
        ListView1.Items.Item(int_currplayindex).BackColor = Color.Blue
        'change the color here to show current playing music.
        If objAudio.CurrentPosition = objAudio.Duration Then
            b_musicEnding = True
        Else
            b_musicEnding = False
        End If
        If b_musicEnding = True Then
            ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
            Check_Next_Media()
        End If
    End Sub
#End Region

     After the the previous Part I & Part II, and also the above coding, you should be able to test your Player now. Press F5 to run the program. Now, you might faced a problem as shown in the picture below:


14



To solve this problem, you will need to change the exception.  Look for Debug | Exceptions. In Exceptions dialog, look for loaderlock in Managed Debugging Assistants and uncheck it at Thrown as shown in the picture below.


15


After that, you should have a working Music Player. If there is still problems, please feel free to leave a comment. I will try my best to help. Open-mouthed smile

Sunday, January 30, 2011

My first step-by-step tutorial on Simple Music Player (VS2008) Part II

 

     After the First Part of my step-by-step tutorial which is the Interface of the Music Player, now I will start with the coding.

     First of all, to use Microsoft.DirectX.AudioVideoPlayback reference that added in previous post, add this line:

“Imports Microsoft.DirectX.AudioVideoPlayback”

to the coding. To open the coding, press F7. The following picture shows the position of the line.


6


The line is added at the most top outside the class.


     After that, we will need to declare some variables for later use.


8


Comments are added besides the coding as to explain the use of each variable. "#Region" is use to separate coding into region and for this one, I use declaration as the region name. You can use any name you like as it is just to understand what the region use for.


Code to be copied:



#Region "declaration"
    Public WithEvents objAudio As Audio
    Private b_musicplaying As Boolean  'use to store music play state
    Private b_musicEnding As Boolean  'use to check end of music
    Private b_loadmusic As Boolean 'use to check loaded music
    Private int_currplayindex As Integer 'use to store current playing index
    Private str_filename As String 'use to store current filename
    Private str_filepath As String 'use to store current filepath
    Private clr_previous As Color 'use to store color for previouly played music
#End Region

Public WithEvents objAudio As Audio


use to set objAudio as Audio in the DirectX (obj means object - this will make user to clear about what we assign to objAudio. objAudio had been assigned with Audio with include the events.)


After declaration, I will continue with the method of drag in music files into the listview1.


 


9


10


11


I didn't explain much in this drag in or drag drop method. For any private sub that handles the object we drag into our interface, you can look at the top where it shows ListView1 in the above picture. If you move your mouse there, a tooltip balloon will show "Class Name" and beside it is "Method Name".


As I mention in the method, I actually modified someone method of looking for directory inside directory... Means look for files inside two layer of directories. I modified it so that when I drag in a folder which contains folders that having a lot of songs inside, it will add the filename into ListView1 and filepath into ListView2.


Code to be copied:


#Region "file_dragenter"


    'this method is being modified from someone else.
    'Sorry for forget his name.
    'This method will only works with two layer directories.
    'Will not works if the files is deep inside more than two layer directories
    'If anyone knows how to loop to find all files in deep, please share it with me. Thanks


    Private Sub ListView1_DragDrop(ByVal sender As Object, _
                                   ByVal e As System.Windows.Forms.DragEventArgs) _
                                   Handles ListView1.DragDrop
        Dim I, iMaxFiles As Integer
        Dim iMaxDir As Integer
        Dim oFileName As String
        Dim str_path As Array
        Dim colFiles() As String = e.Data.GetData(DataFormats.FileDrop, True)
        Dim filelength As Double
        iMaxFiles = colFiles.GetUpperBound(iMaxFiles)
        If iMaxFiles = 0 Then


        End If
        For I = 0 To iMaxFiles
            oFileName = System.IO.Path.GetFileName(colFiles(I))
            filelength = colFiles.Length
            Try
                System.IO.Directory.GetDirectories(colFiles(I))
                If System.IO.Directory.GetDirectories(colFiles(I)).Length > 0 Then
                    iMaxDir = System.IO.Directory.GetDirectories(colFiles(I)).GetUpperBound(iMaxDir)
                    str_path = System.IO.Directory.GetDirectories(colFiles(I))
                    For j = 0 To iMaxDir
                        Dim di As New IO.DirectoryInfo(str_path(j))
                        Dim diar1 As IO.FileInfo() = di.GetFiles("*.mp3") 'change here for other format of files
                        Dim dra As IO.FileInfo
                        For Each dra In diar1
                            ListView1.Items.Add(dra.ToString)
                            ListView2.Items.Add(str_path(j) & "\" & dra.ToString)
                        Next
                    Next
                Else
                    Dim di As New IO.DirectoryInfo(colFiles(I))
                    Dim diar1 As IO.FileInfo() = di.GetFiles("*.mp3") 'change here for other format of files
                    Dim dra As IO.FileInfo


                    For Each dra In diar1
                        ListView1.Items.Add(dra.ToString)
                        ListView2.Items.Add(colFiles(I) & "\" & dra.ToString)
                    Next
                End If
            Catch ex As Exception
                ListView1.Items.Add(oFileName)
                ListView2.Items.Add(colFiles(I))
            End Try
        Next
    End Sub



    Private Sub ListView1_DragEnter(ByVal sender As Object, _
                                    ByVal e As System.Windows.Forms.DragEventArgs) _
                                    Handles ListView1.DragEnter


        e.Effect = DragDropEffects.Copy


    End Sub
#End Region


Reminder:Remember to change your listview1 properties (allowdrop to true). Now you can try to drag and drop a folder into listview1. To do this, you will need to debug the program by pressing F5. Only mp3 files can be drop in if you didn't change the format at here:


Dim diar1 As IO.FileInfo() = di.GetFiles("*.mp3") 'change here for other format of files

 


Now, we will come to the construction part where the main coding works here.


2224252628


The above picture shows what happens when the form is loaded, button1,2,3,4 being clicked, listveiw1 being clicked and double clicked. The coding to be copied is provided as following:



#Region "construction"
    Private Sub SimpleMusicPlayer_Load(ByVal sender As System.Object, _
                                       ByVal e As System.EventArgs) _
                                       Handles MyBase.Load


        'occurs when form load
        clr_previous = Color.DarkGray 'change previouly played music color here


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles Button1.Click


        'occurs when button1 (Play) clicked
        If b_loadmusic = False Then Exit Sub 'exit if no music loaded
        If b_musicplaying = True Then   'if music playing now
            objAudio.Pause()
            Button1.Text = "Play"   'change text from pause to play
            b_musicplaying = False  'set playing as false as music is paused
        ElseIf b_musicplaying = False Then
            Timer1.Start()  'start timer1 - use to check when music end.
            Try
                objAudio.Stop()
            Catch ex As Exception
            End Try
            objAudio.Play()         'play the music
            Button1.Text = "Pause"  'change text from play to pause
            b_musicplaying = True   'set playing as true as music started
        End If


    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles Button2.Click


        'occurs when button2 (Stop) clicked


        If b_loadmusic = False Then Exit Sub 'exit if no music loaded
        objAudio.Stop() 'stop the music
        ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
        Timer1.Stop()   'stop timer1 as music consider ended.
        Button1.Text = "Play"   'change text from pause to play
    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles Button3.Click


        If b_loadmusic = False Then Exit Sub
        If objAudio.Playing = True Then
            Try
                objAudio.Stop()
                ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
                int_currplayindex = int_currplayindex - 1
                If int_currplayindex < 0 Then
                    int_currplayindex = ListView1.Items.Count - 1
                End If
                ListView1.Items.Item(int_currplayindex).Selected = True
                ListView1.Items.Item(int_currplayindex).EnsureVisible()
                Try
                    If int_currplayindex < 0 Then Exit Try
                    str_filepath = CStr(ListView2.Items.Item(int_currplayindex).Text) 'getting file path
                    objAudio = New Audio(str_filepath, False)  'method to load music
                    b_loadmusic = True
                    objAudio.Play()
                Catch ex As Exception
                End Try
            Catch ex As Exception
            End Try
        End If
    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles Button4.Click


        If b_loadmusic = False Then Exit Sub
        If objAudio.Playing = True Then
            Try
                objAudio.Stop()
                ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
                int_currplayindex = int_currplayindex + 1
                If int_currplayindex > ListView1.Items.Count - 1 Then
                    int_currplayindex = 0
                End If
                ListView1.Items.Item(int_currplayindex).Selected = True
                ListView1.Items.Item(int_currplayindex).EnsureVisible()
                Try
                    If int_currplayindex < 0 Then Exit Try
                    If int_currplayindex > ListView1.Items.Count - 1 Then
                        int_currplayindex = 0
                    End If
                    str_filepath = CStr(ListView2.Items.Item(int_currplayindex).Text) 'getting file path
                    objAudio = New Audio(str_filepath, False)  'method to load music
                    b_loadmusic = True
                    objAudio.Play()
                Catch ex As Exception
                End Try
            Catch ex As Exception
            End Try
        End If


    End Sub


    Private Sub ListView1_Click(ByVal sender As Object, _
                                ByVal e As System.EventArgs) _
                                Handles ListView1.Click


        If b_musicplaying = True Then Exit Sub 'do nothing if music playing.
        If int_currplayindex <> Nothing Then
            Try
                If ListView1.SelectedItems(0).Index <> int_currplayindex Then
                    ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
                End If
            Catch ex As Exception
            End Try
        End If
        Try
            int_currplayindex = ListView1.SelectedItems(0).Index
            ListView1.Items.Item(int_currplayindex).EnsureVisible()
            If int_currplayindex < 0 Then Exit Try
            str_filepath = CStr(ListView2.Items.Item(int_currplayindex).Text) 'getting file path
            objAudio = New Audio(str_filepath, False)  'method to load music
            b_loadmusic = True
        Catch ex As Exception
            b_loadmusic = False
        End Try
    End Sub


    Private Sub ListView1_DoubleClick(ByVal sender As Object, _
                                      ByVal e As System.EventArgs) _
                                      Handles ListView1.DoubleClick


        ListView1.Items.Item(int_currplayindex).BackColor = clr_previous 'previous color
        int_currplayindex = ListView1.SelectedItems(0).Index
        ListView1.Items.Item(int_currplayindex).EnsureVisible()
        str_filepath = CStr(ListView2.Items.Item(int_currplayindex).Text)
        If b_loadmusic = True Then
            If b_musicplaying = True Then
                Timer1.Stop()
                objAudio.Stop()
                b_musicEnding = True
                Button1.Text = "Play"
            End If
        End If
        Try
            objAudio = New Audio(str_filepath, False)
            b_loadmusic = True
            b_musicplaying = True
            Timer1.Start()
            objAudio.Play()
            Button1.Text = "Pause"
        Catch ex As Exception
            b_loadmusic = False
            b_musicplaying = False
        End Try
    End Sub
#End Region


There will be part III for the final part of coding.                                                                         Please feel free to ask any questions if you don't understand this method or any coding here.    


(PS: Sorry for my noob code block. I don't really know html much although my website is fully customized in html and CSS only.)



Saturday, January 29, 2011

My first step-by-step tutorial on Simple Music Player (VS2008) Part I

     After I posted more than 10 tutorials, I found out that it might not be useful to those beginner. So this is my first step-by-step tutorial. I hope that it will be useful to everyone. This tutorial might not be completed in only one post but at least two posts. For now, I haven’t decide about the exact number of posts I going to use.

    Tutorial start here:

    Requirements : 1) Visual Studio 2008 (VS2008) or Visual Basic 2008 Express Edition (VB2008).

                               2) Newest Direct X recommended.  Download from here.

    First, start either VS2008 or VB2008. A start page will appear. Click on create project from start page or go to File | New Project. For VS2008, choose Visual Basic | Windows | Windows Form Application while for VB2008, just simply choose Windows Form Application. Choose a name for your application and click OK. In this tutorial, I will be using Simple Music Player.

(Remarks: I am using VS2008)

1

Picture for New Project Dialog

 

2

After click on OK button, this should be the screen that appear

    After that, drag a button from toolbox to the form. If you can’t find toolbox, go to View | Toolbox. Toolbox will appear on the left. Follow the following picture and place four buttons to the same position. To change the button text to the same in the picture, go to the properties. Properties should be on the right but if it is not, go to View | Properties. To change button text, click on the button and look for text in the properties (The red square area on the right). Change the four buttons text to “Play”, “Stop”, “Previous”, “Next”. (ps: sorry for the wrong arrangement in the picture.)

3

Properties:

Button1 - text:Play    - anchor:bottom,left
Button2 - text:Stop    - anchor:bottom,left
Button3 - text:Next    - anchor:bottom,left
Button4 - text:Previous    - anchor:bottom,left

Anchor is use to lock the position and size of any object that being drag into the form.

(Tip: In order to get the same size of button, drag only one button to the form. Copy the button and paste it to the form for the rest buttons.)

     Add two listviews to the form from the toolbox. Listview1 is use to show the music name while listview2 is use to store the music file path. Listview2 will be invisible by setting the properties of visible to false. Resize listview1 to any size that you like.

7

Properties:

listview1 - allowdrop:true         - anchor:top,bottom,left,right      - view:list      - multiselect:false
listview2 - visible:false

     Add a timer into the form. Timer will be appear under the form. Change the Interval to 1. Interval is the time for timer event to elapsed. This is calculated by milliseconds. In this project, timer is use to check for ending of song and also starting the next song.

13

 

      Here, you will need to have DirectX SDK in order to proceed. There are few methods to play Music with VB.net. In this tutorial, I will guide using DirectX method. In order to use DirectX, you will need to add reference to the project. Go to Project | Add Reference and the following dialog will appear. Look for Microsoft.DirectX.AudioVideoPlayback and click ok.

5

 

This will be the first part of the tutorial. This part includes only interfaces but not coding. The next part will be coding. I not sure how long do I need to complete it but I will try my best to complete it asap. Please comment for any problems.

Monday, January 10, 2011

Music Player in vb.net

     As from the title, I had created a music player with playlist, random shuffle, songs repeat and drag drop functions. I had include a video showing how to use the music player.

My Music Player Video

For those who want to download the music player, please visit my website.

Friday, January 7, 2011

My first C sharp (C#) 2010 program - Paper Scissors Stone game

     As someone as me to make my previous program, Paper Scissors Stone game in C#, I tried and now it is working. This is actually my first program with C#. I though everything will be the same as VB.net but now I found out that there are difference keywords from VB.net.

     Well, I work it out using visual basic 2010. It looks exactly the same as from my previous VB 2008 but this time, I change the reset all button to reset directly instead of doing clear status and clear score separately. And for those who want to have the coding, as usual, I will upload it to my website. Just leave your comment for any problems.

image

Monday, January 3, 2011

A new start

       2011 had came and 2010 had passed.  It will be a new start for everyone to continue with their dreams and plans. Dreams and plans might not go through as expected but if without any effort, we won’t know. To achieve our dreams and plans, we should put all our effort on it and even though we might not able to achieve it, never mind. We can try it again and again until we meet our target or we can come out with another better plans.

       Today, I would like to wish everyone happy new year. I hope that everyone had a good start and also unforgettable countdown last few days ago. In this year, I hope that I could start with a new tutorial in programming of Android. I am still trying to learn but hopefully, I could master it in next month. I will be happy if someone could also guide me in Android.