If you've ever been to the Visual Basic Discussion Forum then you realize why I'm posting this. It's simply a list of commonly asked questions. Please feel free to add on anything that either you've learned here at VBC or anything that you find yourself answering on a regular basis. (Revised Jul 06, 2001)
Revised Jul 19, 2001
Revised Jul 24, 2001
| Writing/Appending text to a text file | Open "C:\MyTextFile.txt" For Output As #1 |
Input/Output Text file |
| Reading text from a text file | Open "C:\MyTextFile.txt" For Input As #1 |
Input/Output Text file |
| Setting a string to the application directory | strFileName = App.Path & (Trim(Chr(32 - (60 * (Asc(Right(App.Path, 1)) <> 92))))) |
Relative paths |
| Reading data from an INI file | Private Declare Function GetPrivateProfileString Lib "kernel32"_ |
INI file template routines |
| Writing data to an INI file | Private Declare Function WritePrivateProfileString Lib "kernel32"_ |
INI file template routines |
| Dynamically adding controls | Rem This code is for Visual Basic 6 only but the second link shows how to do it with VB4/5 |
Dynamically create a control(VB6) Creating controls dynamically (VB6,5 and 4) |
| Adding items to a combo/list box and setting it to the first items if an item exist |
cmbMyComboBox.AddItem "Item1" |
None |
| Having problems with the license of your Winsock control? | Just go to the link |
Register/License Winsock Control |
| Allows only numeric characters in a textbox | Private Sub txtNumbersOnly_KeyPress(KeyAscii As Integer) |
Masking Control |
| Prints a picture control contents to the printer | Printer.PaintPicture picMyPictureControl.Picture, 1, 1 |
Printing picture control contents |
| Copy picture/text to the Clipboard | Clipboard.Clear Clipboard.SetData picMyPictureControl.Picture 'Used for pictures |
Copying contents to the Clipboard |
| Paste picture/text from the Clipboard | picMyPictureControl.Picture = Clipboard.GetData 'Used for pictures |
Pasting contents from the Clipboard |
| Evaluate resposes from MsgBox | Rem Use this to check before you save; used with yes/no or ok/cancel options |
None |
| Read data from an Excel spreadsheet | Dim xlsApplication As Object |
None |
| Read data from Outlook Inbox/SentMail folders | Dim outApplication As Object |
None |
| Sending email using the MS Outlook object | Private Sub MrPostman(strSendTo As String, strSubject As String, strMessage As String) |
None |
| Calling procedures dynamically | Rem Use this code when you don't know the name of the procedure or when you want the user to select the procedure to execute |
None |
| Copy/Move files from one location to another | FileCopy "C:\SourceFile.txt", "C:\DestinationFile.txt" |
None |
| Retained is an invalid key error | You will get this error when you attempt to open a project designed in VB6+ with VB5-. The solution is to open the project file (*.vbp) with a text editor like notepad and delete the line that begins with RETAINED=. This will solve the error. |
None |
| What does referencing a control mean? What is the difference between early and late binding? |
When you create a reference to a control, you are indicating that there is a file that exists that you would like to use. Early-binding indicates this reference at design-time of the application rather than an runtime (late binding). Early binding is much faster than late binding. Late binding is used when an application must determine at runtime. Although this process is slower than late binding, it may be faster after consideration. For example, let's say that you are importing data from one source to another. You are uncertain at design time wheter the user will want to import from Excel to Access, Outlook to Excel, Outlook to Access, Excel to Outlook, Access to Outlook, or Access to Excel. Instead of referencing all three objects at design time(early binding),it may be more practical to refernce them once the user has mad a decision (late binding). |
None |