Thursday 10 October 2013

Windows and Linux..... a better Server and a better Desktop

It's a very common discussion comparing Windows and Linux. As windows is favorable to everyone using desktop PC but till now Linux is more suitable as using as a server than windows. Through linux is slowly growing popularity in Desktop version as in Ubuntu, but still windows is still the better one as a desktop version than linux, more user interactivity, easy to install device driver and software, to say specifically linux is a better OS for software engineers.
But.... but but .. when it's comes question of using server version, undoubtedly linux seems to be the best. You can runa machine running linux server for days and months without even restarting without any problems, while windows needs to upgrade itself every weeks so on. It's needed restarting the OS and these upgrade makes the server slow day by day, but linux, continue it for months without any maintenance, restarting. So don't you think it's better to have a server with linux version than windows.
I generally saw students have a fascination of installing desktop version of linux on their machine and getting bored a few days after. They used to get frustrated with package installations, tired of fetching dependency rpms and a few days after they are happy to wipe out the linux version and continue with windows. So for students this is a message that linux is not a fascinating stufff or nor does it server purpose of some gaming stuff, it's in a clean way a stuff that requires a bit of learning to depth and a little patience and then you will find how interesting it is. Tell me one think.... if you are a programmer and you think that the features you see in your desktop version needs to be just as you want it to be... in Windows!!!! never never never. But in linux just take the source code of any package which generally comes in tar format. Modify it as per your wish (until you use it commercially), compile it and GET SET GO..... Windows also give you this privilege but in API format and you don't know what the hell is inside it. All the distros of linux  you see is derived from some basic version of linux, modifying the source code and get your own DISTROS.
So guys if are fascinated with linux boost your fascination to OBSESSION and you will find the secret of this OS, otherwise if you are having  some business needs to maintain a huge data on your server, my suggestion is to use linux server version, believe me it will rock, but but but don't get excited with it, it's better to provide your employee  a desktop with windows version.

thanks to Eli Etherton for information on Using linux as server.



Monday 7 October 2013

How to change the case of letter of the content of a file in bash shell

Suppose there is a file named file1.txt which contains
----
Hello World
This is a simple command
------

Now the command will be like this
$cat file1.txt | while read line; do; echo $line | tr "a-z" "A-Z"; done

Now what happens here
first cat prints the content of the file which instead of going to stdout goes as input to the next
command through the PIPE ( | ). Here we runs a loop which reads one line at a time it gets as
input from file1.txt, and again PIPED to another command tr which is a translation command
converting each character from small case ("a-z") to upper ("A-Z"). while loop runs until last line
of the file is reached.

Output is

----
hELLO wORLD
tHIS IS A SIMPLE COMMAND
------

Glob expressions in Shell Scripting in Linux

1. If you are a regular user of MS Dos you might know the use of wild cards.
The same is applicable in Linux shell know as GLOB Expression

like if you write this syntax

for name in d??

this will find all the file names in your current directory with 3 characters
starting with d and then any 2 characters like doc,dol...

In the same way if we write

for name in *d??
this will show all file name ending with d following any 2 characters
just like extension name, doc,div etc.

2. a. Regular expression in enclose characters
    m[0123456789]x
    it may be any name starting with m followed by digits and ending
    with x
    this can be made short by using m[0-9]x.
  
  The same thing can be done with alphabets
   [0-9][a-z].  This expression will take anything starting with digits and ending with
   alphabets in small case. eg. 98ab but not ab98 or 98AB.

   Negation
   Condition can be negated like m[!0-9]x will take anything starting with    m, any non numeric     
  characters, ending with x,  eg. xyzABCx
  or [0-9][!a-z] will read anything starting with numbers and ending with
  anything not alphabets in small case. eg. 79XYZ.

  In case you want alphabets with both lower case and upper case then you write [a-zA-Z]
  You can also provide range of alphabets or numbers. Like [d-jF-N] will validated any string
  starting with lower case alphabets between d and j and upper case alphabets between F and N.
  The same is with  numbers. [5-9] will validate anything between 5 and 9. 234 is wrong.
 
  All this expression given above only works if files with such pattern exists otherwise it will
  return the expression itself

  Say if you write for name in [a-z]123, this will print the name of file starting with alphabets
  but ending with 123 (may be extension name), but if file with such pattern does not exists it
  will return just the expression [a-z]123.

