.NET walkabout
posts - 12, comments - 21, trackbacks - 0

My Links

News - Two steps ahead

↑ Grab this Headline Animator

Tag Cloud


Post Categories

Code repository websites


venerdì 25 settembre 2009

L'incredibile vulnerabilità di SVN

C'è di che ridere (e sto ridendo parecchio), ma la cosa è MOLTO seria.

SmashingMagazine spiega per filo e per segno quale è il problema che affligge SVN e come questo generi non pochi grattacapi a coloro i quali non hanno pensato a come proteggersi.

Della serie: cerchi di blindare tutta la casa, ma hai dimenticato che la porta principale va SEMPRE chiusa a chiave.

posted @ venerdì 25 settembre 2009 12.51 | Feedback (0) | Filed Under [ Sicurezza ]

venerdì 8 maggio 2009

Editare file di Excel 2007 da VBA o VB6

Interessante articolo su come editare il formato OPENXML di Excel 2007 utilizzando il buon vecchio VBA o, per estensione, il sempre valido Visual basic 6.


posted @ venerdì 8 maggio 2009 9.44 | Feedback (1) | Filed Under [ Visual Basic VBA VBA ]

venerdì 27 marzo 2009

How to zip a file using Visual Basic 6 and the Windows Shell

When it was a matter of zipping a file, I always choosed the easy way: find a thirdy part activex or dll which could do the job for me.

This time, I wanted to find my way to zip a file using Visual Basic 6 (or Visual Basic for Application - aka VBA) and the windows shell. The consderation came from the fact that, since Windows XP,  the support of zipping-unizzping files is a native feature of the OS.

After a long search and multiple fixes, I finally came up with a stable solution which I'm going to quickly explain and post right here. The source code is a mix of pieces of code collected here and there. the only att

Attached to the post it's a zip file containing a working example. It zips the files contained in the testFolder directory.

Click here to download the zip.

I'm going to post just the clsZip class I used to support my zipping project.

Option Explicit

Private objShell As Object
Private mvarZipFileName As String


Private Sub Class_Initialize()
Set objShell = CreateObject("Shell.Application")
End Sub

Private Sub Class_Terminate()
Set objShell = Nothing
End Sub

Public Property Let ZipFileName(ByVal vData As String)
    mvarZipFileName = vData
End Property

Public Property Get ZipFileName() As String
    ZipFileName = mvarZipFileName
End Property

Private Sub CreateEmptyZip(sPath)

    Dim strZIPHeader As String
    Dim fso As Object
    strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, vbNullChar)
    Set fso = CreateObject("Scripting.FileSystemObject")
    With fso
        .CreateTextFile(sPath).Write strZIPHeader
    End With
    Set fso = Nothing
End Sub

Public Function AddFilesToZip(sFileNames() As String) As Boolean

Dim i As Long
Dim iCount As Long

    On Error GoTo AddFilesToZip_Error
    CreateEmptyZip mvarZipFileName
    On Error Resume Next
    For i = LBound(sFileNames) To UBound(sFileNames)
        objShell.Namespace("" & mvarZipFileName).CopyHere "" & sFileNames(i), FOF_NOCONFIRMATION
        iCount = objShell.Namespace("" & mvarZipFileName).items.Count
        Do Until iCount = i + 1
            Sleep 100
            iCount = objShell.Namespace("" & mvarZipFileName).items.Count
    On Error GoTo 0
    Exit Function


    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure AddFilesToZip of Modulo di classe clsZip"

End Function
Public Function UnzipToFolder(sFolderName As String) As Boolean

    objShell.Namespace("" & sFolderName).CopyHere objShell.Namespace("" & mvarZipFileName).items

End Function

Technorati tags: , , ,

posted @ venerdì 27 marzo 2009 11.40 | Feedback (0) | Filed Under [ Visual Basic VBA ]

lunedì 10 novembre 2008

Excel: convenzione di chiamata dll non valida

Una mattina persa a cercare di capire quale potessere essere il mistero legato alla convenzione di chiamata dll non valida.

La soluzione, come spesso accade, sta nel cercare di arrivare all'unica verità possibile, ovvero che il cucchiaio non esiste... Esportare tutti i moduli bas dal progetto vba, eliminarli e reinserirli. Eseguire la compilazione del progetto dall'interno dell'ambiente di sviluppo et voilà... Les jeux sont fait!

posted @ lunedì 10 novembre 2008 22.09 | Feedback (0) | Filed Under [ VBA ]

lunedì 20 ottobre 2008

Contrarre una selection (range) in Excel

Semplice funzione per Excel che consente di contrarre di n righe una selection (per intenderci, un range di celle) .

Risulta utile anche per spostarsi in su od in giù di n righe se la selection corrente è una singola cella.

Function CropSelection(Rows As Long) As Boolean
Dim sSelection As String
Dim iDollarPosition As Long
Dim sRow As String
Dim lRow As Long

    On Error GoTo CropSelection_Error

    sSelection = Selection.Address()
    iDollarPosition = InStrRev(sSelection, "$")
    sRow = Mid(sSelection, iDollarPosition + 1)
    lRow = CLng(sRow) - Rows
    sRow = Mid(sSelection, 1, iDollarPosition - 1) & CStr(lRow)

    On Error GoTo 0
    CropSelection = True
    Exit Function


    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CropSelection of Modulo Modulo1"

End Function

posted @ lunedì 20 ottobre 2008 22.42 | Feedback (0) | Filed Under [ VBA ]

mercoledì 23 aprile 2008

Clausola TOP n

SQL Server:
SELECT TOP 10 product, descr, email
FROM products
SELECT product, descr, email
FROM products

SELECT product, descr, email
FROM products

posted @ mercoledì 23 aprile 2008 20.48 | Feedback (0) | Filed Under [ T-SQL Oracle MySQL ]

giovedì 15 novembre 2007

How to format a value using T-SQL: pad left

SQL server has no built-in format functions. Here is a user defined function which left-pad a varchar value with a variable length string.

CREATE FUNCTION [dbo].[PadString]

(@Seq varchar(16),
@PadWith char(1),
@PadLength int

RETURNS varchar(16) AS


declare @curSeq varchar(16)

SELECT @curSeq = ISNULL(REPLICATE(@PadWith, @PadLength - len(ISNULL(@Seq ,0))), '') + @Seq

RETURN @curSeq


Testing the function:

SELECT dbo.PadString ('8', '0', 5)

SELECT dbo.PadString ('abc', '*', 12)

SELECT dbo.PadString ('abc', '0', 7)


Here are the results:


(1 row(s) affected)


(1 row(s) affected)


(1 row(s) affected)


TAGS: sql server format string pad left

posted @ giovedì 15 novembre 2007 8.55 | Feedback (9) | Filed Under [ T-SQL ]

martedì 16 ottobre 2007

10 source code highlighters

While writing your new post to your blog, you need to highlight a piece of source code. Now, what? Here is a list of 10 online services which could save you. by Oleg Parashchenko
The most "usable" online code highlighter service, supports a LOT of different languages including SQL, scripts, ancient language (*asm) and newest (.NET)


Quick HighLighter by Veign
A very easy to use website, supports a lot of languages, including PHP, ASP, VB.NET, C#, Ruby and "robots.txt" <--LOL

Quick Highlighter

CodeColor by Asp.NET Resources
It has not many languages to work with and I don't like the idea to have a popoup window with the final highlighted code. It works pretty good though.


GeSHi by Nigel McNie
As written there... "Support for a wide range of popular languages, Easy to add a new language for highlighting, Highly customisable output formats". Excellent idea the option to setup your own highlighiting rules. A must have if you are the owner of a phpbb forum or a Mambo website.


ColorCode by Thomas Johansen hosted @ CsharpFriends by Salman Ahmed
Another very easy interface, altough with no options at all. It just supports C#, VB.NET, J# and T-SQL.


Pygments by Pocoo
Sntax highlighting engine written in Python. It supports many different languages. You can store your pieces of highlighted code for later use. Nice and clean interface. Does not support Visual Basic (which is like incredible)


Code Colorizer by
"It can convert your ASP, C/C++, Clipper, Delphi/Pascal, HTML, Java, JavaScript and Visual Basic source code to colorized (syntax highlighted) HTML documents". Very simple interface with few languages supported.


Code Format by
Another simple interface. It supports just C#, vb, aspx, html, xml, t.-sql and msh. The output conforms to the HTML 4.01 specification

ActiPro CodeHighlighter by ActiPro Software
This is the one I like more, not because it has something better than the others, but just because, in my eyes, is the easyer one use.

Syntax Highlighter for Microsoft Live Writer by xKnown
This is very very very cool! It's a plugin for Windows Live Writer which allow us to write highlighted source code directly within Windows Live Writer! The plugin can be downloaded @codeplex and Windows Live Writer can be downloaded here.
What's so cool about that? WLW allows you to post new articles directly to your blog (even Subtext!) and there is no need to use your blog platform interface. The plugin allows you to quickly insert an highlighted piece of code of your choice.

posted @ martedì 16 ottobre 2007 3.16 | Feedback (3) | Filed Under [ ASP.NET ASP VbScript Visual Basic ]

domenica 7 ottobre 2007

OLEDB and text files

This is a very quick example about OLEDB and read a text (.txt) file using Visual Basic 6.
The text file must be formatted as a simple CSV file with a field separator. Something like this



Supposing "Test.Txt" is stored in the root of the C: harddrive, the code will look like


Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CreateObject("ADODB.Connection")
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\;Extended Properties=""text;HDR=No;FMT=Delimited'"""
Set rs = CreateObject("ADODB.Recordset")
"SELECT * FROM Test.txt", cn, 0, 1, 1
While Not rs.EOF
    Debug.Print rs.Fields(
0).Value, rs.Fields(1).Value, rs.Fields(2).Value
Set rs = Nothing
Set cn = Nothing


Take a look to the connection string

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\;Extended Properties=""text;HDR=No;FMT=Delimited'"""

the Data Source=c:\; is the key. If you plan to store your text file in a different folde, let's say "c:\documents and settings\Auser\Documents\myTestFiles\", you are required to change the connection string this way:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\documents and settings\Auser\Documents\myTestFiles\;Extended Properties=""text;HDR=No;FMT=Delimited'"""

posted @ domenica 7 ottobre 2007 20.00 | Feedback (0) | Filed Under [ Visual Basic OLEDB ]

domenica 2 settembre 2007

ShowModalDialog and ASP.NET, a full working example

Here is a simple working example explaining how to use ShowModalDialog and with Visual Studio 2005.

Start with default.aspx, which has a single button. Once clicked, it will popup a modal window which will show a single button labeled "Close me!".

The postback will redirect the user to a new page, whose purpose is to close the modal window and return the string value '1' which will be evalueted by the parent window using the returnValue property.

If returnValue is '1' then the form will be submitted to itself, just to show how to reuse local values and force a timer label to refresh

Download the example from here

posted @ domenica 2 settembre 2007 21.54 | Feedback (4) | Filed Under [ ASP.NET ShowModalDialog ]

Powered by: