Saturday, May 30, 2020

Display Date time in Different DateTime Format in Vb6 or VB.net

Display Date time in Different DateTime Format in Vb6 or VB.net

If you want to display date and time or get system Date Time with various format or specific format then there are various type of method available in VB or VB.Net or C# code. In this post SKOTechLearn explain how to Display Date Time in Different DateTime Format in Vb6 or Vb.Net programming.

Search Files From Folders and Sub-Folders in VB.Net Programming.


First, you have to know that, In programming you can use Date Time Formatting with two way:
  1. Predefined Format method
  2. User-defined Format method

 (1) Predefined Format Method:
Following details and code will describe, how these method will work to show predefined DateTime Format. Let's follow the following Table:

Predefined Format Method Uses
Now VB6.0, VB.Net
Date
Time VB6.0
Format (Now, "Short date") VB6.0, VB.Net
Format (Now, "Long Date")
Format (Now, "General date")
Format (Now, "Short Time")
Format (Now, "Long Time")
Today VB.Net
TimeOfDay
DateTime.Now.ToString() C#, VB.Net
DateTime.Today.ToString()
DateTime.Now.TimeOfDay.ToString()
DateTime.Now.ToShortDateString()
DateTime.Now.ToLongDateString()
DateTime.Now.ToLocalTime().ToString()
DateTime.Now.ToShortTimeString()
DateTime.Now.ToLongTimeString()

So, let's see the examples which can be use to format predefined type in VB6, VB.Net and C# code:

Step by Step to Design Menu and Sub-Menu with Settings in VB6.0. 


VB6.0:
 Private Sub MyButton1_Click()
   MyTxtBox1.Text = Now
   MyTxtBox2.Text = Date
   MyTxtBox3.Text = Time

   MyTxtBox4.Text = Format ( Now,  "Short date" )
   MyTxtBox5.Text = Format ( Now,  "Long Date" )
   MyTxtBox6.Text = Format ( Now,  "General date" )
   MyTxtBox7.Text = Format ( Now,  "Short Time" )
   MyTxtBox8.Text = Format ( Now,  "Long Time" )
 End Sub
After Executing application, you will find that the following output will be Shown:
Pedefined dateTime Format in Vb6.0

VB.Net :
 Sub MyDateBtnClick(sender As Object, As EventArgs)
  MyText1.Text = Now.ToString
  MyText2.Text = Today.ToString
  MyText3.Text = TimeOfDay.ToString
  MyText4.Text = Format ( Now, "Short date" )
  MyText5.Text = Format ( Now, "Long Date" )
  MyText6.Text = Format ( Now, "General date" )
  MyText7.Text = Format ( Now, "Short Time" )
  MyText8.Text = Format ( Now, "Long Time" )
 End Sub
This will show the following output:
predefined datetime format in VB.Net code

PreDefined DateTime Format in C#

C# :
void MyDateBtnClick(object sender, EventArgs e)
  {
     MyCTxt1.Text = DateTime.Now.ToString();
     MyCTxt2.Text = DateTime.Today.ToString();
     MyCTxt3.Text = DateTime.Now.TimeOfDay.ToString();
     MyCTxt4.Text = DateTime.Now.ToShortDateString();
     MyCTxt5.Text = DateTime.Now.ToLongDateString();
     MyCTxt6.Text = DateTime.Now.ToLocalTime().ToString(); 
     MyCTxt7.Text = DateTime.Now.ToShortTimeString();
     MyCTxt8.Text = DateTime.Now.ToLongTimeString();
                    
   } 
After compiling this code, you will find the following output, when you click on Button.
Predefined DateTime Format in CSharp

So these are the predefined method in VB6, VB.Net and C#. Now Let's Find Custom method or User-Defined Method for Display Date and Time.

How to Create Login Form with Database Connection in Vb6.0?


 (2)  User-defined Format method :
The following table describe the method of User-defined DateTime Format in VB6.0, VB.Net and C# code.
User Defined Format Method Use
Format ( now, “Your Formatted String” )  
VB6.0, VB.Net
Now.Today.ToString ( “Your Formated String” ) 
VB.Net
DateTime.Now.ToString ( “Your Formated String” )  
C#, VB.Net
DateAndTime.Now.ToString ( “Your Formated String” ) 
VB.Net

Why user defined format method is required? The answer is, in some case or sometime we required specific date time output on their application. So, the user defined format method is used.

