It is very difficult to work constantly on same topic, even if you like what you are doing. You loose your focus over time. This happens most often for a developer in a multitasking environment; where you need to take care of lot of things to succeed.
The best way to trick yourself is to use a mind game. Treat every successful action as goal you score in an imaginary game. High results at the end of the day can be considered as a good accomplishment showing your victory. This will help you to increase attention to details, and help to stay focus in same way as a game player is doing during a game.
If done well it will help you focus for a lot longer. At the end of the day you count successful moves as a positive and moves you failed to do as negative. You then add them up, if the sum if positive then you win, if negative then you lose.
Saturday, October 27, 2007
Friday, October 5, 2007
How to Create a Schema.ini File Programmatically
1. Start a new project in Visual Basic 6, and save project to disk
2. Add reference to Microsoft ActiveX Data Objects 2.5 Library
3. Add button to the Form
4. Double click on button and add next code
Private Sub Command1_Click()
Dim con As New ADODB.Connection
Dim RS As ADODB.Recordset
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & _
";Extended Properties=text;"
con.Execute & _
"CREATE TABLE [TEST1.CSV] " & _
"( [Name] TEXT NULL, [MaxVolt] DOUBLE NULL)"
End Sub
6. Run project and click on a button
7. Verify that SCHEMA.INI and TEST1.CSV files were created in project folder
8. Use "DROP TABLE [TEST.CSV]" to delete TEST.CSV from SCHEMA.INI and delete TEST1.CSV file from a disk
Remarks: There is no way to update SCHEMA.INI and TEST1.CSV by using ALTER TABLE sql statement. Even if tables (files) does not contain any data, next statement "ALTER TABLE [TEST.CSV] ADD COLUMN [Name2] TEXT NULL" will raise an error "Operation not supported on a table that contains data".
2. Add reference to Microsoft ActiveX Data Objects 2.5 Library
3. Add button to the Form
4. Double click on button and add next code
Private Sub Command1_Click()
Dim con As New ADODB.Connection
Dim RS As ADODB.Recordset
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & _
";Extended Properties=text;"
con.Execute & _
"CREATE TABLE [TEST1.CSV] " & _
"( [Name] TEXT NULL, [MaxVolt] DOUBLE NULL)"
End Sub
6. Run project and click on a button
7. Verify that SCHEMA.INI and TEST1.CSV files were created in project folder
8. Use "DROP TABLE [TEST.CSV]" to delete TEST.CSV from SCHEMA.INI and delete TEST1.CSV file from a disk
Remarks: There is no way to update SCHEMA.INI and TEST1.CSV by using ALTER TABLE sql statement. Even if tables (files) does not contain any data, next statement "ALTER TABLE [TEST.CSV] ADD COLUMN [Name2] TEXT NULL" will raise an error "Operation not supported on a table that contains data".
Tuesday, October 2, 2007
Count number of lines in a project with VBScript
'
' www.pullnews.com
' Save this code as file LineCount.vbs
'
If WScript.Arguments.Count= 0 Then
MsgBox "Usage instruction:" & vbCrLf & _
"Set folder as argument, or Drag source folder and drop on vbs file"
WScript.Quit
End If
nCounter = 0
FolderName = WScript.Arguments(0)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(FolderName) Then
WScript.Echo "Invalid folder name"
Else
CheckSubfolders fso.GetFolder(FolderName)
WScript.Echo "Number of lines in all files is = " & nCounter
End If
' Subfolder recursion
Sub CheckSubfolders(thisFolder)
Dim subFolder
CountLinesInFolder thisFolder
For Each subFolder In thisFolder.SubFolders
CheckSubfolders subFolder
Next
End Sub
Sub CountLinesInFolder(thisFolder)
Const ForReading = 1
Dim File, theFile
For Each File In thisFolder.Files
Set theFile = fso.OpenTextFile(File.Path, ForReading, False)
Do While theFile.AtEndOfStream <> True
theFile.ReadLine
nCounter = nCounter + 1
Loop
theFile.Close
Next
End Sub
' www.pullnews.com
' Save this code as file LineCount.vbs
'
If WScript.Arguments.Count= 0 Then
MsgBox "Usage instruction:" & vbCrLf & _
"Set folder as argument, or Drag source folder and drop on vbs file"
WScript.Quit
End If
nCounter = 0
FolderName = WScript.Arguments(0)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(FolderName) Then
WScript.Echo "Invalid folder name"
Else
CheckSubfolders fso.GetFolder(FolderName)
WScript.Echo "Number of lines in all files is = " & nCounter
End If
' Subfolder recursion
Sub CheckSubfolders(thisFolder)
Dim subFolder
CountLinesInFolder thisFolder
For Each subFolder In thisFolder.SubFolders
CheckSubfolders subFolder
Next
End Sub
Sub CountLinesInFolder(thisFolder)
Const ForReading = 1
Dim File, theFile
For Each File In thisFolder.Files
Set theFile = fso.OpenTextFile(File.Path, ForReading, False)
Do While theFile.AtEndOfStream <> True
theFile.ReadLine
nCounter = nCounter + 1
Loop
theFile.Close
Next
End Sub
Wednesday, September 26, 2007
Import from bin64 to binary file with VBScript
'
' www.pullnews.com
' Save this code into file ImportFromBin64.vbs
'
If WScript.Arguments.Count= 0 Then
MsgBox "Usage instruction:" & vbCrLf & _
"Drag source file and drop on vbs file to process"
WScript.Quit
End If
Set fso = CreateObject("Scripting.FileSystemObject")
sInFName = WScript.Arguments(0)
sPath = fso.GetParentFolderName (WScript.ScriptFullName)
ConvertBin64ToBinary sInFName
' Convert bin64 from xml file into binary file
Sub ConvertBin64ToBinary(sInFileName)
Set xmlDoc = CreateObject("microsoft.xmldom")
xmlDoc.async = False
'Load xml doc
If xmlDoc.Load(sInFName) = False Then
MsgBox "Invalid XML request"
Else
Set oNode = xmlDoc.selectSingleNode("DATA")
sOutFName = oNode.getAttribute("FileName")
SaveBinaryData sPath & "\" & sOutFName, _
oNode.nodeTypedValue
End If
End Sub
' Save binary buffer to file
Function SaveBinaryData(FileName,ByteArray)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
'Write binary data to stream object
BinaryStream.Write ByteArray
'Save to file
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
' www.pullnews.com
' Save this code into file ImportFromBin64.vbs
'
If WScript.Arguments.Count= 0 Then
MsgBox "Usage instruction:" & vbCrLf & _
"Drag source file and drop on vbs file to process"
WScript.Quit
End If
Set fso = CreateObject("Scripting.FileSystemObject")
sInFName = WScript.Arguments(0)
sPath = fso.GetParentFolderName (WScript.ScriptFullName)
ConvertBin64ToBinary sInFName
' Convert bin64 from xml file into binary file
Sub ConvertBin64ToBinary(sInFileName)
Set xmlDoc = CreateObject("microsoft.xmldom")
xmlDoc.async = False
'Load xml doc
If xmlDoc.Load(sInFName) = False Then
MsgBox "Invalid XML request"
Else
Set oNode = xmlDoc.selectSingleNode("DATA")
sOutFName = oNode.getAttribute("FileName")
SaveBinaryData sPath & "\" & sOutFName, _
oNode.nodeTypedValue
End If
End Sub
' Save binary buffer to file
Function SaveBinaryData(FileName,ByteArray)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
'Write binary data to stream object
BinaryStream.Write ByteArray
'Save to file
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
Tuesday, September 18, 2007
Convert binary file into bin64 string with VBScript
'
' www.pullnews.com
' Save this code into file ConvertToBin64.vbs
'
If WScript.Arguments.Count= 0 Then
MsgBox "Usage instruction:" & vbCrLf & _
"Drag source file and drop on vbs file to process"
WScript.Quit
End If
Set fso = CreateObject("Scripting.FileSystemObject")
sInFName = WScript.Arguments(0)
sPath = fso.GetParentFolderName (WScript.ScriptFullName)
sOutFName = sPath & "\base64.xml"
SaveToXMLAsBin64 sInFName, sOutFName
' Save binary buffer into xml file in bin64 format
Sub SaveToXMLAsBin64(sInFileName, sOutFileName)
Set xmlDoc = CreateObject("microsoft.xmldom")
xmlDoc.async = False
'create a node
Set oElement = xmlDoc.createElement("DATA")
oElement.dataType = "bin.base64"
oElement.nodeTypedValue = ReadBinaryFile(sInFileName)
'save file name as well
oElement.setAttribute "FileName", fso.GetFileName( sInFName )
xmlDoc.appendChild oElement
'save file
xmlDoc.save sOutFileName
End Sub
' Read binary or text file into buffer
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End Function
' www.pullnews.com
' Save this code into file ConvertToBin64.vbs
'
If WScript.Arguments.Count= 0 Then
MsgBox "Usage instruction:" & vbCrLf & _
"Drag source file and drop on vbs file to process"
WScript.Quit
End If
Set fso = CreateObject("Scripting.FileSystemObject")
sInFName = WScript.Arguments(0)
sPath = fso.GetParentFolderName (WScript.ScriptFullName)
sOutFName = sPath & "\base64.xml"
SaveToXMLAsBin64 sInFName, sOutFName
' Save binary buffer into xml file in bin64 format
Sub SaveToXMLAsBin64(sInFileName, sOutFileName)
Set xmlDoc = CreateObject("microsoft.xmldom")
xmlDoc.async = False
'create a node
Set oElement = xmlDoc.createElement("DATA")
oElement.dataType = "bin.base64"
oElement.nodeTypedValue = ReadBinaryFile(sInFileName)
'save file name as well
oElement.setAttribute "FileName", fso.GetFileName( sInFName )
xmlDoc.appendChild oElement
'save file
xmlDoc.save sOutFileName
End Sub
' Read binary or text file into buffer
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End Function
Wednesday, September 12, 2007
Create WAMP server with Virtual PC
WAPM is an acronym for Web Server based on Apache, PHP and MySQL installed on Windows. Virtual PC is a free software from Microsoft, that enables you to play with out of box environments. It is assumed that Virtual PC is already installed. Than next is:
1. Install operating system, for me I do prefer of Windows 2000.
2. Simplify interaction and improve performance with Virtual PC by installing Virtual Machine Additions.
3. Absolutely necessary is to install Windows 2000 Service Pack 4.
Otherwise latest Apache installation will fail.
4. Install Internet Explorer 6 or latest FireFox. To work with local host environments.
5. Install Apache, and my choice is latest version Apache 2.2
Provide valid email address for administrator, otherwise Apache will fail to start. Create web site folder like "c:\www", and configure Apache to use it by editing httpd.conf file.
6. Install MYSQL 5.0.48, add select check box "add mysql to environment variables"
Create the database from a command line
mysqladmin -u USERNAME -p create DATABASE
Import the backup data
mysql -u USERNAME -p DATABASE < FILENAME.mysql
7. Install GUI for MySQL 1.12
8. Install PHP 5.2.3
Configure to use extentions GD2 and MySQL
9. Install PHP editor Notepad++
A. Optional is to install debugging framework like xdebug 2.0.0
Created virtual machine file could be cloned and reused with multiple development environments.
Using Pointing Device on Dell laptop will make Virtual PC consistently crash.
With MySQL 4.4.8 possible error could be shown on start of Apache - "could not locate libmysql.dll". Simple reboot of virtual system may solve the problem.
1. Install operating system, for me I do prefer of Windows 2000.
2. Simplify interaction and improve performance with Virtual PC by installing Virtual Machine Additions.
3. Absolutely necessary is to install Windows 2000 Service Pack 4.
Otherwise latest Apache installation will fail.
4. Install Internet Explorer 6 or latest FireFox. To work with local host environments.
5. Install Apache, and my choice is latest version Apache 2.2
Provide valid email address for administrator, otherwise Apache will fail to start. Create web site folder like "c:\www", and configure Apache to use it by editing httpd.conf file.
6. Install MYSQL 5.0.48, add select check box "add mysql to environment variables"
Create the database from a command line
mysqladmin -u USERNAME -p create DATABASE
Import the backup data
mysql -u USERNAME -p DATABASE < FILENAME.mysql
7. Install GUI for MySQL 1.12
8. Install PHP 5.2.3
Configure to use extentions GD2 and MySQL
9. Install PHP editor Notepad++
A. Optional is to install debugging framework like xdebug 2.0.0
Created virtual machine file could be cloned and reused with multiple development environments.
Using Pointing Device on Dell laptop will make Virtual PC consistently crash.
With MySQL 4.4.8 possible error could be shown on start of Apache - "could not locate libmysql.dll". Simple reboot of virtual system may solve the problem.
Thursday, September 6, 2007
Remarks about Virtual Server 2005
There are a few thing that user has to know when running Virtual Server 2005 R2 SP1
1. To enable file sharing is required to share folder on Virtual Machine drive. That is different than use of Share Folders in Virtual PC.
2. There is annoying laud beep sound every time when an operating system event occurs in Virtual Machine. To disable this use "How to turn off the beep sound in a virtual machine in Virtual Server 2005" article from http://support.microsoft.com/kb/838671
If Virtual Server is already ON the best choice is to use command prompt and execute next command:
net stop beep
1. To enable file sharing is required to share folder on Virtual Machine drive. That is different than use of Share Folders in Virtual PC.
2. There is annoying laud beep sound every time when an operating system event occurs in Virtual Machine. To disable this use "How to turn off the beep sound in a virtual machine in Virtual Server 2005" article from http://support.microsoft.com/kb/838671
If Virtual Server is already ON the best choice is to use command prompt and execute next command:
net stop beep
Subscribe to:
Posts (Atom)