Thursday 25 December 2014

writing file using vbscript

'Option Explicit
dim objXML2,fso,strdir,CurrentDirectory,ExportFile,LocalPath,SVNPath,colNodes,objnode
Set objXML2 = CreateObject("Microsoft.XMLDOM")
objXML2.async = "false"
strdir=WScript.Arguments.item(0)'PRODUCTINFO.xml

set fso = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = fso.GetAbsolutePathName(".")
Set ExportFile = fso.CreateTextFile(CurrentDirectory&"\SVNExport.cmd", True)
ExportFile.WriteLine("@echo off")
'ExportFile.WriteLine("start /b 1")

LocalPath = 'WScript.Arguments.item(1)
SVNPath = 'WScript.Arguments.item(2)

'ExportFile.WriteLine("LocalPath: " & LocalPath)
'ExportFile.WriteLine("SVNPath: " & SVNPath)

If (Not objXML2.load(strdir)) Then
    wscript.echo "Unable to load file '" & strdir & "'. "
    WScript.Quit(1)
End If

Set colNodes = objXML2.selectNodes ("/PRODUCTINFO/PRODUCT")
For Each objNode in colNodes
    wscript.echo objnode.getAttribute("NAME")& " : " & objnode.getAttribute("VERSION")
ExportFile.WriteLine("echo Getting " & objnode.getAttribute("NAME") & " of version " & objnode.getAttribute("VERSION") & " from SVN")
ExportFile.WriteLine("""C:\Program Files\TortoiseSVN\bin\svn.exe"" export """ & SVNPath & "/" & objnode.getAttribute("NAME") & "/" & objnode.getAttribute("VERSION") & """   """ & LocalPath & "\" & objnode.getAttribute("NAME") & "\" & objnode.getAttribute("VERSION"))
Next
ExportFile.WriteLine("echo Export Completed")
ExportFile.close()

Thursday 9 October 2014

SSL Settings automation using netsh and appcmd

appcmd set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:']
======================================================================

# get the thumbprint for the certificate we want to use:
$thumb = (Get-ChildItem cert:\LocalMachine\MY | where-object { $_.FriendlyName -eq   "www.stackoverflow.com" } | Select-Object -First 1).Thumbprint
# get a new guid:
$guid = [guid]::NewGuid()

# remove the self-signed certificate:
& netsh http delete sslcert ipport=0.0.0.0:8172
# add the 'proper' certificate:
& netsh http add sslcert ipport=0.0.0.0:8172 certhash=$thumb appid=`{$guid`}


more information

http://www.iis.net/learn/manage/powershell/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in







Tuesday 12 August 2014

links for the COM+ registering



http://msdn.microsoft.com/en-us/library/tzat5yw6(v=vs.110).aspx

http://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C

http://community.microfocus.com/borland/define/caliber_-_requirements_management/w/knowledge_base/16090.why-when-registering-the-helloworld2-vbnet-dll-does-it-generate-the-error-regasm-warning-ra0000-no-types-were-registered.aspx


http://stackoverflow.com/questions/1847763/problem-registering-a-dll-access-denied


http://msdn.microsoft.com/en-us/library/dd233108(v=vs.110).aspx


http://www.codeproject.com/Articles/1405/Using-the-Web-Services-and-COM-Event-System-in-the

http://www.codeproject.com/Articles/206412/Reflection-An-Introduction-to-Reflection-in-NE


http://www.codeproject.com/Articles/337535/Understanding-the-Basics-of-Web-Service-in-ASP-NET

http://msdn.microsoft.com/en-us/magazine/cc301491.aspx

http://oreilly.com/catalog/comdotnetsvs/chapter/ch10.html

http://my.execpc.com/~gopalan/dotnet/complus/complus.net_accountmanager.html

http://www.codeproject.com/Articles/1511/Accessing-COM-component-using-C

http://edndoc.esri.com/arcobjects/9.2/NET/3a2694e6-32da-4e1e-b7c5-ccd3826161bb.htm

http://www.codeproject.com/Articles/206412/Reflection-An-Introduction-to-Reflection-in-NE

http://www.jagjot.com/2014/01/register-c-vb-net-dll-regasm-gacutil/


Friday 8 August 2014

Thursday 7 August 2014

system.data.oledb.oledbexception could not find installable isam


The path name should be like below:

string filename = "C:\\Praveen\\Tasks\\TASK 1\\Mydata.xlsx";
            MyOleCon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ filename +";Extended Properties=\"Excel 12.0 Xml;HDR=YES;\"");

