Learning VB .net by my own and post what i tried and got success with VB .net.

Friday, May 1, 2015

VB .net to browse folders and files

Last night I started to learn to use VB .Net, with a purpose to create an application that will rename files in a folder. That application will rename only files in the folder but not in sub folders.

My first impression regarding its language, it might have around 30% language (code) that similar to VB6/VBA so i might need to pay more energy and time to learn more before I can build any application, even it is a very small application.

However VB .net has some automate function/declaration, for example when i create a form it is automatic declare the form that i can call it to use later. I am sorry, it might normal for you but it seem strange for me and i feel some comfort about it.

Now let go back to my application that i am learning to build (application that rename files in folder), i start VB .net by choosing VB6 as i familiar with it before, and i choose a project to create a desktop application.

It is automatic create a form for me then i created a button that i expect to click to browse for folders and file. At my first try i want to explore the and select the folder. So i used following code:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using OpenDailog As New FolderBrowserDialog
            With OpenDailog

                If OpenDailog.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    MsgBox(.SelectedPath & " were selected")
                End If
            End With

        End Using
    End Sub 

When i right click on button that i just created and choose view code it automatic create a sub button click as you can see in above code. Then below code is function to show folders/files browser that allow me to select files or folders.
        Using OpenDailog As New FolderBrowserDialog
            With OpenDailog
                If OpenDailog.ShowDialog() = Windows.Forms.DialogResult.OK Then
                End If
            End With
        End Using

Then because i just want the system to show me which folder i select i use below code:
MsgBox(.SelectedPath & " were selected")
Mean that when i select a folder and i click "OK" then the system will show a message of folder and it path i selected. At last i can have a desktop application that will work to show me a selected folders. My next post will show a code that will have the application to read all files that exist in the top folder. It seem a long path for me to go....

0 comments:

Post a Comment

Recent Posts

Popular Posts

Powered by Blogger.