Showing posts with label vb. Show all posts
Showing posts with label vb. Show all posts
Monday, 6 June 2016
Opening, Closing, and Hiding Forms with Visual Basic .NET
Opening,Showing, Closing, and Hiding Forms with Visual Basic .NET
NOTE-Before you can open (or close) a form, you need to know the specific name of the form you want to open or close. The Solution Explorer window lists the names of all the forms that make up your Visual Basic .NET program, such as a form named frmMain.vb.
Opening a form:
After you know the name of the form that you want to display, you need to use BASIC command to open the form, such as the following:
Dim oForm As FormName
oForm = New FormName()
oForm.Show()
oForm = Nothing
oForm = New FormName()
oForm.Show()
oForm = Nothing
Hiding a form
If you want to temporarily make a form disappear, you can use the magic Hide command, such as:
FormName.Hide()
Showing a form
After you've hidden a form, you'll eventually want to make it visible again by using the Show command, such as:
FormName.Show()
Closing a form
Hiding a form just tucks it out of sight, but the form is still loaded in the computer's memory. To clear a form out of memory, you need to use the Close command, such as:
FormName.Close()
How to: Add Windows Forms to a Project(Inserting a Form into a Project)
Inserting a Form into a Project
To insert a form into your project
- From Class View, select the project to which you want to add the form, and click the right mouse button.
- From the shortcut menu, click Add and then click Add Class.If the New Form command is not available, your project may be based on the Active Template Library (ATL). To add a form to an ATL project, you must specify certain settings when first creating the project.
- From the MFC folder, click MFC Class.
- Using the MFC Class Wizard, make the new class derive from CFormView.
Visual C++ adds the form to your application, opening it inside the Dialog editor so that you can begin adding controls and working on its overall design.
Sources: https://msdn.microsoft.com/en-us/library/fhxbke21.aspx
Sunday, 5 June 2016
How to: Delete records from SQL table in VB.Net
How to: Delete records from SQL table in VB.Net
Code to delete a record from SQL table using VB.Net is as follows:
Note-
1: Double Click the delete button and copy the following code
2:And also change the server in connection string and the database also
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Try
con.ConnectionString = "Server=.\SQLEXPRESS;Database=Employee Details;Trusted_Connection=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "Delete From emp_det where emp_id like @emp_id"
cmd.Parameters.Add(New SqlParameter("@emp_id", TextBox1.Text))
cmd.ExecuteNonQuery()
If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
MsgBox("Operation Cancelled")
Exit Sub
End If
Catch ex As Exception
MessageBox.Show("Error while deleting record on table..." & ex.Message, "Delete Records")
Finally
con.Close()
End Try
End Sub
Allow Numbers only in a TextBox - Visual Basic .NET
So the code for allowing only numbers in the textbox for employee ID is:
Just copy the code in the box given below:Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then MessageBox.Show("Please enter numbers only") e.Handled = True End IfEnd Sub |
The Result:
Wednesday, 11 May 2016
Stopwatch in VB6
Stopwatch in VB6
This is a stopwatch application in VB6 that uses the Timer control. The user has the option to start, stop and reset the stopwatch.
First create the above design of your program in the form designer and then copy the below code into the code window of the vb.
Code:
Dim smallsec As Integer, sec As Integer, min As Integer
Dim hour As Integer
________________________________________________
Private Sub cmdReset_Click()
cmdStart.Caption = "Start"
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Text1.Text = Format(0, "00")
Text2.Text = Format(0, "00")
Text3.Text = Format(0, "00")
End Sub
________________________________________________
Private Sub cmdStart_Click()
If cmdStart.Caption = "Start" Then
cmdStart.Caption = "Stop"
Else
cmdStart.Caption = "Start"
End If
If cmdStart.Caption = "Stop" Then
Timer3.Enabled = True
Timer2.Enabled = True
Timer1.Enabled = True
Else
Timer3.Enabled = False
Timer2.Enabled = False
Timer1.Enabled = False
End If
End Sub
________________________________________________
Private Sub Timer1_Timer()
If txtMinute.Text < 59 Then
txtMinute.Text = Format(txtMinute.Text + 1, "00")
Else
txtMinute.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer2_Timer()
If txtSecond.Text < 59 Then
txtSecond.Text = Format(txtSecond.Text + 1, "00")
Else
txtSecond.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer3_Timer()
If txtMiniSecond.Text < 99 Then
txtMiniSecond.Text = Format(txtMiniSecond.Text + 1, "00")
Else
txtMiniSecond.Text = Format(0, "00")
End If
End Sub
Dim hour As Integer
________________________________________________
Private Sub cmdReset_Click()
cmdStart.Caption = "Start"
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Text1.Text = Format(0, "00")
Text2.Text = Format(0, "00")
Text3.Text = Format(0, "00")
End Sub
________________________________________________
Private Sub cmdStart_Click()
If cmdStart.Caption = "Start" Then
cmdStart.Caption = "Stop"
Else
cmdStart.Caption = "Start"
End If
If cmdStart.Caption = "Stop" Then
Timer3.Enabled = True
Timer2.Enabled = True
Timer1.Enabled = True
Else
Timer3.Enabled = False
Timer2.Enabled = False
Timer1.Enabled = False
End If
End Sub
________________________________________________
Private Sub Timer1_Timer()
If txtMinute.Text < 59 Then
txtMinute.Text = Format(txtMinute.Text + 1, "00")
Else
txtMinute.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer2_Timer()
If txtSecond.Text < 59 Then
txtSecond.Text = Format(txtSecond.Text + 1, "00")
Else
txtSecond.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer3_Timer()
If txtMiniSecond.Text < 99 Then
txtMiniSecond.Text = Format(txtMiniSecond.Text + 1, "00")
Else
txtMiniSecond.Text = Format(0, "00")
End If
End Sub
Copy-Paste Sample in Visual Basic 6
Copy-Paste Sample in Visual Basic 6
This is a copy paste sample in Visual Basic 6. It shows you how to use the clipboard object in VB6 to perform copy paste operations in your application. This is a very easy sample targeted to the beginners. It shows you the use of the clipboard object very simply and in a straightforward way avoiding the complexities related to this object. Of course, you can make a complex program using the Clipboard object to achieve something of a very high level.
The code for the above program is very simple and two command buttons are used in the program:
1: cmdCopy2: cmdPaste
First create the above design of your program in the form designer and then copy the below code into the code window of the vb.
The code for the above program is very simple and two command buttons are used in the program:
1: cmdCopy2: cmdPaste
First create the above design of your program in the form designer and then copy the below code into the code window of the vb.
Code:
Private Sub cmdCopy_Click()
Clipboard.SetText (txtCopy.Text)
End Sub
Private Sub cmdPaste_Click()
txtPaste.Text = Clipboard.GetText
End Sub
Thank You.
For any other program please comment in the comment box and get any program related to C,C++,VB6 or VB 2010.
Creating Traffic Light Using VB
Creating Traffic Light Using VB
First create the above design of your traffic light in the form designer and then copy the below code into the code window of the vb.
Note:
Fill the circles or ovals made for the traffic lights with the red,yellow and green color before you start coding.
Also, add the three timers from the toolbox.
AS, this is VB 2010 the timers are not visible but if you are using VB 6 the timers will be visible at the side of each light.
So add 3 timers at the side of each coloured circle or oval.
Code:
Private Sub OvalShape2_Click(sender As System.Object, e As System.EventArgs) Handles OvalShape2.Click
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
OvalShape1.Visible = True
OvalShape2.Visible = False
OvalShape3.Visible = False
Timer1.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
OvalShape1.Visible = False
OvalShape2.Visible = True
OvalShape3.Visible = False
Timer2.Enabled = False
Timer3.Enabled = True
End Sub
Private Sub Timer3_Tick(sender As System.Object, e As System.EventArgs) Handles Timer3.Tick
OvalShape1.Visible = False
OvalShape2.Visible = False
OvalShape3.Visible = True
Timer3.Enabled = False
Timer1.Enabled = True
End Sub
Friend WithEvents RectangleShape1 As Microsoft.VisualBasic.PowerPacks.RectangleShape
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Button6 As System.Windows.Forms.Button
Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
Timer1.Enabled = True
OvalShape1.Visible = True
OvalShape2.Visible = False
OvalShape3.Visible = False
End Sub
Friend WithEvents Button7 As System.Windows.Forms.Button
Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
OvalShape1.Visible = False
OvalShape2.Visible = False
OvalShape3.Visible = False
End Sub
End Class
Code for VB 6 Users :
Private Sub Form_Load()
Timer1.Enabled = True
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
End Sub
Private Sub Timer1_Timer()
If Shape1.Visible Then
Shape2.Visible = True
Shape1.Visible = False
Shape3.Visible = False
ElseIf Shape2.Visible Then
Shape3.Visible = True
Shape2.Visible = False
Shape1.Visible = False
Else
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
End If
End Sub
Calculator using VB
Calculator using VB
First create the above design of your calculator in the form designer and then copy the below code into the code window of the vb.
Code:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
TextBox3.Text = TextBox1.Text + TextBox2.Text
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
TextBox3.Text = TextBox1.Text - TextBox2.Text
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
TextBox3.Text = TextBox1.Text / TextBox2.Text
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
TextBox3.Text = TextBox1.Text * TextBox2.Text
End Sub
TextBox3.Text = TextBox1.Text + TextBox2.Text
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
TextBox3.Text = TextBox1.Text - TextBox2.Text
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
TextBox3.Text = TextBox1.Text / TextBox2.Text
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
TextBox3.Text = TextBox1.Text * TextBox2.Text
End Sub
Microsoft Virtual Studio
Microsoft Virtual Studio
Its is a rich, integrated development environment for creating stunning applications for Windows, Android, and iOS, as well as modern web applications and cloud services.
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows, as well as web sites, web applications and web services. Visual Studio uses Microsoft software development platforms such as Windows API, Windows Forms, Windows Presentation Foundation, Windows Store and Microsoft Silverlight. It can produce both native code and managed code.
The term virtual studio can refer to any number of technological tools which seek to simulate a physical television and/or movie studio.
Visual Studio does not support any programming language, solution or tool intrinsically; instead, it allows the plugging of functionality coded as a VSPackage. When installed, the functionality is available as a Service. The IDE provides three services: SVsSolution, which provides the ability to enumerate projects and solutions; SVsUIShell, which provides windowing and UI functionality (including tabs, toolbars and tool windows); and SVsShell, which deals with registration of VSPackages. In addition, the IDE is also responsible for coordinating and enabling communication between services.[9] All editors, designers, project types and other tools are implemented as VSPackages. Visual Studio uses COM to access the VSPackages. The Visual Studio SDK also includes the Managed Package Framework (MPF), which is a set of managed wrappers around the COM-interfaces that allow the Packages to be written in any CLI compliant language.[10] However, MPF does not provide all the functionality exposed by the Visual Studio COM interfaces.[11] The services can then be consumed for creation of other packages, which add functionality to the Visual Studio IDE.
Subscribe to:
Posts (Atom)