Sunday 8 June 2014

Creating Bootable Pen Drive Using Windows Command Prompt


I have used this links:



Making a pen drive bootable is possible in Windows7 & Windows8 operating system. Formatting a computer to install fresh Windows OS with a CD/DVD drive is not very good because it takes too much time to install fresh Windows operating system. There can also be a problem for many people that CD/DVD drive doesn’t work properly. So this can be a problem for them. Today laptop or desktop comes many USB ports. So there is no need of CD/DVD drive to format a system. Formatting is very fast and easy with flash drive/pen drive and also no software is required for this method. Windows7 or Windows8 command prompt can do the work with few lines of command. Just follow this tutorial.

Start your command prompt.
 For windows7 users:
1. Go to “Start” button and click. Write “cmd” then cmd icon will appear on the top of the panel.
2. “Right click” on the cmd icon and click “Run as administrator”
3. It will open the command prompt.





Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>diskpart

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: SUMAN

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          298 GB  1024 KB
  Disk 1    Online           14 GB      0 B

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> clean

DiskPart succeeded in cleaning the disk.

DISKPART> create partition primary

DiskPart succeeded in creating the specified partition.

DISKPART> list partition 1

The arguments specified for this command are not valid.
For more information on the command type: HELP LIST PARTITION

DISKPART> list partition

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
* Partition 1    Primary             14 GB  1024 KB

DISKPART> select partition 1

Partition 1 is now the selected partition.

DISKPART> active

DiskPart marked the current partition as active.

DISKPART> format fs=ntfs

  100 percent completed

DiskPart successfully formatted the volume.

DISKPART> active

DiskPart marked the current partition as active.

DISKPART> exit

Leaving DiskPart...

C:\Windows\system32>

Friday 30 May 2014

Design patterns

Skills needed for .Net experienced

Skills needed for .Net experienced
  • .Net Framework (2.0, 3.5)
  • ASP.NET (2.0)
  • C#/VB.NET
  • Object Oriented Programming
  • .NET IDE (2008)
  • Debug Tools (Fiddler, IE Dev tools, Firebug)
  • SQL Server 2K/2005/8
  • Oracle 11g
  • Web Services/WCF
  • AJAX
  • XML & XSL
  • HTML, CSS
  • Javascript
  • Jquery
  • JSON
  • Crystal Reports
  • Methodologies (AGILE Scrum)
  • VSS, SVN
  • IIS 6.0
  • Modelling Tools (Visio, Erwin)
  • Design Patterns
  • Frameworks(Entity, Spring, MVC)







.Net good materials links

This is the best video material links which is created by G venkat

C# and ASP.net and MVC and WCF.

http://www.pragimtech.com/c-sharp-video-tutorials.aspx


Discover the Design Patterns You're Already Using in the .NET Framework

Introducing Windows Communication Foundation in .NET Framework 4

