Feb 25, 2014

Math library in Java ME

Math.round() is not available in J2ME.
So, it's hard to round a double.

Jan 15, 2014

VB Script

I've needed to access an Access file from an html file. I did could do this using VBScript. It is running very well with Internet Explorer and could be a solutions in Corporatist offices wher security level is too paranoic.

Now I'm working with vbscripts. I use it to generate local xml files. Those xml files I use  to keep data from Access files to be easier to read in my network. The answer of my small app (.hta file) is much faster then if I read straight from MS Access file.

So, I used following code to generate a new .xml file:

<script type='text/vbscript'> 
        Set oFS = CreateObject("Scripting.FileSystemObject") 
           Const strXmlFile = "Documents.xml" 
           Set objXMLFile = oFS.OpenTextFile(strXmlFile, 2, True, 0) 
            objXMLFile.WriteLine "" 
            objXMLFile.WriteLine ""'" href=""Documents.xsl""?>" 
            objXMLFile.WriteLine "" 
           'Set myFolder = oFS.GetFolder("Documents") 
            'For Each File In myFolder.Files 
            'FileLast = File.DateLastModified 
            'FileMod = DateDiff("d", FileLast, Now) 
            '    If FileMod < 5 Then 
             'Corporate = File.Name 
             'myDate = Split(FileLast,"/") 
             'myYear = Left(myDate(2),4) 
             'myMonth = myDate(0) 
             'myURL = "Whatever your URL is" 
             'Download = "Wherever your download site is" 
             'Call CreateXML(Corporate,myYear,myMonth,myURL,Download) 
             Call CreateXML("Corporatia","myYear","myMonth","myURL","Download") 
              
                'End If 
            'Next 
           'This next call will run once the "CreateXML" has finished. 
           Call CloseXML() 
           Function CreateXML(Corporate,myYear,myMonth,myURL,Download) 
            objXMLFile.WriteLine vbTab & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & Corporate & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & myYear & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & myMonth & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & myURL & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & Download & "" 
            objXMLFile.WriteLine vbTab & "
"            End Function 
           Function CloseXML() 
            objXMLFile.WriteLine "
"              wscript.echo "Completed XML Creation" 
           End Function 

          </script>

VBA Excel - Syntax for "for"

Syntax for "for":


For i = 4 To 2000 
    ' do something                
Next i 

MS Access - open form in another database

If you want to open a new form from another Access file you can use following code:

Public Sub OpenForeignForm()  
 Dim appAccess As Access.Application  
 Set appAccess = CreateObject("Access.Application")  
 appAccess.OpenCurrentDatabase "C:\MyPath\DataBaseName2.mdb"  
 appAccess.DoCmd.OpenForm "FormName"  
 Set appAccess = Nothing 
End Sub 

Dec 15, 2013

VBA Excel

Cells, Ranges, Columns and Rows in VBA for Excel

Many beginners start their career using Cells. For example:
Cells(1,1).Select means (row 1, column 1) and is the same thing as Range("A1").Select and
Cells(14,31).Select
means (row 14, column 31) and is the same as Range("AE14").Select.
We strongly recommend that you use Range instead of Cells to work with cells and groups of cells. It makes your sentences much clearer and you are not forced to remember that column AE is column 31.
The only time that you will use Cells is when you want to select all the cells of a worksheet. For example:
Cells.Select
To select all cells and then empty all cells of values or formulas  you will use:
Cells.ClearContents

Range

To select a single cell you will write:
Range
("A1").Select
To select a set of contiguous cells you will use the colon and write:Range("A1:G5").Select
To select a set of non contiguous cells you will use the comma and write:Range("A1,A5,B4").Select
To select a set of non contiguous cells and a range you will use both the colon and the comma:Range("A1,A5,B4:B8").Select

Offset

The Offset property is the one that you will use the most with Range to move around the sheet.
To move one cell down (from B2 to B3): Range("B2").Offset(1,0).Select
To move one cell to the right (from B2 to C2): Range("B2").Offset(0,1).Select
To move one cell up  (from B2 to B1): Range("B2").Offset(-1,0).Select
To move one cell to the left  (from B2 to A2): Range("B2").Offset(0,-1).Select
To move one cell down from the selected cell:
ActiveCell.Offset(1,0).Select
As you notice the first argument between the parentheses for Offset is the number of rows and the second one is the number of columns. So to move from A1 to G6 you will need:
Range("A1").Offset(5,6).Select
You will use very often the following piece of code . It selects a cell PLUS 4 more to the right to be copied/pasted somewhere else:
Range(ActiveCell,ActiveCell.Offset(0,4)).Copy
Notice the comma after the first
ActiveCell and the double closing parentheses before the Copy.