Friday 4 October 2013

Navigating through the arguments of a shell script while executing

 How to get access to the arguments we pass while executing a shell script  
   In the shell script myscript.sh we write
  
   #!bin/bash
  
   while [ -n "$1" ]
   do
     echo "$1"
     shift
   done
  
   output of the shell script when its argument are like this
  
   myscript.sh first comes nation then family
  
   first
   comes
   nation
   then
   family
  
   shift actually takes the next argument from $1 to $2 then to $3 and so on.
   -n "$1" checks whether the value is non zero. When there is no more argument
   -n "$1" return false and the loop end.
  
   You can also write the condition like this.
  
   while [ ! -z "$1" ]
  
   -z check whether the value of "$1" is zero so when there is argument -z "$1" returns false
   so when it is prefixed by ! its return true.
  
   Using for loop instead of while loop
  
   As $1, $2, $3 returns consecutive arguments, $@ return all the arguments in a sentence separated
   by space so if write a for loop like this
  
   for arg in "$@" - here arg takes one word from the sentence $@ for each iteration
   The full script is like this
  
   for arg in "$@"
   do
   echo "$@"
   done

Thursday 3 October 2013

How to check whether a file is a shell script file (.sh) or not

   As we know that the first line of a shell script file contains #!bin/bash,
   so we will check whether a file contains the text bin/bash
  
   Arguments of a shell script file is identified as $1,$2,$2....
   $1 is the name of the executing script file itself, and arguments of
   the script files are $2,$3 ....
  
   So lets us write a shell script file isscript.sh
  
   #!bin/bash
  
   if grep "bin/bash" "$1"
   then
    echo "File is a shell script file"
   else
    echo "File is not a shell script file"
   fi
  
   now suppose we want to see whether a file named abc.sh is a
   shell script file or not
  
   so we run the isscript file like this
   $./isscript.sh abc.sh
  
   Now the shell script takes abc.sh as argument $1
   grep "bin/bash" "$1" checks whether the pattern "bin/bash"
   exists in the shell script abc.sh, if exists then command
   echo "File is a shell script file" is executed otherwise
   echo "File is not a shell script file" is executed.
  
  
  

How to create a bash script

   A shell script file should conventionally have an extension .sh

   The first line of your script file should be #!/bin/bash, this line actually tells
   the OS that the script is a bash script.

   A simple script file example

   open a script file say file1.sh with vi. vi file1.sh

   #!/bin/bash
   echo "Hello World, this is what I got in my home directory
   ls /home/subhroneel

   save the file and quit vi.

   set executable permission to file1.sh

   $chmod u+x file1.sh

   run the script just as written below

   $./file1.sh

   output is:  
   Hello World
   Listing of /home/subhroneel directory
   Music Video Ebooks  

Wednesday 2 October 2013

Basic Linux Bash command

1. Pathname
To types of pathname are there, Relative pathname and Abosolute pathname

Relative pathname does not begins with /, it is always relative to the present working directory.
Suppose your present working directory is /home/myuser, so if you type
$ pwd ($ is the prompt, you type pwd), it will display /home/myuser, this is the absolute path.
Now if you type cd games, then games here is relative to /home/myuser and your present directory changes to /home/myuser/games. IF you have type cd /home/myuser/games the
same thing happened but in this case you have given absolute path.

2. ls
Lists the contents of the current working directory
(pwd - "Print Working Directory" To see the current working directory)

