Category Archives: Microsoft

How to INSTALL DJANGO ON WINDOWS 7?


‘Django’ was one of the popular Python framework, which can be used to create beautiful dynamic website from scratch. Write less and do more that is the frameworks mean to. You don’t need to start from the beginning, Django will take care of that.

How to get my copy of Django?

Well, it is a free framework free of cost, you can download and use Django 1.6.5 or later along with Python 3.3 or prior version on Windows/Linux/Mac or on almost any Computer OS.

Installing Django on Windows 7 and later

Make sure that you have latest Python version installed on your computer. You can download it from Python.org. Extract the Django .Zip/.tar file, using Winzip or 7zip (preferably C:/, root directory).
Setting Python paths on windows will let you run it from any drive, learn how to.
Let’s install the Django, issue the following command using Power Shell or command prompt (Run->PowerShell).

C:/> CD django1.6.5
C:/>django1.6.5> Python setup.py install

And it will run the python script for installation. All file required will be automatically copied to the Python Lib\site-package folder securely. After the process you can safely delete the extracted folder from the C:\ drive.

Installing Django on Linux

On Linux you have prebuilt Python on it, so no need to install it separately. Just extract Django .tar file and run the setup script.
Verifying the Django installation

Run the following on Python prompt

>>> import django
>>> print (django.get_version())

Will result in displaying the current version as (if everything went right)
1.6.5

That’s all

VB6: List all printers using code in Windows


Listing all printers with name, Port in VB6 is simple as listing default printer port using Kernel32 library . Today we going show you how to do this.

As usual we start with function declaration, then define a new function which add all information into a list box. Here we goes

Kernel32 GetProfileString method

Declare Function GetProfileString Lib “kernel32.dll” Alias “GetProfileStringA” (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long

Add printer information into a list box

Public Sub GetPrinterList(lstPrinter As ListBox)Dim PrintData As PrinterDim defprinterpos%

For Each PrintData In Printers

‘ Add printer name and port to list

lstPrinter.AddItem PrintData.DeviceName & ” at: ” & PrintData.Port

‘ Check for default printer

If PrintData.DeviceName = Printer.DeviceName Then defprinterpos = lstPrinter.NewIndex

Next

lstPrinter.ListIndex = defprinterpos%

End Sub

This sub procedure will take list box as argument, and add printer to this list box.

Call the sub

The final line of code just invoke the procedure and see what we have.

Happy coding

Add items to listview using Reader class in C#


Welcome to another code poetry post. Suppose you have a database application and want to display those records from database to a listview, what should you know?. This tutorial will help you.

C# has a neater ways to code with ListView and Database. List View Control work much faster than Grid. Let’s do it with fun.

For this C# project, we need a connection string and method to connect the database, command object which can be used to fetch records from the table. We are already discussed about OLEDB connections (if you are not familiar, attempt a search).

Secondly we need a Reader object which let you move through the records, this method proved to be faster than data views.

How to add items

We are filling listView items with values using following ,
  1. Create List of Strings and gather items
  2. We create ListViewItem object and add those List we are collected to it.
  3. Final step we just fill ListView control with ListViewItem object .

The code

We used a connection method for this project, and called using connect, the rest of the code look like

public void MediceineList(ListView ls, List filter)
        {
            string qstr;
            List lst=new List();

            if (filter[0] == “All”) {
                qstr = “Select * from new_Medicines”;
            }
            else
            {
                qstr = “Select * from new_Medicines where ” + filter[1] + ” =” + filter[0];
            }
            Rs = new OleDbCommand(qstr , conn);

            OleDbDataReader dr = Rs.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            int i = 1;
            while (dr.Read())

            {
                lst.Add(i++.ToString ());
                lst.Add(dr.GetValue(0).ToString());//Pcode
                lst.Add(dr.GetValue(1).ToString ());//PName
                ListViewItem lsvitm = new ListViewItem(lst.ToArray() );
                ls.Items.Add(lsvitm);
                lst.Clear();
            }
            ls.Items.Add(“”);
            ls.Items.Add(“TOTAL: “+ i);
        }
        }

I also used some filtering capabilities. Lets finish the final code and test the application.
 List fltr;

            fltr = new List();
            fltr.Add(“All”);
            db.MediceineList(listView1,fltr);

Treating Keystrokes systematically in C#.Net


Walking around the C#.Net 2015 may be little bit fun. Today I will introduce keystroke and show how it can help to move focus between controls.
Sendkeys Object in .Net frame work help you to fire some key stroke, which will enable functions such as move focus forward and backward with the send() method.

 Lets’ start with building a Key Press event for the following Pcode Textbox.

Making of the Key Press Event

Go to the Property Box – Choose Event – locate Key Press and enter Key Press event name as “EnterKey_Treatment” and hit enter, will bring the method structure code.

Now select all controls with Ctrl + Click and select Key Press Event as  EnterKey_Treatment. You can also do it individually. This would save our time indeed. 

Applying Keystroke

For proper working of the keystroke for moving from one box to another, you have keep the Tab Index of all boxes in as sequential order, i.e, 0,1,2 and so on.Let’s fill this cup with some hot tea.

