Total Pageviews

Showing posts with label My Software. Show all posts
Showing posts with label My Software. Show all posts

Saturday, November 12, 2016

How to make a simple To Do List Software in Visual Basic 2015

To make a simple To Do List in Visual Basic 2015 I will use a listbox and several buttons and one textbox.

1. Start a new Visual Basic 2015 project! This apply for the older .net versions.
Start a new project
Start a new project

2. Create the form and set it up!

Create a new Visual Basic 2015 form

Now let set the properties of the form.
In the form properties change the sizes, width = 500 and height = 500.
Form properties


Change in Properties the title of the form as "Simple To Do List".
Form title

3. StatusStrip Control Setting Up. In the StatusStrip create a label where we will present how many tasks we have to do in the moment.
StatusStrip
We create a lable within the StatusStrip as it's shown on the above picture. Default property name for the created label is ToolStripStatusLabel1. This is not practical to work with so we will change it to lblTasksCount.
ToolStripStatusLabel Control
We have the following view.
ToolStripStatusLabel
You can see that the label text of our ToolStripStatusLabel is ToolStripStatusLabel1. We will delete this text.
ToolStripText Label

4. ToolStrip Control Setting Up.
Let create our first button and our first textbox withing the ToolStrip Control.
ToolStrip Setting Up

Now we will name the button and textbox. 
ToolStripButton1 Name = btnAddTask (coded version)
ToolStripButton1 Name visual version
ToolStripButton1.Text = "Add Task"

The same way we change Text Property to "Add Task"

We will also add an icon to the button property. We do this when we go with the mouse pointer over the button control and perform right click on the mouse and click "Set Image". 
See the photo bellow:
icon

When it comes to downloading icons I always use Iconfinder.com. You can find wonderful premium and free icons there.
ToolStripButton1 Icon inserted

Right from the button is the textbox.
Change the property name from ToolStripTextBox1 to txtAddTask. Use the same way as for ToolStripButton.
Let's change the font and the size of ToolStripTextBox1.
TooStripTextBox Font


Set the font to 16pt.

Change ToolStripTextBox1 size!
ToolStripTextBox1 Size

For our project we will change only Width to 200.

Let's add the other buttons! From designing perspective we will add Separator at first.
ToolStrip Separator

Add the buttons following to look like the image bellow!
Simple To Do List
Simple To Do List
Use the previous explained ways to set the following properties for each of the controls.
- Button2.Name = btnEdit
- Button3.Name = btnRemove
- Button4.Name = btnOpenTaskList
- Button5.Name = btnSaveTaskList

5. Start codding the software!
First change the font of the Task List to 16. Same ways as for the previous controls.

Because in ToolStripTextBox have no Focus (not as the old way), we will write a special code when the form load.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.ActiveControl = txtAddTask.Control
    End Sub


With this code the cursor will be focused in the textbox so we can start writing the task immediately.

    Private Sub btnAddTask_Click(sender As Object, e As EventArgs) Handles btnAddTask.Click
        'Check if txtAddTaskBox is Null or Empty to avoid adding empty task
        If String.IsNullOrEmpty(txtAddTask.Text) Then
            MsgBox("Write your task before adding it to the Task List", vbCritical, "Empty TaskBox")
        Else
            'Add task in the Task List
            ListBox1.Items.Add(txtAddTask.Text.ToString)
            'Clear the task textbox
            txtAddTask.Clear()
            'Focus the task textbox
            txtAddTask.Focus()
            'Count Due Tasks in the Task List
            lblTaskCount.Text = "Due Tasks: " & ListBox1.Items.Count
        End If

    End Sub

You can try to add some tasks now!
Simple Task List in action
Simple Task List in action

Let enter the code in btnEditTask!

    Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
        Dim selecteditemindex As Integer = ListBox1.Items.IndexOf(ListBox1.SelectedItem)
        Dim editaskinput As String
        Dim Item As Object = ListBox1.Items.Item(selecteditemindex)
        Dim index As Integer = ListBox1.Items.IndexOf(Item)
        editaskinput = InputBox("Edit the Task", "Edit selected Task")
        ListBox1.Items.Remove(ListBox1.SelectedItem)
        ListBox1.Items.Insert(index, editaskinput)

    End Sub

    Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
        Dim itemfordeletion
        itemfordeletion = ListBox1.SelectedItem
        ListBox1.Items.Remove(itemfordeletion)

    End Sub

