Friday, September 18, 2009

ClickOnce bug in VB.Net 2008 Express

My memory getting shorter.
ClickOnce doesn't work in VB.net 2008 Express.
The fix: Install Visual Web Developer 2008 and it will.

Still funniest on YouTube: Starwars Kid

Tuesday, September 08, 2009

Cannot open or convert an Access 97 or Access 2000 database in Access 2002, in Access 2003, or in Access 2007

Thank you Microsoft for making my life a mess.
Having old applications running Access 97 DBs isn't fun. After change computer it wasn't possible to view the databases in Access 2003 anymore (Applications open DBs without problem). The best part is the Error message: it says the databases aren't in Access format or it might be corrupt. Hey, YOU made Access97 remember?
Finally after a couple of hours searching the answers for my call for help was answered.

regsvr32 "C:\Program Files\Common Files\Microsoft Shared\DAO\DAO360.DLL"
regsvr32 "c:\WINDOWS\system32\msrd3x40.dll"

How hard can it be?
Answer found at: IwillNeverUseAccessAgainIwillNeverUse...

Wednesday, September 02, 2009

I'm been working on a CodeGenerator that creates code for a dll. Doing so I was in need for a Variable Name validator so the created code doesn't contain invalid variables or enums.

This is the function I created:
' Returns True if variable name is valid.
Function ValidateVariable(ByVal inData As String) As Boolean
Dim VbKeyWords() As String = {"AddHandler", "AddressOf", "Alias", "And", "AndAlso", "Ansi", "As", "Assembly", "Auto", "Binary", "Boolean", "ByRef", "Byte", "ByVal", "Call", "Case", "Catch", "CBool", "CByte", "CChar", "CDate", "CDbl", "CDec", "Char", "CInt", "Class", "CLng", "CObj", "Compare", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt", "CULng", "CUShort", "Custom", "Date", "Decimal", "Declare", "Default", "Delegate", "Dim", "DirectCast", "Do", "Double", "Each", "Else", "ElseIf", "End", "EndIf", "Enum", "Erase", "Error", "Event", "Exit", "Explicit", "ExternalSource", "FALSE", "Finally", "For", "Friend", "Function", "Get", "GetType", "Global", "GoSub", "GoTo", "Handles", "If", "Implements", "Imports", "In", "Inherits", "Integer", "Interface", "Is", "IsFalse", "IsNot", "IsTrue", "Let", "Lib", "Like", "Long", "Loop", "Me", "Mid", "Mod", "Module", "MustInherit", "MustOverride", "MyBase", "MyClass", "Namespace", "Narrowing", "New", "Next", "Not", "Nothing", "NotInheritable", "NotOverridable", "Object", "Of", "Off", "On", "Operator", "Option", "Optional", "Or", "OrElse", "Overloads", "Overridable", "Overrides", "ParamArray", "Partial", "Preserve", "Private", "Property", "Protected", "Public", "RaiseEvent", "ReadOnly", "ReDim", "Region", "REM", "RemoveHandler", "Resume", "Return", "SByte", "Select", "Set", "Shadows", "Shared", "Short", "Single", "Static", "Step", "Stop", "Strict", "String", "Structure", "Sub", "SyncLock", "Text", "Then", "Throw", "To", "True", "Try", "TryCast", "TypeOf", "UInteger", "ULong", "Unicode", "Until", "UShort", "Using", "Variant", "Wend", "When", "While", "Widening", "With", "WithEvents", "WriteOnly", "Xor"}

If Len(inData) = 0 Then Return False 'Empty string


' Chk if 1st character is a numeric
Select Case inData.Chars(0)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
' Not OK
Return False
End Select


' Chk for allowed characters _ 0-1, a-z, A-Z
Dim i As Integer
For i = 0 To Len(inData) - 1
Select Case Asc(inData.Chars(i))
Case 48 To 57, 65 To 90, 97 To 122 ' 0-9, A-Z, a-z
'OK
Case 95 '_
' Ok With _ but not only as _
If inData.Length = 1 Then Return False
Case Else
Return False
End Select

' Chk for Vb KeyWords
Dim j As Integer
Dim txt As String = LCase(inData)
For j = 0 To UBound(VbKeyWords)
' chk agains Keywords
If txt = LCase(VbKeyWords(j)) Then
Return False
End If
Next
Next
Return True

End Function

Thursday, August 27, 2009

C# tutorial for VB programmers

I've been doing some C# programming lately. I came across some difference from VB.net

Random Values:
ushort x1 = 0;
Random r = new Random();
x1=(ushort)r.Next(0,5);
will give a number between 0 and 5 in x1.

Typecasting:
In the example above r will return a int, to convert it to ushort add (ushort) before.

Passing Optional variables:
C# doesn't support Optional variables.
VB code:
Sub MySub(x as integer, Optional n as integer=33)
' n will be 33 if not set when sub is called.
End Sub
In C# this isn't supported, you will have to Overload the sub instead( = more code).



To get help convtering VB -> C# or C# -> VB there is a good site www.developerfusion.com/tools/convert/vb-to-csharp/

Or you can write you code using SharpDevelopment to convert between VB, C# and Boo.

Tuesday, July 07, 2009

vb.net Radiobutton TabIndex problem

I spend 8 hours trying to understand why my dynamically GUI in VB2005 didn't work as expected if I selected a radiobutton ctrl (On/Off) it would set it to On (tabindex=0 for the On button).
If I had more than one (ON/Off) button created it would only set the first to On.

Its due to that VB set focus on the ctrl with tabindex=0 and if the radiobutton get focus it will generate a CheckedChanged event!
Made the same test in VB6 here it works as expected, if you got 2 radiobuttons on a form the on checked will get the focus and not the first in tabindex.

Workaround: Add a button to the form, set tabindex=0, height=1 and width=1.
Now when the form is created the focus will be on the invisible button.

Test the bug:
Create a form with 2 radiobuttons Rb1 and Rb2, check Rb2 radiobutton.
Run the program, now radiobutton Rb1 will be Checked instead of Rb2.

Monday, June 22, 2009

My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData bug

Vb.net (2005) have a nice function to get the CurrentUser/ApplicationData directory,
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
It will return a string like:
"C:\Documents and Settings\TheUser\Application Data\TheCompany\TheProduct\TheFileVersion"

BUT
You will not get same directory if the application is installed using ClickOne deployment!
Then it will return something like:
"C:\Documents and Settings\TheUser\Local Settings\Apps\2.0\
Data\Z5EKHRYM.NA38XHZG83D.VVDcanw..tion_21e
42ebf29780e48_0000.003c_10438657c4e73ebc\Data"

And if your upgrade your application using the ClickOne then you will get another directory
for that version of your application.
So stored files or data for your application will not be found.

Work around:
Use System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)
that returns "C:\Documents and Settings\TheUser\Application Data".
Then Add "\TheCompany\TheProduct\"

Code:
Public LocalAppDataDir As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + _
"\TheCompany\TheProduct"

' Also run this to create the directory if it doesn't exists:
' Determine whether the directory exists.
If Directory.Exists(LocalAppDataDir) = False Then
Console.WriteLine("Create Dir {0}.", LocalAppDataDir)
' Try to create the directory.
Dim di As DirectoryInfo = Directory.CreateDirectory(LocalAppDataDir)
Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(LocalAppDataDir))
End If

Sunday, June 07, 2009

Sqlite database

Have been using Sqlite now with vb.net for a while, a nice experience I can say.
Here are some useful links.
Sqlite Database homepage
Using Sqlite in vb.net fr

Sqlite Administrator Database editor.

Thursday, May 07, 2009

vb.net how to set Structures and Enum global

In a module you have declared a Structure or Enum that you will use through out a project.
Module Module1
Public Structure dummy
Dim i As Integer
Dim s As String
End Structure
End Module
But you can't, you will get an error if you declare following in an other Form
Dim fi as dummy; will give an error looking something like this:
Error 6 'fi' cannot expose type 'Module1.dummy' outside the project through class 'Form1'.

Fix:
Declare Module Module1 as Friend Or Public.
Code:
Public Module Module1
Public Structure dummy
Dim i As Integer
Dim s As String
End Structure
End Module

Saturday, May 02, 2009

VB.Net IsDisposed

I found the simple solution for my VB6 habits.
Open and closing a Form multiple time didn't require any special in VB6,
in VB.Net when you close the Form2 it will be disposed, so check if it IsDisposed
to recreate it. See some coding below


Public Class Form1
Dim frm2 As New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If frm2.IsDisposed Then
' Create it again
frm2 = New Form2
End If
frm2.Show()
End Sub
End Class

Wednesday, January 28, 2009

Google Video

I made my first attempt to add a video to video.google.com

Hard Drive Failure Symphony

MySQL to MariaDB

 Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...