But the MoveToMox and common static class not yet defined, we need the fuel from the common class.( A static class act like a library, it can be called anywhere in the project). 

Static class for Keystroke (MoveToBox)

A static class can contain only static members, and it can access without creating the object, it act like C# library for our project.
For utilizing the KeyPressEventArgs(accessing the keys the user press), have to reference System.Windows.Forms. The new class would look like,

Create a single method for key Press Event and call the commons. That is all you need to know.

Let’s test the program.

Privately set able and publicly get able property in C#


Properties in C# classes are safer way to access and manipulate data. With Set and Get function user can configure the functionality. How about a privately Get able property, which can be accessible only through the class itself and publicly setable property.

This can be done by putting private keyword before the set property.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Data
    {
        private String Narration;

        public Data()
        {
            this.Narration = “Expese”;
         
        }
        public string narration
        {
         
            get
            {
                return  Narration;
            }
            private set
            {
                Narration=value;
            }
        }
        public void SetData()
        {
            this.narration = “Other expense”;
        }

    }
}

Let’s configure the console application. Create the object call the properties and methods.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Data d = new Data();
            Console.WriteLine(d.narration);
         
            d.SetData();
            Console.WriteLine(d.narration);
 Console.ReadKey();
        }
    }
}

The SetData() is call the privately get able property, which can be on;y accessible within the class itself.

The public property can access the data because it is public property and by default all set and get are public.

Download Source

Mount disk image in Windows 10 without third party tool or disc


Most of the installation software come with ISO disk image which you need to burn into a disc (CD/DVD) or USB ,then use the disk to install them using the media.
But Windows 10 has a different option to do the installation directly from the Disk Image using the Disk Image Tool.

When user right the click the Disk Image (Disk Image Tool), Microsoft Windows let user choose the Mount command and will bring the setup directory. So you can easily run the setup and install the software without a media or burning software.

Thank you  Microsoft

Accessing Form control values in C#.Net


C#.net programs are completely build upon class hierarchy, unlike VB.Net it is a full fledged OOP language.

