vijay

welcome Netizen

welcome Netizen
Hi folks this site Share Basic Knowledge in .NET, DotNet, C#,DOT NET CODE, ASP.NET, VB.NET, DOT NET TRICKS,Dotnetcode,Android and Latest Technology Articles in VB,Android and ASP.NET

Saturday, April 16, 2011

How to Read And Write .INI files in vb.net?


Hi..
when i am doing a project i need an requirement to read and write the INI files.then i googled ,But i got only partly result..
lastly i found this solution to read INI files ,then i decide to write articles to read INI files...

First you have to declare a function to read and write INI files..
Private Declare Ansi Function GetPrivateProfileString  Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
        (ByVal lpApplicationName As String, _
        ByVal lpKeyName As String, ByVal lpDefault As String, _
        ByVal lpReturnedString As String, _
        ByVal nSize As Integer, ByVal lpFileName As String) _
        As Integer
    Private Declare Ansi Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
           (ByVal lpApplicationName As String, _
           ByVal lpKeyName As String, ByVal lpString As String, _
           ByVal lpFileName As String) As Integer

Details About Declaration:

Function GetPrivateProfileString:

lpkeyname -->Denotes session of INI file
 lpDefault---->Its return default value
lpReturnedString--->its gets the value from the INI file
nSize---->Declare a size for return string
lpFileName-->Its path of INI file

Function WritePrivateProfileString
lpApplicationName--->Session Name
lpKeyName---->
lpString------>Input text
lpFilename---->Its path of INI file

In form add two buttons one for Read INI files and another one to write.......

In an Button click event enter this code:


    Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Read.Click
textbo1.text=Getinistring("Boys1","students")
End Sub


 Public Function Getinistring(ByVal strKey As String, _
Optional ByVal strSection As String ) As String
        Dim strValue As String
        Dim intPos As Integer
            strValue = Space(1024)
        GetPrivateProfileString(strSection, strKey, "Not-Found", strValue, 1024, "D:\class.ini")
           strValue = Mid(strValue, 1, Len(strValue) - 1)
           strValue = Trim(Left(strValue, Len(Trim(strValue)) - 1))
        
        Getinistring = strValue


    End Function
  Private Sub Write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles  Write.Click
Dim rec as long
rec=WritePrivateProfileString("students", "Boys1", Trim(textbo2.Text), "D:\class.ini")
End Sub

 Sample INI File

i hope this really helpful to you plz post your valuable comments...............

Thursday, April 14, 2011

HOW TO SELECT A FOLDER IN VB.NET?


Hi friends ..
In this article am going to describe about to select a folder in vb.net
In vb.net tools folder browser dialog is available...
Just Drag and drop  folder browser dialog from the tools in your form









Add one button and textbox in your form

Then enter the code in your button click event ...

    Private Sub btntest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntest.Click

  Dim myfolder As New FolderBrowserDialog
        myfolder.Description = "Select The Folder "
        myfolder.RootFolder = Environment.SpecialFolder.MyComputer
        Dim result As DialogResult = myfolder.ShowDialog
        If result = Windows.Forms.DialogResult.OK Then
         t1.text=myfolder.SelectedPath
        End if
        End sub
Your selected folder is stored in the text box

i hope this one helpful to u...&..post your valuable commnets