lunedì 10 novembre 2008
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 l compilazione del progetto dall'interno dell'ambiente di sviluppo et voilà... Les jeux sont fait!
lunedì 20 ottobre 2008
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)
Range(sRow).Select
On Error GoTo 0
CropSelection = True
Exit Function
CropSelection_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CropSelection of Modulo Modulo1"
End Function
mercoledì 23 aprile 2008
SQL Server:
SELECT TOP 10 product, descr, email
FROM products
ORACLE:
SELECT product, descr, email
FROM products
WHERE ROWNUM <= 10
MySQL:
SELECT product, descr, email
FROM products
LIMIT 10
giovedì 15 novembre 2007
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
BEGIN
declare @curSeq varchar(16)
SELECT @curSeq = ISNULL(REPLICATE(@PadWith, @PadLength - len(ISNULL(@Seq ,0))), '') + @Seq
RETURN @curSeq
END
Testing the function:
SELECT dbo.PadString ('8', '0', 5)
SELECT dbo.PadString ('abc', '*', 12)
SELECT dbo.PadString ('abc', '0', 7)
Here are the results:
----------------
00008
(1 row(s) affected)
----------------
*********abc
(1 row(s) affected)
----------------
0000abc
(1 row(s) affected)
---------------------------------------------------------
TAGS: sql server format string pad left
martedì 16 ottobre 2007
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.
ToHtml.com 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

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 Chami.com
"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 manoli.net
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.

domenica 7 ottobre 2007
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
Test.txt
a;1;Test
b;2;Test
c;3;Test
d;4;Test
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")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\;Extended Properties=""text;HDR=No;FMT=Delimited'"""
Set rs = CreateObject("ADODB.Recordset")
rs.Open "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
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
cn.Close
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'"""
domenica 2 settembre 2007
Here is a simple working example explaining how to use ShowModalDialog and asp.net 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
lunedì 27 agosto 2007
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.
default.asp
<%@language=VBSCRIPT%>
<%
dim sFile : sFile = ""
sFile = LoadFile("MyCustomScript.txt")
if len(sFile) > 0 then
Response.Write "The result is: " & ExecScript(sFile)
end if
Function ExecScript(sScript)
dim sc
'Create the Script Control object
set sc = server.CreateObject("scriptcontrol")
sc.Language = "VBSCRIPT"
sc.UseSafeSubset = false
sc.Reset
'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
strFileName = 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)
lsTemp= vbNullString & objTextStream.ReadAll & vbNullString
objTextStream.Close
Set objTextStream = Nothing
Else
'The file did not exist
Response.Write strFileName & " was not found."
End If
'Clean up
Set objFSO = Nothing
LoadFile = lsTemp
end function
%>
MyCustomScript.txt
function CustomScript()
'Let's calculate the area of a rectangle
dim dHeight : dHeight = 10
dim dWidth : dWidth = 20
CustomScript = 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.
mercoledì 22 agosto 2007
Whenever you use a postback in a modal window, magically Internet Explorer fires the event in a new page.
To avoid Internet Explorer to act like that, just add...
<base target="_self" />
... wherever you want, just before the HTML Tag or simply in between the HEAD tag of your HTML page.