Object-Oriented Programming (C# and Visual Basic)

Six important .NET concepts: Stack, heap, value types, reference types, boxing, and unboxing

A Guide to Designing and Building RESTful Web Services with WCF 3.5

Basic Security Practices for Web Applications

Building web apps without web forms

C# Tuterails link

.Net interview real time interview questions




Blog for the interview questions

http://computerauthor.blogspot.in/





sharepoint server 2007 meterial links

Wednesday 9 April 2014

To find the used range of the rows in Excel using VBA

To find the used range of the rows and columns:

Set VillageDataSheet = Worksheets("Water Point Data")
-> NumPoints = VillageDataSheet.UsedRange.Rows.Count
-> NumPoints = VillageDataSheet.Range("A" & VillageDataSheet.Rows.Count).End(xlUp).Row


Tuesday 25 March 2014

How to find the text column number using VBA


it will search the value and find the column number

m_BlocID_CLM = WorksheetFunction.Match("Bloc ID", ActiveWorkbook.Sheets("Data").Range("1:1"), 0)


it will return the value 1

Thursday 13 February 2014

VBA function to convert column number to letter?


Function Col_Letter(lngCol As Long) As String

Dim vArr
vArr = Split(Cells(1, lngCol).Address(True, False), "$")
Col_Letter = vArr(0)
End Function

Sub Test()
MsgBox Col_Letter(100)
End Sub

Friday 7 February 2014

AllowFormattingCells Property [Excel 2003 VBA Language Reference]

Sub ProtectionOptions()

    ActiveSheet.Unprotect

    ' Allow cells to be formatted on a protected worksheet.
    If ActiveSheet.Protection.AllowFormattingCells = False Then
        ActiveSheet.Protect AllowFormattingCells:=True
    End If

    MsgBox "Cells can be formatted on this protected worksheet."

End Sub

How to write the string(unicode) to textfile

Set fs = CreateObject("Scripting.FileSystemObject")

dlgSaveAsString = Application.GetSaveAsFilename("ABCD.txt", FileFilter:="text file (*.txt),*.txt")

If (dlgSaveAsString <> False) Then
    Set a = fs.CreateTextFile(dlgSaveAsString, True, True)
    a.writeline (kmlText)
    a.Close
End If

for more details: please check the below text and link

CreateTextFile Method
See Also    Example    Applies To    Specifics
Description
Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.
Syntax
object.CreateTextFile(filename[, overwrite[, unicode]])
The CreateTextFile method has these parts:

Part
Description
object
Required. Always the name of a FileSystemObject or Folder object.
filename
Required. String expression that identifies the file to create.
overwrite
Optional. Boolean value that indicates if an existing file can be overwritten. The value is True if the file can be overwritten; False if it can't be overwritten. If omitted, existing files are not overwritten.
unicode
Optional. Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is True if the file is created as a Unicode file; False if it's created as an ASCII file. If omitted, an ASCII file is assumed.


http://msdn.microsoft.com/en-us/library/aa265018(v=vs.60).aspx

Tuesday 21 January 2014

How to load excel data to Database using query




LOAD DATA LOCAL INFILE 'D:/MyWork/Master.csv' 
INTO TABLE Master COLUMNS TERMINATED BY ',';

Monday 20 January 2014

How to add the Created Names to Combo box in Excel using VBA

I have created the ComboBox2 in Excel Sheet.

I have created One Name Language and Need to add the Language to ComboBox.

With Sheet1.ComboBox2
    .ListFillRange = ThisWorkbook.Names("Language").RefersTo
    .ListIndex = 0
End With

Monday 13 January 2014

Copy data from one sheet to new sheet in Excel using VBA

Option Explicit

Sub NewCode()
'
' NewCode Macro
'

'
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets("Sheet1").Name = "Sheet1"
    Range("A1").Select
    ActiveSheet.Paste
End Sub

How to get the worksheets of closed workbook and how to attach to ComboBox using VBA

Sub LoadSheets(ClosedWBook As String, ComboboxObject As ComboBox)
Dim Count As Integer
'Dim sh As Worksheets
Dim c As Worksheet

Application.ScreenUpdating = False

Workbooks.Open ClosedWBook
'Set sh = GetObject(ClosedWBook).Worksheets
Count = 0
'Dim ws As Worksheet
With ComboboxObject
    .Clear
    For Each c In ActiveWorkbook.Worksheets
        .AddItem c.Name, Count
        Count = Count + 1
        .ListIndex = 0
    Next
End With

ActiveWorkbook.Close

End Sub

How to clear the data and history after clearing the Combobox while opening the workbook in VBA

While Opening the Workbook you want to clear the data and history of ComboBox.

Sub Workbook_Open()
On Error GoTo ErrorHandler
    With Sheet2
        .TextBox1.Value = Null
        .TextBox2.Value = Null
        .TextBox3.Value = Null
        .TextBox4.Value = Null
        .ComboBox1.Clear
         .ComboBox2.Clear
         .ComboBox1.ListIndex = -1
         .ComboBox2.ListIndex = -1
    End With
    Application.EnableEvents = True
ErrorHandler:
    Application.EnableEvents = False
End Sub

We have to clear the combobox to clear the items and we need to set the ListIndex=-1 then only we can able to show empty combobox

How to handle Exception Handling in Procedures and Function in VBA

   Introduction
Error handling refers to the programming practice of anticipating and coding for error conditions that may arise when your program runs. Errors in general come in three flavors: compiler errors such as undeclared variables that prevent your code from compiling; user data entry error such as a user entering a negative value where only a positive number is acceptable; and run time errors, that occur when VBA cannot correctly execute a program statement.  We will concern ourselves here only with run time errors.  Typical run time errors include attempting to access a non-existent worksheet or workbook, or attempting to divide by zero. The example code in this article will use the division by zero error (Error 11) when we want to deliberately raise an error.
Your application should make as many checks as possible during initialization to ensure that run time errors do not occur later.  In Excel, this includes ensuring that required workbooks and worksheets are present and that required names are defined.  The more checking you do before the real work of your application begins, the more stable your application will be. It is far better to detect potential error situations when your application starts up before data is change than to wait until later to encounter an error situation.
If you have no error handling code and a run time error occurs, VBA will display its standard run time error dialog box. While this may be acceptable, even desirable, in a development environment, it is not acceptable to the end user in a production environment. The goal of well designed error handling code is to anticipate potential errors, and correct them at run time or to terminate code execution in a controlled, graceful method.  Your goal should be to prevent unhandled errors from arising.
A note on terminology: Throughout this article, the term procedure should be taken to mean a SubFunction, orProperty procedure, and the term exit statement should be taken to mean Exit SubExit Function, or Exit Property.  The term end statement should be taken to mean End Sub , End Function,  End Property, or just End.    
The On Error Statement
The heart of error handling in VBA is the On Error statement. This statement instructs VBA what to do when an run time error is encountered.  The On Error statement takes three forms.
On Error Goto 0
On Error Resume Next
On Error Goto <label>:
The first form, On Error Goto 0, is the default mode in VBA.  This indicates that when a run time error occurs VBA should display its standard run time error message box, allowing you to enter the code in debug mode or to terminate the VBA program. When On Error Goto 0 is in effect, it is the same as having no enabled error handler.  Any error will cause VBA to display its standard error message box.
The second form, On Error Resume Next , is the most commonly used and misused form.  It instructs to VBA to essentially ignore the error and resume execution on the next line of code. It is very important to remember that On Error Resume Next does not in any way "fix" the error. It simply instructs VBA to continue as if no error occured. However, the error may have side effects, such as uninitialized variables or objects set to Nothing.  It is the responsibility of your code to test for an error condition and take appropriate action.  You do this by testing the value of Err.Number  and if it is not zero execute appropriate code.  For example,
    On Error Resume Next
    N = 1 / 0    ' cause an error
    If Err.Number <> 0 Then
        N = 1
    End If
This code attempts to assign the value 1 / 0 to the variable N. This is an illegal operations, so VBA will raise an error 11 -- Division By Zero -- and because we have On Error Resume Next in effect, code continues to the If statement. This statement tests the value of Err.Number  and assigns some other number to N.
The third form On Error of  is  On Error Goto <label>:which tells VBA to transfer execution to the line following the specified line label. Whenever an error occurs, code execution immediately goes to the line following the line label.  None of the code between the error and the label is executed, including any loop control statements.
    On Error Goto ErrHandler:
    N = 1 / 0    ' cause an error
    '
    ' more code
    '
    Exit Sub
    ErrHandler:
    ' error handling code
    Resume Next
    End Sub
Enabled And Active Error Handlers
An error handler is said to be enabled when an  On Error statement is executed.  Only one error handler is enabled at any given time, and VBA will behave according to the enabled error handler.  An active error handler is the code that executes when an error occurs and execution is transferred to another location via a On Error Goto <label>: statement. 
Error Handling Blocks And On Error Goto
An error handling block, also called an error handler, is a section of code to which execution is tranferred via a On Error Goto <label>:  statement. This code should be designed either to fix the problem and resume execution in the main code block or to terminate execution of the procedure. You can't use  to the On Error Goto <label>:  statement merely skip over lines. For example, the following code will not work properly:
    On Error GoTo Err1:
    Debug.Print 1 / 0
    ' more code
Err1:
    On Error GoTo Err2:
    Debug.Print 1 / 0
    ' more code
Err2:
When the first error is raised, execution transfers to the line following Err1:. The error hander is still active when the second error occurs, and therefore the second error is not trapped by the On Error statement.

The Resume Statement
The Resume statement instructs VBA to resume execution at a specified point in the code.  You can use  Resume only in an error handling block; any other use will cause an error. Moreover, Resume is the only way, aside from exiting the procedure, to get out of an error handling block. Do not use the Goto statement to direct code execution out of an error handling block.  Doing so will cause strange problems with the error handlers.
The Resume statement takes three syntactic form:
Resume
Resume Next
Resume <label>
Used alone, Resume causes execution to resume at the line of code that caused the error.  In this case you must ensure that your error handling block fixed the problem that caused the initial error. Otherwise, your code will enter an endless loop, jumping between the line of code that caused the error and the error handling block.  The following code attempts to activate a worksheet that does not exist. This causes an error (9 - Subscript Out Of Range), and the code jumps to the error handling block which creates the sheet, correcting the problem, and resumes execution at the line of code that caused the error.    On Error GoTo ErrHandler:
    Worksheets("NewSheet").Activate
    Exit Sub

    ErrHandler:
    If Err.Number = 9 Then
        ' sheet does not exist, so create it
        Worksheets.Add.Name = "NewSheet"
        ' go back to the line of code that caused the problem
        Resume
    End If

The second form of 
Resume is Resume Next . This causes code execution to resume at the line immediately following the line which caused the error.  The following code causes an error (11 - Division By Zero) when attempting to set the value of N. The error handling block assigns 1 to the variable N, and then causes execution to resume at the statement after the statement that caused the error.
    On Error GoTo ErrHandler:
    N = 1 / 0
    Debug.Print N
    Exit Sub

    ErrHandler:
    N = 1
    ' go back to the line following the error
    Resume Next


The third form of 
Resume is Resume <label>: . This causes code execution to resume at a line label. This allows you to skip a section of code if an error occurs. For example,
     On Error GoTo ErrHandler:
    N = 1 / 0
    '
    ' code that is skipped if an error occurs
    '
    Label1:
    '
    ' more code to execute
    '
    Exit Sub

    ErrHandler:
    ' go back to the line at Label1:
    Resume Label1:


All forms of the 
Resume clear or reset the Err object.
Error Handling With Multiple Procedures
Every procedure need not have a error code. When an error occurs, VBA uses the last On Error statement to direct code execution. If the code causing the error is in a procedure with an On Error statement, error handling is as described in the above section. However, if the procedure in which the error occurs does not have an error handler, VBA looks backwards through the procedure calls which lead to the erroneous code. For example if procedure A calls B and B calls C, and A is the only procedure with an error handler, if an error occurs in procedure C, code execution is immediately transferred to the error handler in procedure A, skipping the remaining code in B.
A Note Of Caution
It is tempting to deal with errors by placing an On Error Resume Next statement at the top of the procedure in order to get the code to run without raising an error.  This is very bad coding practice. Remember that using On Error Resume Next  does not fix errors.  It merely ignores them.
The Future Of Error Handling In VBA
Error handling in VB6 and VBA is based on the On Error statement, which leads to awkward code structure. Languages like C++ provide a code structure call Try/Catch that allows much more granularity and control.  At some point, Microsoft will introduce their NET framework in to Office, and when this happens, VBA programmers will have at their disposal the language features of Try/Catch/Finally code structure that VB.NET developers already enjoy.

Macro for upload button in Excel VBA

Sub Upload_Click()


    Dim dlg As FileDialog
    Dim FileSelected As String

    Set dlg = Application.FileDialog(msoFileDialogFilePicker)
    With dlg
        .title = "Select the Excelfile to import"
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Excel Files", "*.xls*", 1
        .Filters.Add "All Files", "*.*", 2
        If .Show = -1 Then
            FileSelected = .SelectedItems(1)
        Else
            Exit Sub
        End If
    End With
   
    Sheet4.TextBox1.Value = FileSelected

End Sub

Tuesday 7 January 2014

How to do stop the auto load of the controls like ComboBox when button event triggerred

My issue is:

Selecting the value form the ComboBox and performing button event, After button event triggered then it will automatically ComboBox value changing with initial value.

Solution:

Application.EnableEvents = False:

is usually used when you create a macro in the code module for a worksheet, workbook, etc, when the macro is created in response to one of Excel's events (e.g. Worksheet_Change when some one updates the worksheet).

The code has the effect of telling VBA not to respond to events that occur, so if in the example the worksheet is changed again after that code has been run, the Worksheet_Change event macro will not be run.

It is usually added in code when you have responded to (say) a change in the worksheet and your program will perform some other actions on the worksheet. If you don't set EnableEvents to False, every time your macro updates the worksheet the Worksheet_Change event macro will start again. This may result in the program doing something unexpected, but even if not it gets horribly complicated trying to work out where the program will go next.

Sunday 5 January 2014

Load Excel Combobox when the excel is opened?

This task is need to perform while opening of the workbook, So this is related to events in the workbook and code should be written in the ThisWorkBook module




Private Sub Workbook_Open()
With Sheet1.mapping
.AddItem "File to Table"
.AddItem "Table to File"
End With
End Sub

Friday 3 January 2014

how to access combo box value in the module in excel vba

Answer:

By using the below command we can able get the ComboBox value from other sheet or module.


Dim abc
abc = Sheet1.ComboBox1.SelText

How do I declare a global variable in VBA?

To use global variables, Insert New Module from VBA Project UI and declare variables using Global
Global iRaw As Integer
Global iColumn As Integer

Disable editing of text in combobox in Excel

Answer: You set the property style to 2-fmStyleDropDownList