Create new table for Pervasive database with Visual Basic 6.0

posted on 29 Aug 2008 11:35 by computertips  in ProgrammingTips

' Pervasive Database
Private Sub My_CREATETABLE()
    ' ITEMSTOCK
    sSQL = "CREATE TABLE """ & "ITEMSTOCK" & """(" & Chr(13)   ' table name
    sSQL = sSQL & Chr(34) & "DETAILNUM" & Chr(34) & " SMALLINT NOT NULL," & Chr(13)
    sSQL = sSQL & Chr(34) & "DOCTYPE" & Chr(34) & " SMALLINT," & Chr(13)
    sSQL = sSQL & Chr(34) & "DOCNUM" & Chr(34) & " CHAR(22)," & Chr(13)
    sSQL = sSQL & Chr(34) & "ITEMCODE" & Chr(34) & " CHAR(24)," & Chr(13)
    sSQL = sSQL & Chr(34) & "AUDTDATE" & Chr(34) & " DECIMAL(19,0)," & Chr(13)
    sSQL = sSQL & Chr(34) & "DAY" & Chr(34) & " DECIMAL(19,0)," & Chr(13)
    sSQL = sSQL & Chr(34) & "MONTH" & Chr(34) & " DECIMAL(19,0)," & Chr(13)
    sSQL = sSQL & Chr(34) & "YEAR" & Chr(34) & " DECIMAL(19,0)," & Chr(13)
    sSQL = sSQL & Chr(34) & "VENDOR" & Chr(34) & " CHAR(60)," & Chr(13)
    sSQL = sSQL & Chr(34) & "CUSTOMER" & Chr(34) & " CHAR(60)," & Chr(13)
    sSQL = sSQL & Chr(34) & "UNITCOSTIN" & Chr(34) & " DECIMAL(19,4)," & Chr(13)
    sSQL = sSQL & Chr(34) & "UNITCOSTOUT" & Chr(34) & " DECIMAL(19,4)," & Chr(13)
    sSQL = sSQL & Chr(34) & "QUANTITYIN" & Chr(34) & " DECIMAL(19,4)," & Chr(13)
    sSQL = sSQL & Chr(34) & "QUANTITYOUT" & Chr(34) & " DECIMAL(19,4)," & Chr(13)
    sSQL = sSQL & Chr(34) & "QTYBALANCE" & Chr(34) & " DECIMAL(19,4)," & Chr(13)
    sSQL = sSQL & Chr(34) & "QTYOPENINGBALANCE" & Chr(34) & " DECIMAL(19,4)," & Chr(13)
    sSQL = sSQL & Chr(34) & "REMARK" & Chr(34) & " CHAR(60)," & Chr(13)
    sSQL = sSQL & "PRIMARY KEY (" & Chr(34) & "DETAILNUM" & Chr(34) & ")" & Chr(13)
    sSQL = sSQL & ");" & Chr(13)
    sSQL = sSQL & "CREATE UNIQUE NOT MODIFIABLE INDEX " & Chr(34) & "PK_DETAILNUM" & Chr(34) & _
    " ON " & Chr(34) & "ITEMSTOCK" & Chr(34) & "(" & Chr(34) & "DETAILNUM" & Chr(34) & ");"

    ' ADBO Connection Execute
    cnn.CommandTimeout = 300
    cnn.Execute sSQL

Show ODBC name to ComboBox Control with Visual Basic 6.0

posted on 29 Aug 2008 11:24 by computertips  in ProgrammingTips

Private Function GetKeyInfo(ByVal section As Long, ByVal key_name As String, ByVal indent As Integer) As String
Dim subkeys As Collection
Dim subkey_values As Collection
Dim subkey_num As Integer
Dim subkey_name As String
Dim subkey_value As String
Dim length As Long
Dim hKey As Long
Dim txt As String
Dim subkey_txt As String
Dim value_num As Long
Dim value_name_len As Long
Dim value_name As String
Dim reserved As Long
Dim value_type As Long
Dim value_string As String
Dim value_data(1 To 1024) As Byte
Dim value_data_len As Long
Dim i As Integer

    Set subkeys = New Collection
    Set subkey_values = New Collection
   
    ' Open the key.
    If RegOpenKeyEx(section, _
        key_name, _
        0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS _
    Then
        MsgBox "Error opening key."
        Exit Function
    End If

    ' Enumerate the key's values.
    value_num = 0
    k = 0
    Do
        value_name_len = 1024
        value_name = Space$(value_name_len)
        value_data_len = 1024

        If RegEnumValue(hKey, value_num, _
            value_name, value_name_len, 0, _
            value_type, value_data(1), value_data_len) _
                <> ERROR_SUCCESS Then Exit Do

        value_name = Left$(value_name, value_name_len)

        Select Case value_type
            Case REG_BINARY
                txt = txt & Space$(indent) & "> " & value_name & " = [binary]" & vbCrLf
            Case REG_DWORD
                value_string = "&H" & _
                    Format$(Hex$(value_data(4)), "00") & _
                    Format$(Hex$(value_data(3)), "00") & _
                    Format$(Hex$(value_data(2)), "00") & _
                    Format$(Hex$(value_data(1)), "00")
                txt = txt & Space$(indent) & "> " & value_name & " = " & value_string & vbCrLf
            Case REG_DWORD_BIG_ENDIAN
                txt = txt & Space$(indent) & "> " & value_name & " = [dword big endian]" & vbCrLf
            Case REG_DWORD_LITTLE_ENDIAN
                txt = txt & Space$(indent) & "> " & value_name & " = [dword little endian]" & vbCrLf
            Case REG_EXPAND_SZ
                txt = txt & Space$(indent) & "> " & value_name & " = [expand sz]" & vbCrLf
            Case REG_FULL_RESOURCE_DESCRIPTOR
                txt = txt & Space$(indent) & "> " & value_name & " = [full resource descriptor]" & vbCrLf
            Case REG_LINK
                txt = txt & Space$(indent) & "> " & value_name & " = [link]" & vbCrLf
            Case REG_MULTI_SZ
                txt = txt & Space$(indent) & "> " & value_name & " = [multi sz]" & vbCrLf
            Case REG_NONE
                txt = txt & Space$(indent) & "> " & value_name & " = [none]" & vbCrLf
            Case REG_RESOURCE_LIST
                txt = txt & Space$(indent) & "> " & value_name & " = [resource list]" & vbCrLf
            Case REG_RESOURCE_REQUIREMENTS_LIST
                txt = txt & Space$(indent) & "> " & value_name & " = [resource requirements list]" & vbCrLf
            Case REG_SZ
                value_string = ""
                For i = 1 To value_data_len - 1
                    value_string = value_string & Chr$(value_data(i))
                Next i
                If UCase(value_string) = UCase("Pervasive ODBC Engine Interface") Then
                    txt = txt & Space$(indent) & " > " & value_name & vbCrLf
                    cboODBC.AddItem Trim("" & value_name), k   ' Show ODBC name to cboODBC
                    k = k + 1
                End If
                'txt = txt & Space$(indent) & "> " & value_name & " = """ & value_string & """" & vbCrLf
        End Select

        value_num = value_num + 1
    Loop

    ' Enumerate the subkeys.
    subkey_num = 0
    Do
        ' Enumerate subkeys until we get an error.
        length = 256
        subkey_name = Space$(length)
        If RegEnumKey(hKey, subkey_num, _
            subkey_name, length) _
                <> ERROR_SUCCESS Then Exit Do
        subkey_num = subkey_num + 1
       
        subkey_name = Left$(subkey_name, InStr(subkey_name, Chr$(0)) - 1)
        subkeys.Add subkey_name
   
        ' Get the subkey's value.
        length = 256
        subkey_value = Space$(length)
        If RegQueryValue(hKey, subkey_name, _
            subkey_value, length) _
            <> ERROR_SUCCESS _
        Then
            subkey_values.Add "Error"
        Else
            ' Remove the trailing null character.
            subkey_value = Left$(subkey_value, length - 1)
            subkey_values.Add subkey_value
        End If
    Loop
   
    ' Close the key.
    If RegCloseKey(hKey) <> ERROR_SUCCESS Then
        MsgBox "Error closing key."
    End If

    ' Recursively get information on the keys.
    For subkey_num = 1 To subkeys.Count
        subkey_txt = GetKeyInfo(section, key_name & "\" & subkeys(subkey_num), indent + 4)
        txt = txt & Space(indent) & _
            subkeys(subkey_num) & _
            ": " & subkey_values(subkey_num) & vbCrLf & _
            subkey_txt
    Next subkey_num

    GetKeyInfo = txt
End Function

Auto logon for Windows XP

posted on 28 Aug 2008 13:39 by computertips  in WindowsTips

Would you rather not have to log on after your computer starts? If you’re the only person who uses your computer, you can make life a little easier by skipping the Welcome screen completely and having Microsoft Windows XP take you straight to your desktop.

To automatically log on to Windows XP upon startup

1.

Click Start, and then click Run.

Note: Remember your user name at the top of the Start menu, because you’ll need it later.

Start menu with Run selected

2.

In the Open box, type control userpasswords2 and click OK.

Run dialog box

3.

Clear the Users must enter a user name and password to use this computer check box. Click OK.

User Accounts dialog box

4.

Click the User name box, type the user name that was displayed on the Start menu in step 1. If you normally type a password to log on, type your password in both the Password and Confirm Password boxes. Otherwise, leave these boxes blank. Click OK.

Automatically Log On dialog box

Auto logon now allows anyone to start and use your computer without typing a password.

Note: Keep in mind that you should not enable auto logon if you need privacy for any files on your computer. If you need to maintain privacy, create separate user accounts for everyone in your home, and protect your account with a password.

Add a Map Drive button to the toolbar

posted on 28 Aug 2008 13:02 by computertips  in WindowsTips

If you have more than one computer running Microsoft Windows XP connected to your home network, you can share folders between them so you can open files on one computer even if they’re stored on another. To make it easier to connect to a shared folder, you can add a Map Drive button to your Windows Explorer toolbar. This button provides a fast link to the shared folder.

To add a Map Drive button

1.

Click Start, and then click My Computer.

The Start menu with My Computer selected

2.

Right-click the toolbar, and then click Customize.

The toolbar shortcut menu with Customize selected

3.

The Customize Toolbar dialog box appears. In the Available toolbar buttons list, click Map Drive, and then click Add. To be able to remove mapped drives using a toolbar button, select Disconnect, and then click Add.

Customize Toolbar dialog box with Map Drive selected in list of Available toolbar buttons

4.

Click Close.

Customize Toolbar dialog box with the Close button selected

The Map Drive button appears on your toolbar. To map a network drive, click the Map Drive toolbar button. The toolbar button has exactly the same effect as clicking the Tools menu and then clicking Map Network Drive.

The Map Drive button

For more information about customizing toolbars, read Change your toolbars.

Format backup drives with NTFS

posted on 28 Aug 2008 12:47 by computertips  in WindowsTips

Backing up your important files regularly is the key to recovering from a serious system failure. And, with Microsoft Windows XP, the most effective way to back up your computer is to copy your files to an external hard drive using Windows Backup. Before you back up your computer for the first time, you'll want to be sure your external hard drive is formatted with the New Technology File System (NTFS).

There are two ways to enable NTFS on your external hard drive: you can format it or convert it. If you have not yet copied any files on your external drive, you should format it with NTFS. Formatting is preferable to converting because it will make the drive run faster, among other benefits. Formatting a hard drive permanently removes all files, so you should not format the drive if you have saved anything on it (without making a copy of the files first). If you don't want to overwrite the data, you should convert the drive to NTFS instead.

Note: File systems define how your computer writes (or saves) files to a hard drive. Windows XP supports two file systems for external drives: FAT32 and NTFS. External hard drives typically come formatted with the FAT32 file system because it is compatible with earlier versions of Windows. However, the NTFS file system is superior to the FAT32 file system in many ways. Most importantly, NTFS can support files larger than 4 GB in size, which provides plenty of room for your backups.

Format a backup drive with NTFS

Before you begin, connect your external hard drive.

To format the drive with NTFS

1.

Log on to your computer as an administrator.

2.

Click Start, right-click My Computer, and then click Manage.

3.

Under Storage, click Disk Management.

Computer Management window with Disk Management selected

4.

If the Initialize and Convert Disk Wizard appears, click Next. If the wizard does not appear, skip to step 8.

Welcome to the Initialize and Convert Disk Wizard page with Next selected

5.

On the Select Disks to Initialize page, click Next.

Select Disks to Initialize page with Next selected

6.

On the Select Disks to Convert page, click Next.

Select Disks to Convert page with Next selected

7.

On the Completing the Initialize and Convert Disk Wizard page, click Finish.

Completing the Initialize and Convert Disk Wizard page with Finish selected

8.

Right-click your external drive (which will probably be drive E or drive F), and then click Format.

Computer Management window with Format selected on an external drive’s shortcut menu

9.

In the Format dialog box, type a name for your external hard drive, such as Backup Drive. Then, click OK.

Format dialog box with drive name entered and OK selected

10.

Click OK again.

Format warning message with OK selected

Windows XP formats your external hard drive. Within a few minutes, your drive will be ready for you to use.

Convert a backup drive to NTFS

If you have already copied files to your external hard drive, and you don't want to delete them, you can convert your hard drive to NTFS.

To convert an external drive to NTFS

1.

Log on to your computer as an administrator.

2.

Click Start, right-click My Computer.

Start menu with My Computer selected

3.

In the My Computer window, make a note of the drive letter and label assigned to your external drive. Usually, the drive letter will be E or F. The drive letter will not be C (that's the hard drive inside your computer). The label is the word between the drive picture and the drive letter. Some drives may not have a label.

My Computer window with drive label and drive letter highlighted

4.

Click Start, click Run, and then type convert drive_letter: /fs:ntfs

For example, if your external drive is drive E, you would type convert E: /fs:ntfs

Then, click OK.

Run dialog box with convert command line entered and OK selected

5.

A command window appears. Type the label for your external drive, and then press ENTER. If your drive does not have a label, just press ENTER.

Convert.exe command window

6.

If a message warns you that the volume is in use by another process, close any other open windows. Then, press Y and then ENTER.

Convert.exe command window with warning message and Y entered in command line

Windows XP converts your external drive to NTFS. When the conversion is done, the window automatically closes. Your drive is ready for your backups.