SQL Server Connection String with Example and SQL Query Process in VB.Net.


Now, follow the following method for User Defined format process.

VB6.0 :
Private Sub UsrDtBtn_Click()
  UsrTxtBox1.Text = Format ( Now,  "dd" )
  UsrTxtBox2.Text = Format ( Now,  "dddd" )
  UsrTxtBox3.Text = Format ( Now,  "MM" )
  UsrTxtBox4.Text = Format ( Now, "MMMM" )
  UsrTxtBox5.Text = Format ( Now,  "yyyy" )
  UsrTxtBox6.Text = Format ( Now,  "dd/MM/yyyy" )
  UsrTxtBox7.Text = Format ( Now,  "dd-MM-yyyy" )
  UsrTxtBox8.Text = Format ( Now,  "MM/dd/yyyy hh:mm:ss AMPM" )
  UsrTxtBox9.Text = Format ( Now,  "hh:mm:ss AMPM" )
  UsrTxtBox10.Text = Format ( Now,  "hh:mm:ss" )
 End Sub
When you run VB Form, The following image output will be show.
User-Defined DateTime Format in VB6.0

VB.Net :
Sub UsrDTBtnClick(sender As Object, e As EventArgs)
    UsrTxt1.Text = Now.ToString ( "dd/MM/yyyy" )
    UsrTxt2.Text = Now.ToString ( "MM/dd/yyyy hh:mm:ss tt" )
    UsrTxt3.Text = DateAndTime.Now.ToString ( "dddd" )
    UsrTxt4.Text = DateAndTime.Now.ToString ( "MMMM" )
    UsrTxt5.Text = DateTime.Now.ToString ( "hh:mm:ss tt" )
    UsrTxt6.Text = DateTime.Now.ToString ( "dddd; dd-MMMM-yyyy" )
    UsrTxt7.Text = Format ( Now,  "dd-MM-yyyy" )
    UsrTxt8.Text = Format ( Now,  "MMMM, yyyy" )
        
 End Sub
Ok, Let's see the output:
User-Defined DateTime Format in VB.Net

C# :
void UserDtBtnClick(object sender, EventArgs e)
        {
            DateTime UsrDt;
            UsrDt = DateTime.Now;
            MyText1.Text = UsrDt.ToString ( "dd/MM/yyyy" );
            MyText2.Text = UsrDt.ToString ( "MM/dd/yyyy hh:mm:ss tt" );
            MyText3.Text = UsrDt.ToString ( "dddd" );
            MyText4.Text = UsrDt.ToString ( "MMMM" );
            MyText5.Text = UsrDt.ToString ( "hh:mm:ss tt" );
            MyText6.Text = UsrDt.ToString ( "dddd; dd-MMMM-yyyy" );
            MyText7.Text = UsrDt.ToString ( "MMMM, dd-yyyy" );
            MyText8.Text = UsrDt.ToString ( "dd-MMMM-yy" );
                    
        } 
After that we get following output:
User-Defined DateTime Format in CSharp

Now, these are the process to use to Display Date Time in Different DateTime Format in VB6.0 or VB.Net and C# with SKOTechLearn Tips.

Styling ProgressBar with Color Change and Settings in Vb6.0 or VB.Net.

Thursday, May 14, 2020

SQL Server Connection String with SQL Query in VB.Net

SQL Server Connection String with SQL Query in VB.Net

In VB.Net, if you want to Connect MS SQL Server Database , you have to Import some SQL Connection Class to your application. Now, we proceed with step by step process for MS SQL Server Connection String in VB.Net and the Example of SQL Query in VB.Net.

In this post SKOTechLearn describe the connection of database with SQL Server in two ways in VB.Net.
  1. SqlConnection
  2. OleDbConnection

 1. SqlConnection :
If you connect Database through SqlConnection connection string in VB.Net, you have to import some Namespace.
Assembly Reference Namespace Details
System.Data.SqlClient.dll
System.Data.SqlClient
Connection String and SQL Server Data Provider.
System.Data.dll
System.Data
Provide ADO.Net classes’ access

In Vb.Net, You have to first Import this Namespace:

VB.Net :
 Imports System.Data.SqlClient
 Imports System.Data

C# :
 using System.Data.SqlClient;
 using System.Data;

There are following Syntax of SqlConnection:

VB.Net :
Dim myCnn As SqlConnection
 myCnn  = new SqlConnection ("Data Source = MySQLServer_Name; Initial Catalog = MYDatabase_Name; User ID = My_USERID; Password = My_Password;")

C# :
 SqlConnection MyCnn ;
 MyCnn  = new SqlConnection ("Data Source = MySQLServer_Name; Initial Catalog = MYDatabase_Name; User ID = My_USERID; Password = MySQL_Password;"); 


When you import above given class then write following SqlConnection Connection String example:
VB.Net :
  Dim mySqlConn As SqlConnection
  mySqlConn = New SqlConnection("Data Source = XXX.XXX.XXX.XX; Initial Catalog = MY_ABCD_DB; User ID = sa; Password = XXXXXXXXXXX;")

 try
    mySqlConn.Open()
    MessageBox.Show ( "My Database Connection Successfully Connected" )
    mySqlConn.Close()
 Catch errex As Exception
     MessageBox.Show( "My Database Connection Problem" )
 End Try   


C# :
 SqlConnection mySqlConn;
 mySqlConn = new SqlConnection( "Data Source = XXX.XXX.XXX.XX; Initial Catalog = MY_ABCD_DB; User ID = sa; Password = XXXXXXXXXXXX;");  
            try
            {
                mySqlConn.Open();
                MessageBox.Show ("My Database Connected Successfully.");
                mySqlConn.Close();
            }
            catch (Exception errex)
            {
                MessageBox.Show("My Database Connection Error.");
            } 

ConnectionString Code in VB.Net and C#

 Execute or write Query or SQL Statement in VB.Net through SqlConnection:

Now, Let’s write code to execute query or SQL statement and read data from it.

How to Retrieve Data or Read Data From SQL Server in VB.Net?


VB.Net :
  Dim myDBCnn As SqlConnection
  'SqlCommand is used for write Query Statement
  Dim myDBCmd As SqlCommand
  'SqlDataReader is used for Read data from database
  Dim myDBReader As SqlDataReader

  myDBCnn  = New SqlConnection("Data Source = XXX.XXX.XXX.XX; Initial Catalog = MYDBName; User ID = MYDBUSERID; Password=MYDBPassword;")
  myDBCnn .Open()

  Dim MystrQ As String
  MystrQ  = ""
  'Write Query String
  MystrQ  = "Select * From MyDBTableName;"
  'SQLCommand Syntax: SQLCommand(Query, Connection)
  myDBCmd  = New SqlCommand( MystrQ , myDBCnn )
  myDBReader  = myDBCmd .ExecuteReader
  'Start Loop to read data one by one from Table
      Do  While myDBReader.Read()
          Debug.WriteLine(myDBReader("MyField ").ToString())
      loop
  myDBReader.Close()
  myDBCmd.Dispose()
  myDBCnn.Close()
  MessageBox.Show("Data Reading Process Done.")
  

C# :
SqlConnection mySqlCnn;
  'SqlCommand is used for write Query Statement
  SqlCommand myDBcmd;
  'SqlDataReader is used for Read data from database
  SqlDataReader myDBreader;
  mySqlCnn = new SqlConnection("Data Source = XXX.XXX.XXX.XX; Initial Catalog = MYDBName; User ID = MYDBUSERID; Password = MYDBPassword;");  
            try
            {
                mySqlCnn.Open();
               'SqlCommand Syntax: SqlCommand(Query, Conection)
                myDBcmd = new SqlCommand( "Select * From MyDBTableName;", mySqlCnn );
                'ExecuteReader is used to read data from table
                myDBreader = myDBcmd.ExecuteReader();
               'Start Loop to read data one by one from Table
                while ( myDBreader.Read() ) {
                    Console.WriteLine( myDBreader["MyField"] );
                }
                myDBreader.Close();
                myDBcmd.Dispose();
                mySqlCnn.Close();
                MessageBox.Show( "Query Execution Done" );
            }
            catch (Exception errex)
            {
                MessageBox.Show( "Connection or Query Error " );
            }    
  

 2OleDbConnection :
Now, we proceed with second process to connect MS SQL Server in VB.Net through OleDbConnection.
If you connect through OleDbConnection Connection String in Vb.Net, you have to import some Namespace.
Assembly Reference Namespace Details
System.Data.OleDb.dll
System.Data.OleDb
Provide ConnectionString through data source connection.

First, You will have to import following class:

VB.Net :
 Imports System.Data.OleDb


C# :
 using System.Data.OleDb;


OleDbConnection Connection String Example:

VB.Net :
Dim myOleConn As OleDbConnection
   myOleConn = New OleDbConnection("Provider = SQLOLEDB; Data Source = XXX.XXX.XXX.XX; Database = MyOleDataBase ; Uid = MyUserID; Pwd  style="background-color: #fcfbfb;"= MyServerPassword;")
   try
     myOleConn.Open()
     MessageBox.Show ( "Server Connected Successfully." )
     myOleConn.Close()
   Catch errex As Exception
     MessageBox.Show( "Server Connection Error." )
   End Try


C# :
  OleDbConnection MyOleConn;
  MyOleConn = new OleDbConnection("Provider = SQLOLEDB; Data Source= XXX.XXX.XXX.XX; Database= MyOleDataBase; Uid= MyUserID; Pwd= MyServerPassword;");
             try
            {
                 MyOleConn.Open();
                 MessageBox.Show( "OleConnection Successfully." );
                 MyOleConn.Close();
             }
             catch (Exception olex)
            {
                MessageBox.Show( "OleConnection Error." );
            }

OleDB ConnectionString Code in VB.Net and C#

Note: In OleDbConnection String, you have to add Provider for data source.

Now Let’s come to the Query Example of OleDbConnection.

 SQL Server Execute Query or Write Query through OleDbConnection :

So, there are following way to write query for read data form SQL Server through OleDbConnection.

How to use Select Query in SQL with VB.Net ?

VB.Net :
  Dim myOleConn As OleDbConnection
  'ConnectionString Setting
  myOleConn = New OleDbConnection ( "Provider=SQLOLEDB; Data Source=XXX.XXX.XXX.XX; Database= MyOleDataBase; Uid= MyUserID; Pwd= MyServerPassword;" )  
  Try
      'OleDbCommand for Query
       Dim MyOlecmd As New OleDbCommand( "Select * From MyDBTableName;" )
        MyOlecmd.Connection = myOleConn
        myOleConn.Open()
        'OleDbDataReader to read data from Table
        Dim MyOleReader As OleDbDataReader = MyOlecmd.ExecuteReader()
        'Start Loop until Read data according to Query.
        While MyOleReader.Read()
            'If you want to show Particular field then write code like given bellow.
            Console.Write( MyOleReader("MyField ").ToString() )
        End While
     MessageBox.Show ( "OleDbServer Connected Successfully." )
     'fter that close all connection including OleReader.
     MyOleReader.Close()
     MyOlecmd.Dispose()
     myOleConn.Close()
   Catch oleex As Exception
     MessageBox.Show( "OleDbServer Connection Error." )
   End Try    


C# :
OleDbConnection MyOleConn ;
 OleDbCommand MyOlecmd ;
 OleDbDataReader MyOlereader ;

 MyOleConn = new OleDbConnection( "Provider= SQLOLEDB; Data Source= XXX.XXX.XXX.XX; Database= MyOleDataBase; Uid= MyUserID; Pwd= MyServerPassword;" );
 try
    {
       MyOleConn.Open();
       MyOlecmd = new OleDbCommand( "Select * From MyDBTableName;" , MyOleConn);
       MyOlereader = MyOlecmd.ExecuteReader();
       while ( MyOlereader.Read() )
       {
            Console.WriteLine(MyOlereader["MyField"]);
       }
       MessageBox.Show( "Record Show Successfully." );
       MyOlereader.Close();
       MyOlecmd.Dispose();
       MyOleConn.Close();
    }
    catch (Exception Oleex)
       {
           MessageBox.Show( "Problem in Database Connection. " );
        }

So, SKOTechLearn Described the easiest way where you can use SqlConnection or OleDbConnection class for MS SQL Server Connection String with SQL Query in VB.Net (VB and C# Code).

Saturday, May 9, 2020

If Else Statement in Python with Use of Operators in Python

If Else Statement in Python with Use of Operators in Python

When you write code or programming in any language then, mostly you have to use If Else statement with condition. So, Here SKOTechLearn describes the easy learning way about IF Else Statement in Python.

Basically, If Else statement work on true and false condition.

But, before we start , we understand, how this statement works in python by given following flow chart.

Suppose, If we ask our friend with a cup of Tea, then how will this condition apply?

IF Else statement Flow Chart in Python
If ( <condition> ) :
    <Statement>
else:
    <Statement>

Now, IF Else statement require different types of Operators.

Basically, in condition require “Comparison Operators” and “Logical Operators”.
Comparison Operators in Python :
Name
Details
==
Comparing Equal condition
!=
Comparing Not Equal
>
Comparing Value is Greater Than
<
Comparing Value is Less Than
>=
Comparing Value is Greater or Equal to
<=
Comparing Value is Less or Equal to
<>
Comparing Not Equal

Logical Operators in Python :
Name
Details
and
Statement with Two and more condition, and if all condition are true
or
Statement with Two or more condition, and if any one condition are true
not
Reverse condition if true then false and if false then true

How to Use Operators in Python?


Example of If Else Statement with Comparison Operators in Python:
MyFstVl1 = 135
MySecVl2 = 234

#Condition1
if ( MyFstVl1 == MySecVl2 ):
   print "Condition1 : MyFstVl1 is Equal to MySecVl2"
else:
   print "Condition1 : MyFstVl1 is Not Equal to MySecVl2"


#Condition2
if ( MyFstVl1 != MySecVl2 ):
   print "Condition2 : MyFstVl1 is Not Equal to MySecVl2"
else:
   print "Condition2 : MyFstVl1 is Equal to MySecVl2"


#Condition3
if ( MyFstVl1 <> MySecVl2 ):
   print "Condition3 : MyFstVl1 is Not Equal to MySecVl2"
else:
   print "Condition3 : MyFstVl1 is Equal to MySecVl2"


#Condition4
if ( MyFstVl1 < MySecVl2 ):
   print "Condition4 : MyFstVl1 is Less than MySecVl2"
else:
   print "Condition4 : MyFstVl1 is Greater than MySecVl2"


#Condition5
if ( MyFstVl1 > MySecVl2):
   print "Condition5 : MyFstVl1 is Greater than MySecVl2"
else:
   print "Condition5 : MyFstVl1 is Less than MySecVl2"


#Condition6   
if ( MyFstVl1 <= MySecVl2):
   print "Condition6 : MyFstVl1 is Less than or equal to MySecVl2"
else:
   print "Condition6 : MyFstVl1 is Not Less than or Not equal to MySecVl2"


#Condition7
if ( MyFstVl1 >= MySecVl2):
   print "Condition7 : MyFstVl1 is greater or equal to MySecVl2"
else:
   print "Condition7 : MyFstVl1 is Not greater or Not equal to MySecVl2"


When you compile or run this script, the following output will be display:

 Condition1 : MyFstVl1 is Not Equal to MySecVl2
 Condition2 : MyFstVl1 is Not Equal to MySecVl2
 Condition3 : MyFstVl1 is Not Equal to MySecVl2
 Condition4 : MyFstVl1 is Less than MySecVl2
 Condition5 : MyFstVl1 is Less than MySecVl2
 Condition6 : MyFstVl1 is Less than or equal to MySecVl2
 Condition7 : MyFstVl1 is Not greater or Not equal to MySecVl2
IF Else with Comparision Operator in Python
IF Else Statement Example with Comparision Operator

Example of IF Else Statement with Comparison Operators in Python:
MyStr1 = "python"
MyStr2 = "Learn"
MyStr3 = "Programming"

if ( MyStr1 == "python" and MyStr2 =="Learn" ):
   print " 'And' Operator Output : " + MyStr1 + MyStr2
else:
   print " 'And' Operator Output: String Not Match"
   
if ( MyStr1 == "python" or MyStr1 == "PYTHON" ):
   print " 'Or' Operator Output : " + MyStr1
else:
   print " 'Or' Operator Output : String Not Found"
   
if not ( MyStr3 == "python" or MyStr3 == "PYTHON" ):
   print " 'Not' Operator Output : " + MyStr3 + " is not equal to python"
else:
   print " 'Not' Operator Output : " + MyStr3 + " is equal to python"

The following output will be display, when you run this python code:
 'And' Operator Output : pythonLearn
 'Or' Operator Output : python
 'Not' Operator Output : Programming is not equal to python

IF Else Statement with Logical Operator in Python
IF Else Statement Example with Logical Operator in Python
Nested If Else :
When you want to check condition and want to check another condition after previous condition, then we have to use Nested If Else. Let’s check following example:
 sk = 102
 if (sk < 500): 
    sk = sk % 2
    print ( sk )
    if (sk == 0): 
        print ( "sk is even" ) 
    if (sk > 100): 
        print ( "sk Greater than 100" ) 
    else: 
        print ( "sk Less than 100" )

Output:
 0
 sk is even
 sk Less than 100

If Else ladder (if elif else):
There is following example of Ladder:
 Vl = 35
 if ( Vl == 12 ): 
     print ( "Vl equal to 12" ) 
 elif ( Vl == 18 ): 
     print ( "Vl equal to 18" ) 
 elif ( Vl == 35 ): 
     print ( "Vl equal to 35" ) 
 else: 
     print ( "Vl Not equal to any" )

Output:
 Vl equal to 35

So, Here, SKOTechlearn describe the example of If Else Statement in Python with Logical operator and comparison operators in python.

Friday, May 8, 2020

Remove Multiple Checked Items from Listview in VB6.0 Easy Tips

Remove Multiple Checked Items from Listview in VB6.0 Easy Tips

Whenever you create an application in Visual Basic 6.0, and want to implement your application with data or record through list, then you have to require some component or tool like Listview, FlexGrid, MSHFlexGrid etc. In this control you can add, delete or edit items easily. But in this post, we describe the way where you can remove multiple checked items from Listview in VB6.0 easily with SKOTechLearn.

If you want to proceed only one by one or single item’s removal process, then you can check it from easily edit or delete selected listview items in vb6.0.

But, if you want to remove or delete multiple checked items, then you have to follow the steps describe by SKOTechLearn.

Suppose, this control contain some records and there is a problem to remove of some selected checked item. First you have to implement in Properties of this control like bellow.
ListView CheckBoxes Setting in VB6.0
ListView CheckBoxes Setting
You have to enable “CheckBoxes=True” from Properties windows. Then proceed with following way.

Dynamically add data in ListView with simple way. 


Add some records in loop through code:
Private Sub AddItems_Cmd_Click()
MyListVBox1.ListItems.Clear
'Here MyListVBox1 is Listview Control
Dim i As Integer
i = 1
 While Not i = 10
    MyListVBox1.ListItems.Add , , Right("0000" & i, 4)
    MyListVBox1.ListItems(i).ListSubItems.Add , , "A" & i
    MyListVBox1.ListItems(i).ListSubItems.Add , , Right("0000" & i, 4) & "-" & Val(Replace(Format(Now, "hh:mm:ss"), ":", "")) + i
    i = i + 1
    DoEvents
 Wend
End Sub
Add Items in Listview in Vb6.0
Add some records
Now we select some items for deletion.

Note: If you try to remove data from ascending order like from top to bottom, then it will remove wrong items. You have to proceed from Bottom to top means you have to create a loop which start from bottom to top.

So, we write code for deletion from Bottom to Top Loop. For this process, we drag a button and write code inside it, like bellow.
Private Sub RemoveItems_cmd_Click() 
  Dim rm1 As Integer
  rm1 = MyListVBox1.ListItems.Count
  While rm1 > 0
     If MyListVBox1.ListItems(rm1).Checked = True Then
         MyListVBox1.ListItems.Remove (rm1)
     End If
     rm1 = rm1 - 1
     DoEvents
  Wend
  MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation
End Sub
Remove Checked Items From Listview in VB6.0
Remove Checked Items
When you write code inside “RemoveItems_cmd” and run application,  and press this button. The checked record will be deleted like above image.

Get ListView selected row data in TextBox.


If you want to store deleted item or show it on another ListViewBox then, just add this control on application and write the following code for it.
Private Sub RemoveItems_cmd_Click()
 MyListVBox2.ListItems.Clear
 Dim rm1, ls2 As Integer
 ls2 = 1
 rm1 = MyListVBox.ListItems.Count
 While rm1 > 0
    If MyListVBox.ListItems(rm1).Checked = True Then
      'add checked item in another listview control
      MyListVBox2.ListItems.Add , , MyVListBox.ListItems(rm1).Text
      MyListVBox2.ListItems(ls2).ListSubItems.Add , , MyListVBox.ListItems(rm1).SubItems(1)
      MyListVBox2.ListItems(ls2).ListSubItems.Add , , MyListVBox.ListItems(rm1).SubItems(2)

      MyListVBox1.ListItems.Remove (rm1)

      ls2 = ls2 + 1
   End If
   rm1 = rm1 - 1
   DoEvents
 Wend
 MsgBox "Checked Items Deleted Or Removed Successfully.", vbInformation
End Sub
Suppose my second Listview is “MyListVBox2” then we first add checked item after that we remove that particular items like above code and you will see the output will be just like bellow image.
Get Deleted Items in Other ListView in VB6.0
Get Deleted record in Other ListView
You can easily Get checked record in other List Control.

So, This is the way for Removing or Delete Multiple Checked Items From ListView in VB6.0 with SKOTechLearn.

Friday, April 10, 2020

How to jRadioButton Select One Option at a Time in Java Netbeans

How to jRadioButton Select One Option at a Time in Java Netbeans

Whenever you use multiple jRadioButton in java, you have to face problem that it can not work as jRadioButton select one option at a time in java when you click on that particular option.

When you select one option and then jump or select other option, then previous option also selected including current selected option. So, get rid of this problem, you have to try or use following two ways according to SKOTechLearn Tips.
  1. jRadioButton Select One Option at a Time in Java through ‘ItemStateChanged’ events 
  2. Use ButtonGroup for Select One Option at a Time in Java
So, before we start, We have to drag this control , then change its Name and Text according to your self.

 1. jRadioButton select One Option at a time in java through ‘ItemStateChanged’ events:
Suppose we drag 3 jRadioButton with name MyOption1, MyOption2, MyOption3. So, we have to write code inside every RadioButton’s ‘ItemStateChanged’ events.

jRadioButton ‘ItemStateChanged’ events


If MyOption1 is selected then write following code:
 private void MyOption1ItemStateChanged(java.awt.event.ItemEvent evt) { 
        if (MyOption1.isSelected()){
            MyOption2.setSelected(false);
            MyOption3.setSelected(false);
        }
    }

If MyOption2 is selected then write following code:
 private void MyOption2ItemStateChanged(java.awt.event.ItemEvent evt) { 
        if (MyOption2.isSelected()){
            MyOption1.setSelected(false);
            MyOption3.setSelected(false);
        }
    }

If MyOption3 is selected then write following code:
 private void MyOption3ItemStateChanged(java.awt.event.ItemEvent evt) { 
        if (MyOption3.isSelected()){
            MyOption1.setSelected(false);
            MyOption2.setSelected(false);
        }
    }
jRadioButton ItemStateChanged Event in java
ItemStateChanged Event

As you can see that when write this code and run application. And when you select any option, others will be deselected.

 SetSelected(true) : Is Use For Selection
 SetSelected(false) : Is Use For Deselecting

 2. Use ButtonGroup for Select One Option at a Time in Java:
Now, first we talk about ButtonGroup, Basically ButtonGroup class is use for selecting only one RadioButton and deselects remain RadioButton.

So, this can be done by adding all related jRadioButton in ButtonGroup.

Now, drag ButtonGroup on jFrame. Then write following code inside your jFrame class or ‘formWindowOpened’ events.

Import ButtonGroup class


First, you have to Import ButtonGroup class:
  import javax.swing.ButtonGroup;


Add jRadioButton on ButtonGroup Class


If you want initialize in jFrame class then write code like following:
public MyRadioButtonFrame() {
        initComponents();
        ButtonGroup MyOptiongroup = new ButtonGroup();
        MyOptiongroup.add(MyOption1);
        MyOptiongroup.add(MyOption2);
        MyOptiongroup.add(MyOption3); 
    }

Or you can initialize it in jFrame’s ‘formWindowOpened’ events like bellow:
public formWindowOpened(java.awt.event.WindowEvent evt) {
        ButtonGroup MyOptiongroup = new ButtonGroup();
        MyOptiongroup.add(MyOption1);
        MyOptiongroup.add(MyOption2);
        MyOptiongroup.add(MyOption3); 
    }

jRadioButton With Example


If you want to display selected radiobutton text on jLabel then go to following examples.
private void MyOption1ItemStateChanged(java.awt.event.ItemEvent evt) {
        if(MyOption1.isSelected()){
            MyLabel1.setText("MyOption1 is Selected");
        }
    }

private void MyOption2ItemStateChanged(java.awt.event.ItemEvent evt) {
        if(MyOption2.isSelected()){
            MyLabel1.setText("MyOption2 is Selected");
        }
    }

private void MyOption3ItemStateChanged(java.awt.event.ItemEvent evt) {
        if(MyOption3.isSelected()){
            MyLabel1.setText("MyOption3 is Selected");
        }
    }
jRadioButton Option Select Example in Java
RadioButton Option Select Example

These two point will be use as jRadioButton Select one Option at a time in java Netbeans with SKOTechLearn Tips.