ls -a
List all files including the files with Dot prefix

ls -l

List name of files with details like permission,date time (created/modified)

Commands can be combined
Say you want to list all files with details you type
ls -a -l or ls -al
This joining can be only done for Short options
for long options like -all you cannot join to options
(example ls -al)

Long and short options can be mixed.
ls --all -l

3.  . and .. (dot and dotdot) directory
    Every directory (even empty) contains two directory in it. One is . (dot) and another is .. (dotdot)
    . (dot) directory is actually the shortcut to the current working directory and .. (dotdot) is a     shortcut to the parent working directory. For example if you type cd .. (you present directory is   /home/myuser/games) you will navigate to /home/myuser.
   For example if you type ls ../ (your pwd is /home/myuser/games) it will list all files and   directories in  myuser folder.

4. rm  - Commands used to delete a file.
   
    Command is - rm filename.extensionname
     rm file1.txt

     rm does not remove directory but you can remove list of files in a directory by this command
     rm -r directoryname.  (-r recursive method)
     rm -r Music.  This command will remove all the files in the directory Music.

     You cannot remove files with rm if you do not have write permission on the files.

     
5. cp - Copies files / directory from source to destination

    cp file1.txt file2.txt
    cp /home/myuser/Music/a.txt /home/myuser/a.txt

    cp can also copy directories and sub directories in a recirsive manner.

    cp -r dir1 dir2.  This copies all contents of dir1 including files and subdirectories to dir2.

6. mv - Moves files / directories from source to destination
    mv oldfilename.txt newfilename.txt (this is similar to renaming a file).
    mv /home/myuser/Music/olddir /home/myuser/newdir

7. cat,tac and less command
     cat file1.txt prints the content of the file
     cat file1.txt file2.txt file3.txt displays content of all the three files concatenated.
   
     tac file1.txt prints the content of the file in reverse order.
   
     less file1.txt displays contents of the file pagewise.

8.  file command Gives information about the file type
      file file1.bmp  Bitmap image

9.  find command searches the entire directories/subdirectories starting from the source           directory specified for a certain file/ directory specified. Wildcard can be used.
    
      find / -name "*.txt" searches all files with extension txt starting from /

10. locate command does the same as find but build an index before searching which makes the           search more faster.
      locate abc.txt
      locate command cannot be used to search a newly created file until it is indexed, in that case          you have to use the find command.

11. chmod
      syntax is - chmod permissions filename
      chmod u+x file1.sh. Set/Adds executable (x) permission to current user (u) (u+x).
      chmod u-x file1.sh.  Unset/removes executable (x) permission to current user (u) (u-x).
      chmod go-rwx file1.sh Unset/removes read,write,executing permission from the group (g) the
      user belongs to and all others (o). So with this permission only user has the rights. Rights are
      revoked from everybody else.

12. gzip and gunzip
     
      gzip  compreses a file 
      gzip file1.txt  this command compress the file file1.txt to file1.txt.gz
     
      gunzip file1.txt.gz this command uncompress the file file1.txt.gz to file1.txt
     
      gzip works best for text files.
      gzip is not an archiver, it's a compressor. Archiver archives multiple files to a single file like winrar or winzip,
      but gzip compresses only a single file.
      To archive files you need to use tar command.

13. tar archive a directory containing multiple files
     create
     tar -cvf Musicbkup.tar /home/myuser/Music, c is to create the archive, v is for verbose mode       
     (prints all the files names to be archived), f is for target tar filename (Musicbkup.tar),
     if you mention f option you need to give the output archivename.
   
     tar -czvf Musicbkup.tar.gz /home/myuser/Music, z is added to the options -cvf to compress the archived file.
       
     extract
     tar -xvf Musicbkup.tar, extract all files from the archive.

     tar -xzvf Musicbkup.tar.gz, extract and uncompress all files from the compressed .gz.

     tar -xzvf Musicbkup.tar.gz actually perform two commands into one. First its gunzip
     Musicbkup.tar.gz into Musicbkup.tar and then extract all files from Musicbkup.tar.
   
14. head and tail commands
    head -n 10 file1.txt prints the first 10 lines of the file file1.txt, option n being the number of lines.
    head does the same thing as less commands but less commands prints page by pagee but head
    commands prints the desired number of lines.
   
    tail -n 10 file1.txt prints the last 10 lines of the file file1.txt, option n being the number of lines.
   
15. du command prints the amount of space a specified diretory use in the disk.
    du -sh Desktop if s option is not given then du command prints size information of all the subdirectories under
    specified directories, s option summarizes all the information and only shows the space occupied by it. h option
    gives the size information in MB or GB instead of bytes, if you do not provide h option result will come into byte units.

16. grep command searches for pattern in the content of a file specified.
    grep sun file1.txt searches for pattern sun output can be like this sun,sunny,sundry,prasun.
   
17. history command list all the previous commands you have typed. Up and down arrow browse through history in lifo method.
    when you type any command the commands stored into the memory but when you end terminal session all commands are appended
    into a file automatically. Now when you are into one session and you want to see the command history on another terminal
    session, it will not show because it is not written onto disk yet. You can type history -a which flushes the memory and
    append current history in the file and you can see those commands when you type history from other terminal session.
   
18. export command to set environment variable on your current session
    export VAR_NAME=value general convension is to set the variable in upper case.
    export ORACLE_HOME=u01/oracle/app/db_1
    unset VAR_NAME - command to unset the environment variable is
    unset ORACLE_HOME
   
19. vi / vim editor vi or vim editor is a text editor which can be used to create file, edit contents of the file.
    command is vi filename or vim filename
    some commands in insert mode
    'i' turn insert mode on by moving the cursor to the next cursor location
    'a' turn insert mode keeping the cursor where it is.
    'i' to insert text or to say to turn the editor to insert mode
    'esc' to turn off the insert mode and enter to command mode
   
    this commands works when not in command mode
    'h' move the cursor to the left.
    'k' move the cursor up.
    'l' move the cursor to the right.
    'j' move the cursor down.
    'b' move one word left.
    'w' move one word right.
    'x' delete one character right (del).
    'X' delete one character left (backspace).
    'V' Highlight / Salect a complete line.
    'j' to hightlight the line following the selected line downwards.
    'y' (yank) to copy a selected line / paragraph.
    'p' paste a copied line / paragraph on top of the copied section.
    'P' paste a copied line / paragraph below the copied section.
    'd' delete a selected line / paragraph.
    :w writes changes to disk / save the file.
    :q quits vim.
    :wq writes changes to disk and then quit vim.
    :q! discard changes to file and then quit vim.
   
19. env - a command to see all the environment variable set in the current session.   

20. sort  this command sorts lines in a file in alphabetical order.
    sort file1.txt

Tuesday 1 October 2013

A Simple PC Diagnostic Tool Project

This is a simple PC Diagnostic Tool project developed using windows management service class library in Visual Basic 6.0.
.
Download the project


How to search windows component using Windows API in Visual Basic 6.0

Download Source Code

Option Explicit
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" _
Alias "GetMenuItemInfoA" (ByVal hMenu As Long, _
ByVal un As Long, ByVal b As Boolean, _
lpMenuItemInfo As MENUITEMINFO) As Boolean

Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&

Private Const MIIM_ID = &H2
Private Const MIIM_TYPE = &H10
Private Const MFT_STRING = &H0&

Private Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
End Type

Dim taskBarhWnd As Long, notifyTrayhWnd As Long, rebarWindow As Long, toolbarWindow As Long, quickLaunchWindow As Long, startBtnWindow As Long
Dim ppthWnd As Long, ribbonhWnd As Long, panehWnd As Long, deskhWnd As Long, vbhWnd As Long, vbmainMenuhWnd As Long, vbaWindowhWnd As Long, ExplorerhWnd As Long

