INFO: How Visual Basic 4.0 Handles Files Marked Read-OnlyLast reviewed: March 31, 1997Article ID: Q143044 |
The information in this article applies to:
SUMMARYVisual Basic 4.0 may handle files with the read-only attribute set differently than Visual Basic 3.0. This may result in a "Can't Edit Module" error when trying to change a code module. The Visual Basic 4.0 development environment will handle read-only files in one of two ways. The way Visual Basic 4.0 behaves is dependent on the current setting of the ReadOnlyMode property of the development environment. If the ReadOnlyMode is set to 0 (lenient) you will be able to edit files marked read-only just like Visual Basic 3.0. Of course you will still not be able to save your changes. If the ReadOnlyMode is set to 1 (strict) Visual Basic will not allow you to edit files marked read-only.
MORE INFORMATIONThe default ReadOnlyMode for Visual Basic 4.0 is lenient. However, the default can be changed to strict by adding ReadOnlyMode=1 to the Visual Basic section of the VB.INI. ReadOnlyMode can also be changed dynamically by Visual Basic 4.0 add-ins through the ReadOnlyMode property of the Application object of Visual Basic 4.0 add-in object model. The Microsoft SourceSafe add-in for Visual Basic 4.0 sets Visual Basic 4.0 to the strict mode. The following example shows you how to create a add-in that will allow you to toggle the ReadOnlyMode from a menu item.
Example
using the Tools/References dialog.4. Add a new standard module (Module1.BAS by default). 5. Put the following code in the standard module:
''' MODULE1.BAS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #If Win16 Then Declare Function WritePrivateProfileString Lib "KERNEL" ( _ ByVal AppName As String, ByVal KeyName As String, _ ByVal keydefault As String, ByVal FileName As String) As Integer Declare Function GetPrivateProfileString Lib "KERNEL" ( _ ByVal AppName As String, ByVal KeyName As String, _ ByVal keydefault As String, ByVal ReturnString As String, _ ByVal NumBytes As Integer, ByVal FileName As String) As Integer #ElseIf Win32 Then Declare Function WritePrivateProfileString Lib "KERNEL32" _ Alias "WritePrivateProfileStringA" (ByVal AppName As String, _ ByVal KeyName As String, ByVal keydefault As String, _ ByVal FileName As String) As Long Declare Function GetPrivateProfileString Lib "KERNEL32" _ Alias "GetPrivateProfileStringA" (ByVal AppName As String, _ ByVal KeyName As String, ByVal keydefault As String, _ ByVal ReturnString As String, ByVal NumBytes As Long, _ ByVal FileName As String) As Long #End If Sub Main() #If Win16 Then Const Section = "Add-Ins16" #ElseIf Win32 Then Const Section = "Add-Ins32" #End If Const BufSize = 255 Dim Ret As Variant Dim RetStr As String 'Check to see if the entry is already in the VB.INI file. Add ifnot.
RetStr = Space(BufSize) Ret = GetPrivateProfileString(Section, "ReadOnlyMode.Switch", _ "NotFound", RetStr, BufSize, "VB.INI") RetStr = Left(RetStr, Ret) If RetStr = "NotFound" Then WritePrivateProfileString Section, "ReadOnlyMode.Switch", _ "0", "VB.INI" End If End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' values: Property Value ---------- ----------------------- Instancing 1 - Creatable MultiUse Name Switch Public True
''' CLASS1.CLS '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit Private ThisInstance As VBIDE.Application Private AddInMenuLine As VBIDE.MenuLine Private AddInID As Long Public Sub ConnectAddIn(VBInstance As Object) Set ThisInstance = VBInstance Set AddInMenuLine = ThisInstance.AddInMenu.MenuItems.Add( _ "Strict &ReadOnlyMode") AddInMenuLine.Checked = ThisInstance.ReadOnlyMode AddInID = AddInMenuLine.ConnectEvents(Me) End Sub Public Sub DisconnectAddIn(Mode As Integer) AddInMenuLine.DisconnectEvents AddInID ThisInstance.AddInMenu.MenuItems.Remove AddInMenuLine End Sub Public Sub AfterClick() ThisInstance.ReadOnlyMode = ThisInstance.ReadOnlyMode Xor 1 AddInMenuLine.Checked = ThisInstance.ReadOnlyMode End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Value -------------- --------------------- Startup Form Sub Main Project Name ReadOnlyMode StartMode OLE Server Error Trapping Break in Class Module default.)13. Use the Add-In Manager to add the ReadOnlyMode.Switch add-in. 14. Open a code module with that has the read-only attribute set. You can tell if a file is marked read-only by the small red lock that appears in the project window next to the file.15. From the Add-In menu you can switch the ReadOnlyMode. When checked the environment will be in strict mode and when unchecked it will be in lenient mode. |
Additional query words: Addin Addins VBIDE ssafe
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |