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
Subscribe to:
Posts (Atom)