Private Sub Command1_Click(Index As Integer)
    Select Case Index
    Case 0
        taskBarhWnd = FindWindow("Shell_TrayWnd", vbNullString)
        notifyTrayhWnd = FindWindowEx(taskBarhWnd, 0&, "TrayNotifyWnd", vbNullString)
        Call ShowWindow(notifyTrayhWnd, show_Chk(Index).Value)
    Case 1
        taskBarhWnd = FindWindow("Shell_TrayWnd", vbNullString)
        'toolbarWindow = FindWindow("RebarWindow32", "")
        rebarWindow = FindWindowEx(taskBarhWnd, 0&, "RebarWindow32", "")
        Call ShowWindow(rebarWindow, show_Chk(Index).Value)
    Case 2
        taskBarhWnd = FindWindow("Shell_TrayWnd", vbNullString)
        'toolbarWindow = FindWindow("RebarWindow32", "")
        quickLaunchWindow = FindWindowEx(FindWindowEx(taskBarhWnd, 0&, "RebarWindow32", ""), 0&, "ToolbarWindow32", "Quick Launch")
        Call ShowWindow(quickLaunchWindow, show_Chk(Index).Value)
    Case 3
        taskBarhWnd = FindWindow("Shell_TrayWnd", vbNullString)
        startBtnWindow = FindWindowEx(taskBarhWnd, 0&, "button", "start")
        Call ShowWindow(startBtnWindow, show_Chk(Index).Value)
    Case 4
        taskBarhWnd = FindWindow("Shell_TrayWnd", vbNullString)
        'toolbarWindow = FindWindow("RebarWindow32", "")
        quickLaunchWindow = FindWindowEx(FindWindowEx(taskBarhWnd, 0&, "RebarWindow32", ""), 0&, "ToolbarWindow32", "Quick Launch")
        toolbarWindow = FindWindowEx(FindWindowEx(taskBarhWnd, 0&, "RebarWindow32", ""), quickLaunchWindow, "ToolbarWindow32", "Running Applications")
        Call ShowWindow(toolbarWindow, show_Chk(Index).Value)
    Case 5
        ppthWnd = FindWindow("PP12FrameClass", vbNullString)
        'panehWnd = FindWindowEx(ppthWnd, 0&, "paneClassDC", "Slide")
        Call ShowWindow(ppthWnd, show_Chk(Index).Value)
    Case 6
        ppthWnd = FindWindow("PP11FrameClass", vbNullString)
        'panehWnd = FindWindowEx(ppthWnd, 0&, "paneClassDC", "Slide")
        Call ShowWindow(ppthWnd, show_Chk(Index).Value)
    Case 7
        vbhWnd = FindWindow("wndclass_desked_gsk", vbNullString)
        'panehWnd = FindWindowEx(ppthWnd, 0&, "paneClassDC", "Slide")
        Call ShowWindow(vbhWnd, show_Chk(Index).Value)
    Case 8
        vbhWnd = FindWindow("wndclass_desked_gsk", vbNullString)
        vbmainMenuhWnd = FindWindowEx(FindWindowEx(vbhWnd, 0&, "MsoCommandBarDock", "MsoDockTop"), 0&, "MsoCommandBar", "Menu Bar")
        'panehWnd = FindWindowEx(ppthWnd, 0&, "paneClassDC", "Slide")
        Call ShowWindow(vbmainMenuhWnd, show_Chk(Index).Value)
    Case 9
        vbhWnd = FindWindow("wndclass_desked_gsk", vbNullString)
        vbaWindowhWnd = FindWindowEx(FindWindowEx(vbhWnd, 0&, "MDIClient", ""), 0&, "VbaWindow", "Form1 (Code)")
        'panehWnd = FindWindowEx(ppthWnd, 0&, "paneClassDC", "Slide")
        Call ShowWindow(vbaWindowhWnd, show_Chk(Index).Value)
    Case 10
        ExplorerhWnd = FindWindow("CabinetWClass", "My Computer")
       ' vbaWindowhWnd = FindWindowEx(FindWindowEx(vbhWnd, 0&, "MDIClient", ""), 0&, "#32770(Dialog)", "Display Properties")
        'panehWnd = FindWindowEx(ppthWnd, 0&, "paneClassDC", "Slide")
        Call ShowWindow(FindWindow("CabinetWClass", "My Computer"), show_Chk(Index).Value)
        Call ShowWindow(FindWindow("ExploreWClass", "My Computer"), show_Chk(Index).Value)
    End Select
