Home > Language Reference > Classes > StreamFileDB
Open Method
Creates and/or opens a file.
Syntax
Public Sub Open(ByRef sName As String, ByVal eMode As HbMode, Optional ByRef sType As String = "", Optional ByRef sCreator As String = "")
| Parameter | Description |
| sName | File name. |
| eMode | Open mode. |
| sType | Database type. |
| sCreator | Database creator. |
Remarks
The Open method opens or creates a file in the storage heap and associates it with this instance of the StreamFileDB class. All subsequent operations carried out using the properties and methods of this object apply to this file.
The sName parameter specify the name of the database containing the file to open or create. This name uniquely identify the file, two different databases cannot having the same name in the storage heap. The eMode parameter specifies the mode to use when opening a file and can be a combination of the constants from the following groups:
To indicate the file access mode, specify one of the following constants:
| Constant | Value | Description |
| hbModeReadOnly | &H0001 | Read only access. |
| hbModeWrite | &H0002 | Write only access. |
| hbModeReadWrite | &H0003 | Read and write access. |
To indicate the file creation mode, specify one of the following constants:
| Constant | Value | Description |
| hbModeOpenExisting | &H0000 | Open an existing file. If it does not exist, an error occurs. |
| hbModeOpenAlways | &H1000 | Open an existing file. If it does not exist, it is created. |
| hbModeCreateAlways | &H2000 | Create a file. If it already exists, overwrite it. |
Finally, you can also specify the following constants:
| Constant | Value | Description |
| hbModeExclusive | &H0008 | Exclude anyone else from using the file until it is closed. |
| hbModeLeaveOpen | &H0004 | Leave the file open even after the application exits. |
If you specify the creation mode hbModeOpenAlways or hbModeCreateAlways, you should also specify the access mode hbModeWrite or hbModeReadWrite, or a runtime error occurs. In effect, these file open modes require the creation or truncation of the file which is why they must be available for writing.
If you open an existing file, the optional sType and sCreator parameters are ignored. On the other hand, if the file is to be created, they respectively specify the type and creator of the database that will contain the file. If you omit the sType parameter, it defaults to "strm". If you omit the sCreator parameter, it defaults to the same creator as your application.
The following example creates a file named "tmp" and writes some text:
Private Sub Button1_Click() Dim s as New StreamFileDB s.Open "tmp",hbModeCreateAlways+hbModeReadWrite s.Write "Sample text" s.Close End Sub
To avoid conflict between stream databases used by different applications, it is strongly advised to use significative names. For example, you can prefix file names with the creator of your application, or use descriptive names that are unlikely to be used by another application.
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |