Category Archives: Computer Science

About computers, algorithms and unusual troubleshoots.

Word cound in MS-Word using Fields

Sometimes you want to count the number of words in MS word file excluding titles, references etc. To do this follow these steps:
First count the number of words that has to be ignored (by selecting them, the status bar at bottom shows the number of selected words e.g. 15/1542)
Insert field using Ctrl+F9. a double bracket {} should appear.
type =
then insert field codes from insert menu (like number of pages, words etc:: insert>quickpart>fields>NumWords)
it should look like {=130-12}
right click and toggle the field code.

Now if you change the document, update the field code by selecting it and pressing F9 button.

Autocad calculation using fields and blocks

While drafting in AutoCAD, sometimes we come to situation where we need to upadate some text based on values of other text (similar to using formulas as in excel). In such case we can use FIELDS of Autocad to do our calculations and update the drawings automatically.

Basics:

The basic method to use field is very easy. Try following steps to get the idea.

>>MTEXT (type some number say 151) and click ok

>>MTEXT>Instert Field (or directly use FIELD command) : a dialog box will appear as shown below

field.PNG

-Select Field category: Objects

-Field names: Formula

-In Formula filed: right click >insert field : this will open new field window (the idea is use field value within another field)

-In this new Filed dialog box choose

-Filed names: Objects

-Objet type:Select the Mtext with the input number

-Property:Contents

-Click Ok

field2.PNG

Now in the original window there will be some value like 151 at the end type *2 so the content will look like 151*2

-Click ok

The new Mtext will change to value showing 302.

-To edit the formula, double click the field.

Now if the first Mtext value is changed to 100 from 151 then after REGENERATEing the drawing. The field will show 200.

For blocks

The fields will work not only in Mtext but also in Block attributes, hence making life easy to create blocks which has multiple values based on some formula of few input parameters. For eg a scale block (as shown below). However, there are few differences. A sample method is given below using example of scale block:

scaleautocad.PNG

– Draw the shapes (lines, hatch etc)

-Define block attributes (name them L1, R1,R2,R3,R4,R5,SCALE) (i made SCALE as hidden so that it will not be visible and will be used for calculation only) also i made all tags prompting to “DO NOT EDIT” as you will see later as these values should be updated automatically).

-Create block using BLOCK command

Now double click the box to change attibute value (say for value of L1).

-in Value field >right click>edit field

Now the field dialog box appears as discussed above.

-Select formula in field name

-in formula right click >Add fileds

New field dialog box appears

-select Object in field names

-select the Block that you had just created in Object type

-all tags will appear in the property (L1, R1,R2,R3,R4,R5,SCALE)

-Chose the tag that you want to use (here SCALE). Click ok

Back in the formula write the required formula using this variable (eg 1000*50)

-Click ok

Close all the dialog box

Now if you change value of SCALE tag and regenerate, the value of L1 will change according to the formula specified.

Repeat the process for all the tags to get required value.

field2.PNG

Excel VBA code to concatenate with custom characters

Sometimes it is necessary to join the contents of cell with custom characters like +,-,:,|, etc. This can be achieved by using excel inbuilt function CONCATENATE. The problem with this function is you will have to specify the character every time. The function listed below will help to simplify this problem.

The function can take multiple arguments just like =SUM() function.

Example:

=CONCATENATE_WITH_CUSTOM_CHARACTER("+", a1:c1,b8)

the result: all the cell values of a1:c1 and b8 will be displayed separated by “+” sign.

The code:


Function CONCATENATE_WITH_CUSTOM_CHARACTER(SEPERATOR, ParamArray args() As Variant)
' this function can take multiple parameters and return each cell value seperated by "+"
Dim i, j
Dim out
For i = LBound(args) To UBound(args)
    If IsNull(args(i)) = False Then 'check null value
            If IsArray(args(i)) = False Then 'check if arg is array
            'no array do usual
                If out = "" Then
                    out = args(i)
                ElseIf args(i) = "" Then
                    out = out
                 Else
                    out = out & SEPERATOR & args(i)
                End If
            Else  ' arg is an array, do for array
                For j = 1 To args(i).Count
                    If out = "" Then
                        out = args(i)(j)
                    ElseIf args(i)(j) = "" Then
                        out = out
                    Else
                        out = out & SEPERATOR & args(i)(j)
                    End If
                Next j
            End If ' array check end
    End If 'null check end