End Sub

Private Sub Text1_LostFocus()
    Timer1.Enabled = False
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
        Timer1.Enabled = True
        Timer1.Interval = 10
    End If
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
    Dim hMenu As Long, hSubMenu As Long, hID As Long, ExtraSubMenu As Long
'    'hMenu = GetActiveWindow
    hMenu = GetMenu(Me.hwnd)
'
    If GetMenuItemCount(hMenu) > 0 Then
        RemoveMenu hMenu, 0, MF_BYPOSITION Or MF_REMOVE
        RemoveMenu hMenu, 1, MF_BYPOSITION Or MF_REMOVE
    End If
'    Debug.Print hMenu
    hSubMenu = GetSubMenu(hMenu, 0)
   
    Debug.Print hSubMenu
    Call ShowWindow(hSubMenu, 0)
End Sub

A usercontrol example to build an Analog clock in Visual Basic 6.0

Download Source Code

Option Explicit
Private Type POINTAPI
    x As Double
    y As Double
End Type
Private oHrCenter As POINTAPI, oHrEnd As POINTAPI
Private oMinCenter As POINTAPI, oMinEnd As POINTAPI
Private oSecCenter As POINTAPI, oSecEnd As POINTAPI
Private m_Hour As Integer
Private m_Minute As Integer
Private m_Second As Integer
Private m_Radius As Double
Private Const PIE = 3.14159265358979

Private Sub Timer1_Timer()
    Call UserControl_Resize
End Sub

Private Sub UserControl_Initialize()
    UserControl.ScaleMode = vbPixels
End Sub

Private Sub DrawClock()
    UserControl.Cls
    m_Hour = VBA.hour(VBA.Now)
    m_Minute = VBA.Minute(VBA.Now)
    m_Second = VBA.second(VBA.Now)
    Call SetHour((m_Hour Mod 12))
    Call SetMinute(m_Minute)
    Call SetSecond(m_Second)
    Debug.Print (m_Second) & " : " & GetAngle(m_Second * 6)
    UserControl.Circle (oHrCenter.x, oHrCenter.y), m_Radius, RGB(255, 255, 255)
    UserControl.DrawWidth = 2    UserControl.Line (oHrCenter.x, oHrCenter.y)-(oHrEnd.x, oHrEnd.y)
    UserControl.DrawWidth = 1
    UserControl.Line (oMinCenter.x, oMinCenter.y)-(oMinEnd.x, oMinEnd.y)
    UserControl.Line (oSecCenter.x, oSecCenter.y)-(oSecEnd.x, oSecEnd.y)
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    If UserControl.Ambient.UserMode = True Then
        Timer1.Enabled = True
        Timer1.Interval = 1000
    End If
End Sub

Private Sub UserControl_Resize()
    UserControl.Height = UserControl.Width
    m_Radius = UserControl.ScaleWidth / 2 - 1
    DrawClock
End Sub

Public Sub SetHour(hour As Integer)
    oHrCenter.x = UserControl.ScaleWidth / 2
    oHrCenter.y = UserControl.ScaleHeight / 2
    oHrEnd.x = (m_Radius - 10) * XValue(hour * 30) + oHrCenter.x
    oHrEnd.y = (m_Radius - 10) * YValue(hour * 30) + oHrCenter.y