Edit and Remove selected tasks from the List Task is programmed. 

Now we will add the codes for Open Task List and Save Task List.



    btnOpenTaskList.Click
        Dim OpenFileDialog1 As New OpenFileDialog
        OpenFileDialog1.FileName = ""
        OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim lines = File.ReadAllLines(OpenFileDialog1.FileName)
            ListBox1.Items.Clear()
            ListBox1.Items.AddRange(lines)
        End If
    End Sub
    Private Sub btnSaveTaskList_Click(sender As Object, e As EventArgs) Handles btnSaveTaskList.Click
        Dim SaveFileDialog1 As New SaveFileDialog
        SaveFileDialog1.FileName = ""
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim sb As New System.Text.StringBuilder()
            For Each o As Object In ListBox1.Items
                sb.AppendLine(o)
            Next
            System.IO.File.WriteAllText(SaveFileDialog1.FileName, sb.ToString())
        End If

    End Sub

Our "Simple To Do List Software" is finished. In my next post I will add advanced options to the software so we can make it complete To Do List Software.

Some of the source codes I used are taking from one of my previous posts "ListBox Complete Tutorial - Visual Basic 2015".

Friday, September 23, 2016

Create Keyword Density Calculator for SEO in Visual Basic 2015

Visual Basic 2015 Tutorials: Keyword Density Calculator

Visual Basic 2015 is very powerful programming language. You can create almost all type of software using it.
We all know that if you want your website to be high in the search engine searches you need to SEO optimize your content. One of the best and most widely used way for SEO optimization is writing content with proper Keyword density. Proper keyword density should be between 2 and 3%.

Let's create keyword density calculator in Visual Basic 2015.

Keyword density calculator in Visual basic 2015

As you can see on the photo we have several textboxes.

Controls properties:
- .Name = txtKeyword
- .Name = txtWordsNo
- .Name = txtKeywordsNo
- .Name = txtPercent
- .Name = Label5

We have no buttons here because the calculation goes automatically in the time of writing. I added a menu so we can save the written SEO optimized text and open it later.

Visual Basic 2015 Tutorials: Writing the code

First we have to call System.IO

Imports System.IO

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        If txtKeyword.Text <> "" Then
            Static rex As New System.Text.RegularExpressions.Regex("\b", System.Text.RegularExpressions.RegexOptions.Compiled Or System.Text.RegularExpressions.RegexOptions.Multiline)

            txtWordsNo.Text = (rex.Matches(TextBox1.Text).Count / 2).ToString()

            txtKeywordsNo.Text = FindWords(TextBox1.Text, txtKeyword.Text)

            txtPercent.Text = Math.Round(txtKeywordsNo.Text / txtWordsNo.Text * 100, 2)


            If txtPercent.Text > 1.5 And txtPercent.Text <= 3 Then
                Label5.BackColor = Color.Green
            Else
                Label5.BackColor = Color.Red
            End If
        End If
    End Sub

To make the software more useful I added a menu where I can open and save text files from the TextBox control in Visual Basic 2015.

Visual Basic 2015 Tutorials

   Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click


        OpenFileDialog1.CheckFileExists = True
        OpenFileDialog1.CheckPathExists = True
        OpenFileDialog1.DefaultExt = "txt"
        OpenFileDialog1.FileName = ""
        OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        OpenFileDialog1.Multiselect = False

        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            Dim oReader As New System.IO.StreamReader(OpenFileDialog1.FileName)
            TextBox1.Text = oReader.ReadToEnd
        End If
    End Sub

    Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click

        SaveFileDialog1.DefaultExt = "txt"
        SaveFileDialog1.FileName = ""
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        SaveFileDialog1.FilterIndex = 2
        SaveFileDialog1.RestoreDirectory = True

        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            IO.File.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text)
        End If
    End Sub

We finished the code. This code is perfect and it's not making any mistakes. If you want some changes or you want me to send you Visual Studio files or only as an exe file you can freely contact me in the contact form or by commenting. I will answer with pleasure.
My goal is to make this visual basic 2015 tutorials blog more useful as possible.