Next i
CONCATENATE_WITH_CUSTOM_CHARACTER = out

End Function

Cracking excel VBA password

To remove VBA password in Excel document use following steps. The steps are really simple and you can remove the password in no time.Backup the xls file first!

  1. Using a HEX editor, locate the DPB=… part
  2. Change the DPB=… string to DPx=…
  3. Open the xls file in Excel
  4. Excel discovers an invalid key (DPx) and asks whether you want to continue loading the project (basically ignoring the protection)
  5. Open the VBA editor (ALT+F11)
  6. Overwrite the password, so change it to something you can remember
  7. Save the xls file
  8. Close and reopen the document and work your VBA magic!

Solution was found at: http://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project

If you want to remove password from protected sheet then see https://nirmaljoshi.wordpress.com/2011/05/25/breaking-excel-passoword/.

How to setup your site in ZERO Rupee (.np doman)

If you are some of the guys who dont want to waste you money in building your website, Here is elaborated guide to set up your free domain and email.
A guide to set up http://mydomain.com.np and a email mail@mydomain.com.np

PART 1

First you need to register yourdomain.com.np at http://www.mos.com.np.
but before doing that you should do the following:

[Notes: If the website is personal you need to use your name in the domain, otherwise it will be rejected. A sample coverletter for you has been written below the article. You need to submit it with your details at the Mecentile Building, Durbarmarg.]

Go to http://www.freehostia.com/
registeran account for a free username and password
In the Hosted Domains add your domain that you registerd in the mos.com.np site ie mydomain.com.np

Now go to mos.com.np
Register for a domain. Fill the form. In the nameserver field of the form copy the following values
dns1.freehostia.com / IP: 66.40.52.47
dns2.freehostia.com / IP: 66.40.66.152

[note: The ip can be obtained by Run>Cmd>Ping dns1.freehostia.com]

Now you need to submit the necesary document to Mercentile office (at Durbarmarg) and wait until the domain gets activated.

PART 2

In the mean time we will set up our new site and email addreess.

Freehostia provides free incoming email but you cannot send email from here so we will use gmain instead.

To setup email go to http://www.google.com/a/ or here

Register for google apps (free) with your mydomain.com.np

Use Manage Domain>Service settings and activate the Email

In Setting>Email of google apps change URL of web address to http://mail.mydomain.com.np

Now goto freehostia.com
In custom DNS records change MX of mydomain.com.np value to ASPMX.L.GOOGLE.COM (MX stands for mail exchange)

Register new subdomain named mail.mydomain.com from subdomain manager

Again go to ustom DNS records andchange ip number of A record of mail.mydomain.com.np to ghs.google.com

Thats all. You have also set up the email address for youself.

It will take 2-3 days to update all the server in the planet for your email and domains

PART 3

Set up a content management system for your site

Go to freehostia.com

Install Joomla 1.5 listed in Web tools> Elephat free scripts

During the process you will be asked to set up a database. Make a database. Remember the password you provided.

————

Now wait and wait and wait

RUN>CMD>Ping mydomain.com.np each day until you get the reply.
————
visit http://mydomain.com.np to see your website
visit http://mydomain.com.np/administrator to adminster the content of your site (if you have installed joomla 1.5)
visit http://mail.mydomain.com.np to access your email mail@mydomain.com.np (with all cool gmail features)

——

Cover letter

To,
NPccTLD Registration Services
MERCANTILE COMMUNICATIONS PVT. LTD.
P. O. Box 876
Durbarmarg, Kathmandu, NEPAL

Subject: Registration of domain

Dear Sir/ Madam,
I would like to register .np domain name. I have already submitted the .np domain registration online form. I have attached the photocopy of my citizenship with this application.

I will be happy if you register my domain name as soon as possible. Thank you for considering my application.

Domain name: www.mydomain.com.np 

Sincerely,
Mr. xxxx