End Sub

Public Sub SetMinute(min As Integer)
    oMinCenter.x = UserControl.ScaleWidth / 2
    oMinCenter.y = UserControl.ScaleHeight / 2
    oMinEnd.x = (m_Radius - 5) * XValue(min * 6) + oMinCenter.x
    oMinEnd.y = (m_Radius - 5) * YValue(min * 6) + oMinCenter.y
End Sub

Public Sub SetSecond(second As Integer)
    oSecCenter.x = UserControl.ScaleWidth / 2
    oSecCenter.y = UserControl.ScaleHeight / 2
    oSecEnd.x = (m_Radius) * XValue(second * 6) + oSecCenter.x
    oSecEnd.y = (m_Radius) * YValue(second * 6) + oSecCenter.y
 '   Debug.Print (second * 6)

End Sub

Private Function GetAngle(ang As Double) As Double
'    If ang > 0 And ang <= 90 Then
'      GetAngle = 90 - ang
'    Else
        GetAngle = (450 - ang)
'    End If
End Function

Private Function YValue(ByVal angle As Double) As Double
  Select Case angle
    Case 0 To 90, 360 To 450
      YValue = -Math.Sin(GetAngle(angle) * 2 * PIE / 360)
    Case 90 To 180
      YValue = -Math.Sin(GetAngle(angle) * 2 * PIE / 360)
    Case 180 To 270
      YValue = -Math.Sin(GetAngle(angle) * 2 * PIE / 360)
    Case 270 To 360
      YValue = -Math.Sin(GetAngle(angle) * 2 * PIE / 360)
  End Select
End Function

Private Function XValue(ByVal angle As Double) As Double
  Select Case (angle)
    Case 0 To 90, 360 To 450
      XValue = Math.Cos(GetAngle(angle) * 2 * PIE / 360)
    Case 90 To 180
      XValue = Math.Cos(GetAngle(angle) * 2 * PIE / 360)
    Case 180 To 270
      XValue = Math.Cos(GetAngle(angle) * 2 * PIE / 360)
    Case 270 To 360
      XValue = Math.Cos(GetAngle(angle) * 2 * PIE / 360)
  End Select
End Function

How to browse folder using Windows API

Download Source Code

option explicit

Private Type BrowseInfo
     hwndOwner As Long
     pIDLRoot As Long
     pszDisplayName As Long
     lpszTitle As Long
     ulFlags As Long
     lpfnCallback As Long
     lParam As Long
     iImage As Long
End Type
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function getTempPathAPI Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Private Const MAX_PATH = 1024

Private Sub Command1_Click()
  Dim b As BrowseInfo
  MsgBox BrowseForFolder(0, "Browse", "c:\")
End Sub

Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String, ByVal StartLocation As String) As String
    'Declare variables to be used
     Dim iNull As Integer
     Dim lpIDList As Long
     Dim lResult As Long
     Dim sPath As String
     Dim BI As BrowseInfo
    'Initialise Type variables
     With BI
        .hwndOwner = hwndOwner
        .lpszTitle = lstrcat(sPrompt, "")
        .ulFlags = BIF_RETURNONLYFSDIRS
        .lpfnCallback = getFunctionLong
        .lParam = lstrcat(StartLocation, "")
     End With
    'Call the browse for folder API
     lpIDList = SHBrowseForFolder(BI)
    'Get the resulting string path
     If lpIDList Then
        sPath = String$(MAX_PATH, Chr$(0))
        lResult = SHGetPathFromIDList(lpIDList, sPath)
        Call CoTaskMemFree(lpIDList)
        iNull = InStr(sPath, vbNullChar)
        If iNull Then sPath = Left$(sPath, iNull - 1)
     End If
    'If cancelled, set sPath = ""
     BrowseForFolder = sPath
End Function