Posts tagged: file

INFO: Lightweight Controls in Visual Basic 6.0

By , January 20, 2011

Symptoms
This article contains information about the lightweight, or windowless,controls that ship with Visual Basic version 6.0. This article alsodescribes lightweight controls, explains their advantages anddisadvantages, and illustrates how to install lightweight controls in yourVisual Basic project.
Resolution
Lightweight controls, sometimes referred to as windowless controls, aresimilar to the regular controls shipped in Visual Basic except that they donot have a window handle. Because lightweight controls do not have a windowhandle, these controls use less system resources. Lightweight controls areideal for projects where system resources might be a limiting factor, suchas Internet applications and distributed applications.
Lightweight controls with a Transparent BackStyle property are trulytransparent. A regular control might appear to be transparent under thesame conditions. However, the control is still processing Windows messagesin that transparent background area. When a lightweight control has atransparent background, the container holding the lightweight controlactually processes the Windows messages instead of the lightweight control.Because lightweight controls are truly transparent, these controls can beany shape.
There are some disadvantages to lightweight controls. Lightweight controlcontainers can only contain other lightweight controls. If you put aregular control in a lightweight control container, the container willrevert to a regular window control container. Regular controls alwaysappear on top of a lightweight control because the lightweight control usesthe resources of the parent window.
When you run Visual Basic, the following controls in your Toolbox arelightweight controls:Image ControlLabel ControlLine ControlShape ControlIn addition to these intrinsic lightweight controls, following are otherlightweight controls included in the component file MSWLess.ocx that shipswith Visual Basic 6.0:WLCheck ControlWLCombo ControlWLCommand ControlWLFrame ControlWLHScroll ControlWLVScroll ControlWLList ControlWLOption ControlWLText ControlTo use these controls in your Visual Basic program, you must complete thefollowing steps:Register the windowless component file in your system registry.Copy the component file and help files to the appropriate directories in your system.Add the ActiveX controls to your Visual Basic program.
How To Register the Windowless Component FileSearch for the registration file, MSWLess.reg, on your Visual Basicinstallation disks. The file is located in the Common\Tools\Vb\WinLessdirectory on disk 1. NOTE: The windowless controls are in the following location on the August 1998 MSDN CDs: Disk3\Common\Tools\VB\Winless.Double-click MSWLess.reg. The following Registry Editor dialog boxappears when you have successfully registered the windowless componentfile:
Information in the Common\Tools\Vb\WinLess\MSWLess.reg has beensuccessfully entered into the registry.You have just registered the windowless component file. The next sectionshows you how to copy the appropriate windowless component and Help filesto your computer.
How To Copy the Windowless Component FilesSearch for the following files on your Visual Basic installation disks. These files are located in the Common\Tools\Vb\WinLess directory ondisk 1.

FilenameDescription————————————————————————ltwtct98.chiHelp file on windowless controls.ltwtct98.chmHelp file on windowless controls.MSWLess.ocxWindowless component file with the windowless ActiveXControls. Copy the two Help files to your local Windows\Help directory.Copy the windowless component file, MSWLess.ocx, to your localWindows\System directory.You have just copied all the necessary windowless component files. The nextsection shows you how to add a windowless control to your Visual Basicprogram.
How To Add a Windowless Control To Your ProjectStart a new project in Visual Basic.From the Project menu, click Components. The Components dialog box appears.From the Controls tab, select the Microsoft Windowless Controls 6.0 check box.Click OK to close the Components dialog box. All the windowless controls appear on the toolbar.

INFO: The Microsoft Office XP FileDialog Object

By , December 13, 2010

