.NET walkabout
posts - 11, comments - 18, trackbacks - 0

Friday, September 25, 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 @ Friday, September 25, 2009 12:51 PM | Feedback (0) | Filed Under [ Sicurezza ]

Friday, May 8, 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 @ Friday, May 8, 2009 9:44 AM | Feedback (1) | Filed Under [ Visual Basic VBA VBA ]

Friday, March 27, 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 @ Friday, March 27, 2009 11:40 AM | Feedback (0) | Filed Under [ Visual Basic VBA ]

Monday, November 10, 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 @ Monday, November 10, 2008 10:09 PM | Feedback (0) | Filed Under [ VBA ]

Monday, October 20, 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 @ Monday, October 20, 2008 10:42 PM | Feedback (0) | Filed Under [ VBA ]

Wednesday, April 23, 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 @ Wednesday, April 23, 2008 8:48 PM | Feedback (0) | Filed Under [ T-SQL Oracle MySQL ]

Thursday, November 15, 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 @ Thursday, November 15, 2007 8:55 AM | Feedback (9) | Filed Under [ T-SQL ]

Sunday, October 7, 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 @ Sunday, October 7, 2007 8:00 PM | Feedback (0) | Filed Under [ Visual Basic OLEDB ]

Sunday, September 2, 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 @ Sunday, September 2, 2007 9:54 PM | Feedback (4) | Filed Under [ ASP.NET ShowModalDialog ]

Monday, August 27, 2007

Running custom VbScript code from asp

Running custom VbScript code from asp

I was in the need to run some custom VbScript code from an asp page, so I went through the problem and found a very simple solution.
A common solution is to use the Microsoft ScriptControl.
Here is a very simple example running a piece of code stored in a text file.



dim sFile : sFile = ""

= LoadFile("MyCustomScript.txt")

if len(sFile) > 0 then
"The result is: " & ExecScript(sFile)
end if

Function ExecScript(sScript)

dim sc
'Create the Script Control object
        set sc = server.CreateObject("scriptcontrol")
= false
'add the custom script to the ScripContro object
        sc.AddCode sScript
'run the code and evaluate the result of the "CustomScript" function
        ExecScript = sc.Eval("CustomScript")
set sc = nothing

End Function

Function LoadFile(sFileName)
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim objTextStream
dim strFileName
dim lsTemp

= server.MapPath(sFileName)
const fsoForReading = 1

If objFSO.FileExists(strFileName) then
'The file exists, so open it and output its contents
        Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
=  vbNullString & objTextStream.ReadAll & vbNullString
Set objTextStream = Nothing
'The file did not exist
        Response.Write strFileName & " was not found."
End If

'Clean up
    Set objFSO = Nothing
= lsTemp
end function



function CustomScript()
'Let's calculate the area of a rectangle
    dim dHeight : dHeight = 10
dim dWidth : dWidth = 20
= cstr(dHeight * dWidth)
end function

This is a very easy example of how to use the Microsoft ScriptControl in an asp page.
A more realistic task would be, for example, store the script in a database, get the scripts from there and run 'em like exposed above.

posted @ Monday, August 27, 2007 8:25 PM | Feedback (3) | Filed Under [ ASP VbScript ]

Powered by:
Powered By Subtext Powered By ASP.NET