Tuesday, May 5, 2009

Reading ini File using VB.NET

Following fucntion reads INI file by Section and Keys and get the value of the Section. Following function uses GetPrivateProfileStringW API function to read the INI file

Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Int32, _
    ByVal lpFileName As String) As Int32

Public Overloads Sub ReadINIFile(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String(), _
ByRef KeyValue As String())
    Dim Length As Integer
    Dim strData As String
    strData = Space$(1024)
    For i As Integer = 1 To KeyName.Length - 1
        If KeyName(i) <> "" Then
            'This will read the ini file using Section Name and Key
            Length = GetPrivateProfileString(SectionName, KeyName(i), KeyValue(i), _
            strData, strData.Length, LTrim(RTrim((INIPath))))
            If Length > 0 Then
                KeyValue(i) = strData.Substring(0, Length)
            Else
                KeyValue(i) = ""
            End If
        End If
    Next
End Sub


Testing above function
Create a Sample INI file using below text in C:\Logs\test.ini
[Sample Section 1]
SampleKey1=SAMPLEVALUE1
SampleKey2=SAMPLEVALUE2
[Sample Section 2]
SampleKey3=SAMPLEVALUE3
SampleKey4=SAMPLEVALUE4

And use following code
Dim KeyName(2) As String
Dim KeyValues(2) As String
KeyName(1) = "ServerName"
KeyName(2) = "DBName"
ReadINIFile("C:\Logs\test.ini", "TEST Server", KeyName, KeyValues)
MessageBox.Show(KeyValues(1) & " " & KeyValues(2))

Hope this helps

Monday, May 4, 2009

Validate All TextBoxes Using JavaScript

Using following function you can find out all text boxes in the page are entered a value or not, no need to manually write each text box name to validate.

<script language="javascript" type="text/javascript">
function validate() {
    // Get all input controls
    var arrTextBox = document.getElementsByTagName("input");
    var retValue = 1;
    // Loop through all controls
    for(i=0;i<arrTextBox.length;i++)
    {
        // Check whether control is textbox and has a value
        if (arrTextBox[i].type == "text" && arrTextBox[i].value == "") {
            retValue = 0;
        }
    }
    //based on the validation return the value
    if (retValue == 0) {
        alert("Validation Failed");
        return false;
    }
    else {
        alert("Validation Success");
        return true;
    }
}
<script>


Tags : Validate JavaScript, All TextBoxes, document.getElementByTagName

Saturday, May 2, 2009

Microsoft Tech-Ed 2009 At Hyderabad

 

Microsoft’s Tech-Ed is going to happen in Hyderabad this year, you can here latest technology news from Microsoft speakers who are actually involved in developing that particular technology.

Tech-Ed is one place where you can make yourself ready for next generation technology, today's economic scenario you need to be ahead of others so this Tech-Ed will help you to stay ahead of others.

You can know about the event at  Tech-Ed 2009

You can see what is the agenda at Day 1 Day 2 Day 3

You can register for the event at Register

Tags: Tech-Ed 2009, ASP.NET

Tuesday, April 28, 2009

Most Valuable Member : DotnetSpider.com

Today I have received The Most Valuable Member award from the DotnetSpider team, I am active on Dotnetspider.com forum from last 4 years.

Recently they introduced the MVM award for the best and quality contributors, I am very happy to receive this.

You can find the post at DotnetSpider MVMs and my profile in dotnetspider at My Profile

I am also happy for other members who got this award as this is prestigious to us.

Congratulations to all the Winners.

I would like to take this opportunity to thank each and every member in the forum.

Also I would like to thank editors, Raghav and Tony for your support towards me all the time.

Cheers,

Satish.

Thursday, April 23, 2009

Creating Dynamic Controls, and Preserve them for alternate Page Loads : ASP.NET

Normally when you create a control dynamically means at runtime, on the next page load you will loose that control, that control will be no longer exists, in this example I am try to explain how we can store that controls and get them back.

Create a Web Application and Add one button to it.
In the page load add following code, in the following code I am creating a object of Control Collection and keeping it in the Session.

image

Now Doble click on button1 and add following code in Button1_Click event.
Here in this code I am storing all the controls created into control collection and saving into session.

image

now we are ready with code just build, run and test.

Tags: Creating Dynamic controls, ASP.NET, C#, Preserve the Dynamic controls

Monday, April 20, 2009

Saving, Retrieving Data in Smart Device Applications

In this example I am try to use SQL Compact Edition with Smart Device Applications.

We can store data and update the data in the device using SQL CE, so lets start building a example.

Create SmartDeviceProject and add 2 Forms to it, please design the Form1 & Form2 as displayed in the Screen shot.




Now lets create a SQL CE database file, for that please right click on the project add new file and select Database file and name it as Employees.sdf



After adding the database file, create a table with following fields.
ID int
Name nVarchar
City nVarchar
Designation nVarchar



Now we are ready with design part lets write some code to insert data into table.

Now double click on the Add button and add following code, in the following code we are creating SQLCeConncetion object and SQLCeCommand Object to insert the data into the .sdf file, it is almost similar how we insert data into normal SQL Server database, normally our database file will be saved on the device where the application is installed so I have taken the path of the .sdf and creating a connection.

Double click on the View button and create a object for Form2 where will show all the employees details.




Now open the Form2 and add grid and one button as shown in the screen shot above, in Form2_Load event write the code to fill the datagrid, double click on back button and write a code to go back to Form1



Now we are ready with our code let built, run and Test

Saturday, April 11, 2009

Implementing Tabs using MultiView Control : ASP.NET

Using MultiView control in ASP.NET we can achieve tabs in a web page, now in this example I am going to explain how we can create tabs using MulitView control

Create a web application and add a Table control with 1 row and 3 columns and a MultiView control with 3 views, you can refer below screen shot

Here we are adding 3 cells using table control and each cell will have a link button which acts as Tab

image

We need to set ActiveViewIndex property of a MultiView control to see particular tab for that initially in Page_Load we set ActiveViewIndex to 0 and on clicking every link we will call TabChange event to show the particular tab, in the below code we identify which link button is clicked and based that we will change the ActiveViewIndex to show the contents

image

Now we are ready with out code, just build, run and test

Hope this helps

Tags : Tab control in ASP.NET, MulitView control, Satish Kumar J