The first problem newbie faced  in C#.Net while migrating from VB.Net was the global accessing of controls in other classes. In C# every Windows Form is a partial class derived from Form. This problem can be solved by creating properties with Get and Set method.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PharmaERP
{
    public partial class Product_Registration : Form
    {
        public Product_Registration()
        {
            InitializeComponent();
        }
        public string  _txtPcode
        {
            get
            {
                return txt_Pcode.Text;
            }
                
            set
            {
                txt_Pcode.Text  = value;
            } 
        }

Once you are created the object you can Set or Get values from the control as follows.
Declare the form Object in general section of a Form class,where you would like to access the controls.

public Product_Registration frm_PR = new Product_Registration(); frm_PR._txtPcode=”S706″;

will set the Text Box with “S706” string using the Set method You can also get the string from control using the Get as,

Messagebox.show(frm_PR._txtPcode)
or
 Messagebox.show(this._txtPcode) — from the Form itself

<<<That is all I have today…. please leave comments on Disqus>>>

Check for folder/Drive/File in VB 6


In visual Basic 6.0 you can check the existence of file and folder by utilizing the File System Object. Lets take a look at the sub routine  which check the existence of folder in your system.

Is Dir/Folder Exist

‘Returns a Boolean – True if the file exists

Public Function DirExist(OrigFile As String)
Dim fs
Set fs = CreateObject(“Scripting.FileSystemObject”)
DirExists = fs.folderexists(OrigFile)
End Function

The function return false if the folder check fails.

 Is Drive Exist

Public Function DExists(OrigFile As String)
Dim fs, d
Set fs = CreateObject(“Scripting.FileSystemObject”)
    If fs.driveexists(OrigFile) = True Then
    Set d = fs.getdrive(OrigFile)
    DExists = 1
        If d.isready = True Then
        DExists = 2
        Exit Function
        End If
    Else
    DExists = 0
    End If
End Function

The function return a none zero value if the drive found and active other wise it leave a zero.

And finally the file check and it simple with three line code

File Check

Public Function FExists(OrigFile As String)
Dim fs
Set fs = CreateObject(“Scripting.FileSystemObject”)
FExists = fs.fileexists(OrigFile)
End Function

I thing that is enough to for a code poet to make sure the file exist in the system. Please re share the post.

Create a Auto generating Excel expense sheet with VBA


Microsoft Excel becomes one of my favourite application since I marry Excel macros, it help me lot to minimize tedious jobs. Here I will explain how you can perform an advanced Macro operation with the help of VB coding operations in Microsoft Excel 2013/2010/2007.

Making of Expense Sheet

 Firstly design your expense sheet as you like and Name the worksheet says ‘XP monthly’ which is short for Expense Monthly. It will be the base sheet which is working as source for additional sheet.

Sheet Renaming and checking for duplicate sheet

This task will require VB coding, just hit Alt+F11 to activate VB Editor and drop the following codes in Sheet1(XP Monthly).
Private Sub Worksheet_Activate()
Dim j, str, temp
If Name “xps” Or Name “XP Monthly” Or Left(Name, 3) = “XP-” Then

‘ FIND THE SPACE IN IN SHEET NAME FOR TITLE
For j = 4 To Len(Name)
 temp = Mid(Name, j, 1)
 If temp ” ” Then
   str = str & temp
 Else
  Exit For
 End If
Next
Range(“A7”) = str ‘ Name of the Month
‘………………………………………………………………………
End If
‘If (Left(Name, 3) = “xps” Or Name = “Monthly”) Then
Dim flag
flag = 0
‘ FIND THE PERIODS IN SHEET NAME
For j = Len(Name) To 1 Step -1
 temp = Mid(Name, j, 1)
If temp = “.” Then
 flag = 1
 Exit For
End If
Next
‘………………………………………………………………………
If (flag > 0) Then MsgBox “Naming is possible”
Dim nameStr As String
nameStr = “XP-” & MonthName(Month(Date)) & ” ” & Year(Date)
Dim i
‘ CHECK WHETHER THE SHEET NAME ALREADY TAKEN
Dim h, yy
For h = 1 To Worksheets.Count
 If Sheets.Item(h).Name = nameStr Then
  foo = True
  MsgBox “Sorry the XPs Sheet already exist for this month,Rename the sheet manually”, vbCritical, “Naming Error”
  Exit For
 End If
Next
If foo = False Then
 i = MsgBox(“Do you want to alter the worksheet name as ” & “‘” & nameStr & “‘” & “?”, vbYesNo, “Naming offer”)
 If i = vbYes Then Name = nameStr
End If
End If
End Sub

For avoiding the accidental renaming we add some numbers (NewXPS)with sheet name when it is duplicating.Above action will be perform when user switch between sheets during which Activate event of Sheet is fired.

Copying the Base sheet

Now we are ready create new Macro for copying the Base sheet for current month.Press Alt+F8 and enter macro name XPSheet and hit Create button and drop the following Macro code.

Sub NewXPS()
‘ NewXPS Macro
Sheets(“XP Monthly”).Select
Sheets(“XP Monthly”).Copy After:=Sheets(1)
ActiveSheet.Name = “XP-” & MonthName(Month(Date)) & ” ” & Year(Date) & ” ” & Rnd((1))
End Sub

The Rand() will generate random number file name, which used to avoid duplicating sheets. The sheet will be renamed later as current month, if there is no duplicate sheet otherwise you have rename it manually.

How to use this Macro enabled sheet

Whenever you need a new Expense sheet just run the Macro and switch between sheets once, it will rename automatically. VB Macro programming offer flexibility and ease of peace, working with MS Excel.

You can download and use complete Work Book from our Doc storage.

Clear and Format all textboxes at runtime in Visual Basic


All we know Visual Basic 6 is the simplest ways to develop Windows application for desktop computer. In this special article we are going to learn a code poem which automatically clear the text box content with few line of code. The idea sound good, isn’t it?

Firstly lets make a Sub to clear the fields. I have two method the first one let you clear selected text box which utilize the paramArray argument and the second will clear the entire field in a form. 
Open your Visual Basic 6.0 and enter the following sub routine.

Sub ClearBox for selected boxes

Sub ClearBox (ParamArray boxes() As Variant)
Dim ct As Variant
For Each ct In boxes
 If TypeOf ct Is TextBox Then
    ct.Text = “”
 End If
Next
End Sub

This sub will clear the passed text box controls  on the form,  The sub utilizes the paramArray feature, so that the program can accept any number of arguments/controls. Remember that paramArray object should be type of variant.

Clear all the boxes

The second method will clear all the boxes on the form. Lets take a look at the second code. 

Sub ClearBox_Auto(f As  Form)
 Dim ob As Object
 Dim ct As Control

 For Each ob In Form1.Controls
  Set ct = ob
  If TypeOf ct Is TextBox Then
    ct.Text = “”
  End If
 Next
 End Sub

Form’s controls property is returning the object collection and we collect each of then to ‘ob’ and then assign to a control variable and then can do the similar type of operations done in Clear Box. sub

Auto Number Format ‘Sub’

Finally I have a special format box which  utilise Forms controls collection to gather controls appeared in the User Interface and  apply specific number format to all the number field as follows.

Sub AutoNumberFormat(f As  Form)
 Dim ob As Object
 Dim ct As Control

 For Each ob In Form1.Controls
  Set ct = ob
  If TypeOf ct Is TextBox Then
     If IsNumeric(ct.Text) Then
        ct.Text = Format(ct, “0.00”)
     End If
  End If
 Next

End Sub


Call the Box function

Let invoke the subroutines on the click event of command button 
‘Clear selected boxes
 Call ClearBox(TextBox1, TextBox2, TextBox3)
‘Clear All the boxes
Call ClearBox_Auto(Me)

‘Format numbered fields
Call AutoNumberFormat(Me)

Note: 

The code is working on Microsoft Word VBA and Visual Studio 6.0   alike. For using on Word VBA please replace the Form (in argument) with UserForm

 Join us on Disqus.