Symptoms
Microsoft Office XP provides a FileDialog object that gives youfunctionality that is similar to the standard Open and Save dialog boxes that are found in all Office XP applications. By using FileDialog objects in your Visual Basic for Application (VBA) solutions, you can easily provide a user interface for file selection or file naming without the need for additional ActiveX Controls or third-party solutions.
Resolution
To use a FileDialog object, you must first call the FileDialog property of an Office XP Application object and provide an argument for the DialogType. There are four types of file dialogs:Open Dialog (msoFileDialogOpen) – allows users to select one or more files. If you choose to do so, you can then open the selected file or files in the host application by using the Execute method. SaveAs Dialog (msoFileDialogSaveAs) – allows users to select a single file. If you choose to do so, you can then save the current file by using the Execute method. File Picker Dialog (msoFileDialogFilePicker) – allows users to select one or more files. The file paths that the user selects are captured in the FileDialogSelectedItems collection. Folder Picker Dialog (msoFileDialogFolderPicker) – allows users to select a folder. The path for the selected folder is captured in the FileDialogSelectedItems collection. Each host Office application can only instantiate a single instance of a FileDialog object. Many of the properties of the FileDialog object persist even when you create multiple FileDialog objects. Therefore, you should initialize all of the dialog properties appropriately for your purpose before you display the dialog box.
Once you have a reference to a FileDialog object, you can display the dialog box by using the Show method. All FileDialog objects are modal so once a dialog box is displayed, no code continues to execute until the dialog box is dismissed. Your code can also check the return value of the Show method to determine if the user accepts or cancels the file (or folder) selection and then to handle that condition as needed.
The following sample VBA code creates and shows a File Picker dialog box. When you run the code to display the dialog box, select one or more files and click OK to dismiss the dialog box. Each of your file selections is displayed in a message box. Note that you can use the CTRL+SHIFT keyboard combination in the dialog box to select multiple files.

Sub Main()’Declare a variable as a FileDialog object.Dim fd As FileDialog’Create a FileDialog object as a File Picker dialog box.Set fd = Application.FileDialog(msoFileDialogFilePicker)’Declare a variable to contain the path’of each selected item. Even though the path is a String,’the variable must be a Variant because For Each…Next’routines only work with Variants and Objects.Dim vrtSelectedItem As Variant’Use a With…End With block to reference the FileDialog object.With fd’Use the Show method to display the File Picker dialog box’The user pressed the action button.If .Show = -1 Then’Step through the FileDialogSelectedItems collection.For Each vrtSelectedItem In .SelectedItems’vrtSelectedItem contains the path of each selected item.’Here use any file I/O functions you want on the path.’This example simply displays the path in a message box.MsgBox “The path is: ” & vrtSelectedItemNext vrtSelectedItem’The user pressed Cancel.ElseEnd IfEnd With’Set the object variable to Nothing.Set fd = NothingEnd Sub After you call the Show method to display a file dialog box, if the dialog box is type msoFileDialogOpen or msoFileDialogSaveAs, you can call the Execute method to carry out the default Open or Save action. For example, if the file dialog box type is msoFileDialogOpen, you can call the Execute method to open the file selected by the user.
Additional Note
Because a file dialog box can only be accessed by calling the FileDialog property of an Office Application object, use of an Office XP file dialog box requires a running instance of an Office XP application. Therefore, you cannot use the Office XP file dialog boxes from a non-Office application without Automation to an Office application.

Add Embedded Resources by C#

By , August 25, 2010

Add Embedded Resources

To add a text file and an image file to your project as embedded resources, follow these steps:

  1. Create a new Windows Application project for this demonstration. This form is used to display the resources that are accessed from the executing assembly during run time.
  2. Right-click your project name, click Add, and then click Add New Item.
  3. In the New Item dialog box, select Text File from the menu, and name the file MyTextFile.txt. When the file opens in the integrated development environment (IDE), add some text, and then close the file.
  4. Repeat steps 1 and 2 to add a bitmap image to your project, but instead of selecting Text File as the new item type, select Bitmap File, and then change the file name to MyImage.bmp. When the new image is opened in the IDE, draw something on the image, and then close the file.
  5. Right-click either the text file or the bitmap, and then select Properties.
  6. In the Properties dialog box, locate the Build Action property. By default, this property is set to Content. Click the property and change the Build Action property to Embedded Resource.
  7. Repeat steps 4 and 5 for the other file.

The next time you build the project, the compiler adds these files to your assembly. The compiler adds the root namespace of the project to the name of the resource when it is included in the project. For example, if the root namespace of your project is MyNamespace, the resources are named MyNamespace.MyTextFile.txt and MyNamespace.MyImage.bmp.