------------------------------------------------- VB FAQ http://www.beadsandbaubles.com/coolvb/qa/faq.txt ------------------------------------------------- Hypertext version available @ http://www.beadsandbaubles.com/coolvb/qa/ 0 Bug Fixes 1 ActiveX 2 Classes(Object-Oriented Programming) 3 Coding 4 Controls 5 Data Access 6 Disk Access 7 Forms 8 General 9 Graphics 10 Math 11 Miscellaneous 12 Multimedia 13 OLE 14 Port/Serial I/O 15 String Manipulation 16 The Visual Basic IDE 17 User Interface 18 Variables 19 Windows API 1.0 Picturebox drains resources. Medium *Bug Fix* Compatibility:VB5 A picturebox with the appearance property set to 0 - Flat loses memory ever time the form is unloaded. This does not occur when the appearance property is set to 1 - 3D. To fix, set the appearance property to 1-3d or use a different container, such as image control, frame, or usercontrol. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 2.0 Books online search yields incorrect results. Medium *Bug Fix* Compatibility:VB5 Books Online will not display the correct titles if the search string is typed in too slowly. To fix, either *type as quickly as possible *or paste the search string into the search field. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Controls 14.0 I have a Tab control on my form. If I start with tab # 1 selected, my controls disapear. What gives? Medium *Bug Fix* Compatibility:VB4 VB5 That's a definite bug. It should be fixed if you get DevStudio service pack 1. However, the easier fix is simply to always start on tab 1. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ActiveX 3.0 In other ActiveX controls, they have descriptive text in the properties window, instead of numbers. How can I do that? Medium Compatibility:VB5 Simple. Instead of declaring the property of type integer or long, do this: Enum MyOptions [The Description of The First Item] TheDescriptionofTheSecondItem end Enum You only need to enclose the description in brackets if it contains spaces or other illegal characters. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ActiveX 4.0 My controls don't have cool features, like having the caption update as you type. Medium Compatibility:VB5 In order to give a property a special function, follow these steps: *Go into object browser. *Select the appropriate property. *Right click on the property and click on Properties. *Select Advanced. The Procedure ID drop-down box allows you to select a "behavior" of that property. Here are some of the more interesting settings: *Caption, Text Either of these procedure IDs will give a property the Properties window behavior demonstrated by the Caption and Text properties of Visual Basic intrinsic controls. That is, when a user types a value into the Properties window, the new value will be reflected immediately in the control. This means that your Property Let procedure will be called for each keystroke the user enters, receiving a complete new value each time. This is similar to a Text control or a label. * (Default) The default property of a control is the one that will be accessed when no property has been specified. For example, the following assigns the string "Cool VB" to the (default) Caption property of Label1: Label1 = "Cool VB" * Enabled This procedure ID must be assigned to the Enabled property of your control, in order for its enabled/disabled behavior to match that of other controls. The other interesting box is the Categories box, which controls what section the properties appear in the Categorized tab. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Classes(Object-Oriented Programming) 5.0 How can I pass multiple parameters to a property let procedure? Let's say I've two (2) string member variables defined as follows: Private m_s1 As String Private m_s2 As String I want to create a procedure to "set" these variables in the "TheClass" class and so I code Public Property Let SetVals(ByVal sStr1 As String, ByVal sStr2 As String) m_s1 = sStr1 m_s2 = sStr2 End Property In the General Declaration on my form I code Dim MyClass as TheClass During Form Load I code Set MyClass = New TheClass MyClass.SetVals ("AA","BB") ' And god knows how many variations!! . . No matter what variation on MyClass.SetVals I use (= sign, (), etc.) I get either compilation or run-time errors. Medium Compatibility:VB4 VB5 You *can* do this, but not the way you think. It works like this: SetVals("AA") = "BB" It's kind of odd, because the first param is what is on the left side of the assignment(=), and the rest are contained in the params. Like this: SetVals(Param2,Param3,Param4) = Param1 However, I would implement your class like this: Private m_s1 As String Private m_s2 As String Property Let s1(ByVal sStr1 As String) m_s1 = sStr1 End Property Property Let s2(ByVal sStr1 As String) m_s2 = sStr1 End Property =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Classes(Object-Oriented Programming) 6.0 How can I create a class member that is public to other files in my project but private to the world? Medium Compatibility:VB5 Use the Friend keyword. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Classes(Object-Oriented Programming) 7.0 How can I create a stack class with the least amount of code? Expert Compatibility:VB4 VB5 Try this code: Dim m_Collect As New Collection Property Get Count() As Long Count = m_Collect.Count End Property Public Sub Push(i As Variant) m_Collect.Add i End Sub Public Function Pop() As Variant If m_Collect.Count = 0 Then Beep: GoTo exiter Pop = m_Collect(m_Collect.Count) m_Collect.Remove m_Collect.Count exiter: End Function =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Coding 8.0 I've heard that using END is dangerous; what's the best way to end my program? Medium Compatibility:VB3 VB4 VB5 To end your program, use this code: dim ret as object for each ret in forms unload ret set ret = nothing next =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Coding 9.0 What does it mean to pass by reference? Medium Compatibility:VB3 VB4 VB5 When you pass by reference, you get the actual variable. (You pass by reference by default.) In contrast, when passing by value, you get a copy of the variable. The net effect is passing by value prevents you from changing the variable =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Coding 10.0 What is Option Explicit and why should I use it? Medium Compatibility:VB3 VB4 VB5 When you use Option Explicit, you have to declare all of your variables. For instance: sub mySub() dim i as integer i = 3 'Works with either x = 3 'Works only when option explicit is disabled. ... end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Coding 11.0 How can I break up long lines of VB code? Medium Compatibility:VB4 VB5 Use a space followed by a underscore, like this: debug.print "Hi! "; _ "World!" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Controls 12.0 How can I include a ampersand inside a control? Easy Compatibility:VB3 VB4 VB5 As you no doubt noticed, VB automatically converts ampersands to undescores. To fix this, use a double ampersand in place of a single ampersand. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Controls 13.0 Can I create a label that is vertically oriented? Easy Compatibility:VB3 VB4 VB5 Sure. Try this: dim s as string for i = 1 to len(label1) s = mid$(label1,i,1) & vbcrlf ' Replace vbcrlf with chr$(13) & chr$(10) next label1 = s =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Controls 14.0 I have a Tab control on my form. If I start with tab # 1 selected, my controls disapear. What gives? Medium*Bug Fix* Compatibility:VB4 VB5 That's a definite bug. It should be fixed if you get DevStudio service pack 1. However, the easier fix is simply to always start on tab 1. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Data Access 15.0 I'm writing a database system. How can I create a number that's is fairly unique, and feasible to implement for ID strings? Expert Compatibility:VB4 VB5 GUIDs, which windows uses to OLE resources, are farely random 128-bit numbers. Where I work we use them heavily to track items in a database. GUID's are great because the are unique. Well, Visual Basic 5.0 comes with a program that create them for you, but what a pain. Wouldn't it be nice to just do it via code? Well now you can with the sample code below. Private Type GUID Data1 As Long Data2 As Long Data3 As Long Data4(8) As Byte End Type Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any,ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long Public Function GetGUID() As String Dim pudtGUID As GUID Dim pstrGUID As String Dim pbytGUID() As Byte Dim plngRet As Long Dim plngLen As Long plngLen = 40 pbytGUID = String(plngLen, 0) CoCreateGuid pudtGUID plngRet = StringFromGUID2(pudtGUID, VarPtr(pbytGUID(0)), plngLen) pstrGUID = pbytGUID If (Asc(Mid$(pstrGUID, plngRet, 1)) = 0) Then plngRet = plngRet - 1 GetGUID = Left(pstrGUID, plngRet) End Function Compliments of David McCarter/Woody Pewitt =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Disk Access 16.0 How can I check for the existance of files? Medium Compatibility:VB3 VB4 VB5 Use this function: Public Function fileExist(fileName As String) As Boolean Dim l As Long On Error Resume Next l = FileLen(fileName) fileExist = Not (Err.Number > 0) On Error GoTo 0 End Function =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Disk Access 17.0 I'm trying to read a file with EOF's in it. I can't read past the first EOF. Medium Compatibility:VB3 VB4 VB5 In VB, there are three modes of I/O. Random, Text, and Binary. When you open a file as Text mode, you are telling VB that the file you're reading is a text file. Text files end with a EOF. So, the answer would be to open the file as binary. Binary files can have EOFs in them with no problem. Instead of this: open "myfile.dat" as #1 for input Do this: open "myfile.dat" as #1 for binaryNote that you will have to use slightly different functions in binary mode. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Disk Access 18.0 How can I load a file into a TextBox or RichTextBox? Medium Compatibility:VB4 VB5 Use the following code: dim sFile as string 'Set sFile equal to your filename dim i as long i = freefile() open sFile for input as #i txtMain.text = input$(i,LOF(i)) close #1 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Disk Access 19.0 How can I make all the files in a directory uppercase or lowercase? Medium Compatibility:VB3 VB4 VB5 Say you want to take a whole bunch of files and make them all named in lowercase(or uppercase). Launch VB, and copy and paste this code: Dim s As String, mypath As String mypath = "d:\mydir\moredir" s = Dir$(mypath & "*.txt") '*.* works too Do While s <> "" Name mypath & s As mypath & LCase$(s) s = Dir$() Loop =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Disk Access 20.0 I have a program that writes to a file. Instead of adding to it, it overwrites it. What's wrong? Medium Compatibility:VB3 VB4 VB5 When you open a file like this: Open ... for output You're telling VB to create a new file or overwrite the only one. What you want to say is: open ... for append That should solve your problem. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 21.0 How can I create a window with a small title bar? Easy Compatibility:VB5 Just set the WindowStyle property to "Sizable Toolwindow" or "Fixed Toolwindow". =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 22.0 What's the difference between Modal and Modaless forms? Easy Compatibility: When a modal form is active, no otherforms in your program can get the focus. To display a modal form, use the following code: myForm.show 1 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 23.0 How can I create a window with no title bar? Easy Compatibility:VB3 VB4 VB5 You have to set the following properties on your form: Title = blank MinBox = False MaxBox = False ControlBox = False =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 24.0 How can I put a toolbar in my application? Medium Compatibility:VB4 VB5 Create a new form with all your buttons on it. Under VB5, you'll want to set the border property to "4 - ToolWindow". Put the following declarations in a new module: declare Function SetWindowWord Lib "User32" (ByVal hWnd as Long, ByVal _ nIndex as long, ByVal nNewWord as long) as long Next, put the following code in the load event of the toolbar form. SetWindowWord Me.hWnd, -8, Main.hWnd Replace main with the name of your main form. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 25.0 I've heard that using END is dangerous; what's the best way to end my program? Medium Compatibility:VB3 VB4 VB5 To end your program, use this code: dim ret as object for each ret in forms unload ret set ret = nothing next =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 26.0 What's the difference between hiding a form and unloading it? Medium Compatibility:VB3 VB4 VB5 When you unload a form, you're taking the graphical portion of the form out of memory. When you hide a form, you're just telling Windows to stop displaying that form. Hiding a form is faster; Unloading a form takes up less memory. In order to unload the code portion of a form, use the following code: set MyForm = nothing =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 27.0 How can I center a form onto the screen? Medium Compatibility:VB3 VB4 VB5 Simple. In VB5, just set the StartUpPosition property of your form to your desired setting. In VB4/VB3, do this: sub CenterForm(myForm as object) myform.left = (screen.width / 2) - (myform.width / 2) myform.top = (screen.height / 2) - (myform.height / 2) end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 28.0 How can I make a form "Always on top"? Medium Compatibility:VB4 VB5 Put this code in a module: Declare Function SetWindowPos Lib "user32" ( _     ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _     ByVal x As Long, ByVal y As Long, ByVal cx As Long, _     ByVal cy As Long, ByVal wFlags As Long) As Long Private Const SWP_NOSIZE = &H1 Private Const SWP_NOMOVE = &H2 Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 public sub SetFormOnTop(myForm as object) SetWindowPos myForm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 29.0 How can I minimize all the forms in my project at once? Medium Compatibility:VB4 VB5 Copy this code into a module: sub MinimizeAllForms() dim objTemp as object for each objTemp in forms objTemp.windowstate = 1 next end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Forms 30.0 How can I tile a image on a form? Medium Compatibility:VB4 VB5 Put the following code in your form_paint: dim i as integer, j as integer for i = 0 to scalewidth step picture1.width for j = 0 to scaleheight step picture1.height paintpicture picture1.picture, i, j next next and replace picture1 with the name of your picturebox or imagebox control. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- General 31.0 What is the most recent version of Microsoft Visual Basic? Easy Compatibility:VB3 VB4 VB5 As of this writing, 5.0. (Plus one bug patch.) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- General 32.0 Is there a student discount for Visual Basic and other related products? Easy Compatibility:VB3 VB4 VB5 Yes; you can get VB5 Pro for $90. Contact Microsoft for the dealer closest to you. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- General 33.0 Does VB create stand alone Exe files? Easy Compatibility:VB3 VB4 VB5 Yes. However, each version of VB requres a different "runtime" file. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- General 34.0 What are some good examples of commercial apps built using Visual Basic? Medium Compatibility:VB3 VB4 VB5 Many commercial programs have been writen in Visual Basic: *Neuron, the paralegal database system, which is being used by the Research Connection of New Hampshire(http://rcnh.home.ml.org) *HotDog Pro *Many small utilities from Microsoft *MaxIcon Please note that this is only a small list of all the programs written in VB. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- General 35.0 What are the limits of VB? Medium Compatibility:VB3 VB4 VB5 The higher the version you have, the fewer limits you'll encounter. VB5 has almost no limits. VB4 can do more then VB3, but still can't approach C++. You can use pointers in VB5, which speeds up variable manipulation quite a bit. You can also write ActiveX controls and servers in VB5. However, the following things are not possible to write in straight VB: *Non-OLE DLL's. (Not very useful anyway.) *Device drivers. *Control panel applets. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Graphics 36.0 How can I use VB to view a JPEG, GIF, or XBM? Medium Compatibility:VB4 VB5 You can't do this with VB4 or earlier. You have to get a OCX or VBX. (Unless, of course, you have or had VB5CCE installed, in which case you can do it the same as in VB5). With VB5, you can use loadpicture, like this: picture1 = loadpicture("mypicture.jpg") picture2 = loadpicture("myotherpic.gif") Or, you can set the picture or icon property of any control at design time to a JPEG, GIF, or XBM. This technique works for GIF, JPEG, WMF, BMP, ICO, RLE, and XBM. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Math 37.0 I process customer orders, and they come in batches of tens. I need to round a number to the closest 10, but I can only round up. Otherwise, the user won't have sufficent product. How can I do this? Plus, is there anyway to round down? Medium Compatibility:VB3 VB4 VB5 Use these functions: Function RoundUp(byVal Value as long, Round as long) RoundUp = ((Value \ Round) + Sgn(Value Mod Round)) * 5 End Function Function RoundDown(byVal Value as long, Round as long) RoundUp = Value - (Value mod Round) End Function =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Miscellaneous 38.0 Can I send keystokes to a dos app? Easy Compatibility:VB3 VB4 VB5 It is possible to use DOS redirection commands to do that with some apps. For instance, to format your diskdrive, print "Y"(no quotes) to a file name "myfile.txt". Then do this: shell "format a: < myfile.txt" Tada! =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Miscellaneous 39.0 Can I compile 16 bit apps in VB5? Easy Compatibility:VB5 No. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Miscellaneous 40.0 How can I check to see if a certain switch has been passed on the command line? Medium Compatibility:VB3 VB4 VB5 Use this function: Function GetCommandLine(iMaxArgs As Integer, iArgCnt As Integer)     Dim i As Integer     Dim iCmdLnLen As Integer     Dim iNumArgs As Integer     Dim fInArg As Boolean     Dim cArg As Variant     Dim CmdLine As Variant     If IsMissing(iMaxArgs) Then iMaxArgs = 10     ReDim ArgArray(iMaxArgs)     iNumArgs = 0: fInArg = False     CmdLine = Command()     iCmdLnLen = Len(CmdLine)     For i = 1 To iCmdLnLen         cArg = Mid(CmdLine, i, 1)         If (cArg <> " " And cArg <> vbTab) Then             'Neither space nor tab.             'Test if already in argument.             If Not bInArg Then             'New argument begins.             'Test for too many arguments.                 If iNumArgs >= iMaxArgs Then Exit For                 iNumArgs = iNumArgs + 1                 fInArg = True             End If             'Concatenate character to current argument.             ArgArray(iNumArgs) = ArgArray(iNumArgs) & cArg         Else             'Found a space or tab.             bInArg = False         End If     Next i     'Resize array just enough to hold arguments.     ReDim Preserve ArgArray(iNumArgs)     iArgCnt = iNumArgs     GetCommandLine = ArgArray() End Function =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Miscellaneous 41.0 What does an "Out of Stack space" error message mean? Medium Compatibility:VB3 VB4 VB5 That means your code in stuck in a infinite loop. For instance, this code will produce that error: sub badSub() badSub end sub Another, somewhat more subtle example, is if you put this code in a text boxes change event: text1 = reverse(text1) (Assuming, of course, you wrote a function to reverse a string named reverse.) When you assign the reverse of text1 to text1, you cause text1_change to fire again. And again. And again. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Miscellaneous 42.0 I have a VB application that loads improperly. Some of the controls and text boxes are white when the application loads until the form_load procedure is complete. Medium Compatibility:VB3 VB4 VB5 You need to put some DoEvents statements in your code. Your Form_Load procedure is usurping the CPU time, and DoEvents give Windows a chance to repaint and process window messages. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Miscellaneous 43.0 I process customer orders, and they come in batches of tens. I need to round a number to the closest 10, but I can only round up. Otherwise, the user won't have sufficent product. How can I do this? Plus, is there anyway to round down? Medium Compatibility:VB3 VB4 VB5 Use these functions: Function RoundUp(byVal Value as long, Round as long) RoundUp = ((Value \ Round) + Sgn(Value Mod Round)) * 5 End Function Function RoundDown(byVal Value as long, Round as long) RoundUp = Value - (Value mod Round) End Function =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Multimedia 44.0 How can I play sounds in my program? Medium Compatibility:VB4 VB5 Put the following functions in a module: Declare Function mciExecute Lib "winmm.dll" Alias "mciExecute" (ByVal lpstrCommand As String) As Long public sub PlayWav(fileName as string) mciExecute("play " & fileName) end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- OLE 45.0 How can I create a class member that is public to other files in my project but private to the world? Medium Compatibility:VB5 Use the Friend keyword. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- OLE 46.0 What is IUnknown? Expert Compatibility:VB4 VB5 IUnknown is the internal interface that all OLE classes implement. If a class is OLE-compliant, then it implements IUnknown. IUnknown defines three methods: Addref, Query, Release. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Port/Serial I/O 47.0 What commands (if any) are used to access the parallel port (both to output and to read)? Similar to the "out" command in some Basics? Medium Compatibility:VB4 VB5 You have a choice. You can use the MS-Comm ocx, which is available by clicking Project->Components->Microsoft Comm Control XX.0. The best way is to use our DLL, CVBIO. You can get it at our download site. It's free of charge. However, the following text: "Portions copyright 1997, Cool VB. http://www.beadsandbaubles.com/coolvb/" must be put in one or more of the following: the credits, the manual, or the about box. Here are the declarations: Private Declare Function cvbInp Lib "cvbio.dll" (ByVal Port As Integer) As Byte Private Declare Function cvbInpw Lib "cvbio.dll" (ByVal Port As Integer) As Integer Private Declare Function cvbInpd Lib "cvbio.dll" (ByVal Port As Integer) As Long Private Declare Function cvbOut Lib "cvbio.dll" (ByVal Port As Integer, ByVal Value As Byte) As Boolean Private Declare Function cvbOutw Lib "cvbio.dlll" (ByVal Port As Integer, ByVal Value As Integer) As Boolean Private Declare Function cvbOutd Lib "cvbio.dlll" (ByVal Port As Integer, ByVal Value As Long) As Boolean The other option is to access the port directly, like this: 'Input dim s as string open "LPT1" for input as #1 s = input(numberofbytestoread, 1) close #1 'Output open "LPT1" for output as #1 print #1, "thestufftosend" close #1 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- String Manipulation 48.0 Why is it that Chr$(13) does not insert a new line? Easy Compatibility:VB3 VB4 VB5 In order to insert a new line, use the VB Constant vbCrLf, or use chr$(13) & chr$(10). =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- String Manipulation 49.0 How can I compare two strings using wildcards? Medium Compatibility:VB3 VB4 VB5 Say you want to compare the string MyStr to the wildcard string "S*" to see if it begins with "S". Do this: ... if MyStr like "S*" then ... .. . =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- String Manipulation 50.0 How should I format dates so that they look correct in all date and langauge formats? Medium Compatibility:VB3 VB4 VB5 Instead of defining your own format, like this: myStr = format$(myDate, "mm:dd:yy") use the predefined types, like this: myStr = format$(myDate, "Short Date") =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- String Manipulation 51.0 How can I count all occurence of one string within another string? Medium Compatibility:VB3 VB4 VB5 Put this code into a module: Public Function sCount(String1 As String, String2 As String) As String Dim I As Integer, iCount As Integer I = 1 Do If (I > Len(String1)) Then Exit Do I = InStr(I, String1, String2, vbTextCompare) If I Then iCount = iCount + 1 I = I + 2 DoEvents End If Loop While I sCount = iCount End Function =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- String Manipulation 52.0 How can I remove all occurences of one string within another string? Medium Compatibility:VB3 VB4 VB5 Put this code into a module: Public Sub sRemove(String1 As String, String2 As String) Dim I As Integer I = 1 Do If (I > Len(String1)) Then Exit Do I = InStr(I, String1, String2) If I Then String1 = Left$(String1, I - 1) + Mid$(String1, I + Len(String2)+1) I = I + 2 DoEvents End If Loop While I End Sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- String Manipulation 53.0 How can I replace all occurences of one string within another string with a third string? Medium Compatibility:VB3 VB4 VB5 Put this code into a module: Public Sub sReplace(String1 As String, String2 As String, RepString As String) Dim I As Integer I = 1 Do If (I > Len(String1)) Then Exit Do I = InStr(I, String1, String2) If I Then String1 = Left$(String1, I - 1) + RepString + Mid$(String1, I + Len(String2)+1 ) I = I + 2 DoEvents End If Loop While I =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The Visual Basic IDE 54.0 Is there any way to create an EXE without going into the IDE? Easy Compatibility:VB5 Right-click on the VB5 .vbp file and click "Make". =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 55.0 How can I create a window with a small title bar? Easy Compatibility:VB5 Just set the WindowStyle property to "Sizable Toolwindow" or "Fixed Toolwindow". =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 56.0 How can I show another form from a command button? Easy Compatibility:VB3 VB4 VB5 Start up VB. Create a new form. Create a second form named form2. Make a new command button named Command1. Put this code in the form: sub Command1_Click() form2.show end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 57.0 How do you make a message box that asks the user if they want to exit the program? Easy Compatibility:VB3 VB4 VB5 Do this: dim l as long l = msgbox("Are you sure you want to exit the program?",vbYesNo) if (l = 6) then 'don't exit else 'exit end if =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 58.0 How do I create message boxes with those cool red X's? Easy Compatibility:VB3 VB4 VB5 Easy. Try this: MsgBox "My Message", vbCritical, "My Title" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 59.0 Can I create a label that is vertically oriented? Easy Compatibility:VB3 VB4 VB5 Sure. Try this: dim s as string for i = 1 to len(label1) s = mid$(label1,i,1) & vbcrlf ' Replace vbcrlf with chr$(13) & chr$(10) next label1 = s =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 60.0 How come I get funny black boxes in my text box? Easy Compatibility:VB3 VB4 VB5 Set the multiline property of your text box to true. When it is false, you get black boxes instead of CRLF's. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 61.0 I want create a text box that displays "x" instead of the users input. Can I do that in VB? Easy Compatibility:VB3 VB4 VB5 Sure. Just set the PasswordChar property of the text box or rich text box to your favorite character. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 62.0 How can I run another program from a command button? Easy Compatibility:VB3 VB4 VB5 Start up VB. Create a new form. Make a new command button named Command1. Put this code in the form: sub Command1_Click() shell "c:\path\to\your\program.exe" end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 63.0 I want create a text box that displays "x" instead of the users input. Can I do that in VB? Easy Compatibility:VB3 VB4 VB5 Sure. Just set the PasswordChar property of the text box or rich text box to your favorite character. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 64.0 Why is it that Chr$(13) does not insert a new line? Easy Compatibility:VB3 VB4 VB5 In order to insert a new line, use the VB Constant vbCrLf, or use chr$(13) & chr$(10). =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 65.0 How can I undo the last action in a textbox? Easy Compatibility:VB3 VB4 VB5 Use this code: Sendmessage(myHwnd, EM_UNDO, 0 , 0) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 66.0 How can I create a textbox that let's you insert tabs? Easy Compatibility:VB3 VB4 VB5 Simply set tabstop on all the controls in a particular form to false. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 67.0 How can I use VB to view a JPEG, GIF, or XBM? Medium Compatibility:VB4 VB5 You can't do this with VB4 or earlier. You have to get a OCX or VBX. (Unless, of course, you have or had VB5CCE installed, in which case you can do it the same as in VB5). With VB5, you can use loadpicture, like this: picture1 = loadpicture("mypicture.jpg") picture2 = loadpicture("myotherpic.gif") Or, you can set the picture or icon property of any control at design time to a JPEG, GIF, or XBM. This technique works for GIF, JPEG, WMF, BMP, ICO, RLE, and XBM. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 68.0 How can I store a picture in the memory in VB, then PSet to it (and the other drawing functions) and copy it to a picture box to display it? Medium Compatibility:VB3 VB4 VB5 You need to create a second, invisible picturebox. Next, say you had pictureboxes named Picture1 and Picture2(Picture2 being the invisible one): picture2 = picture1 'do picture stuff picture1 = picture2 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 69.0 How do I implement hotkeys for text boxes? Medium Compatibility:VB3 VB4 VB5 Create a label with your hotkey. Set the tabindex of the label to one less then the TabIndex of the textbox. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 70.0 I would like to create a program that won't let the user in without a password. I want to make the password case insensitive. How can I do that? Medium Compatibility:VB3 VB4 VB5 Easy. Say you have a password text box named txtPass and a main form named frmMain. Put this code in the click event of the OK button on your pasword form: if lcase(txtPass) = "mypass" then frmMain.show else Msgbox "Invalid Password!" end if =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- User Interface 71.0 How can I tile a image on a form? Medium Compatibility:VB4 VB5 Put the following code in your form_paint: dim i as integer, j as integer for i = 0 to scalewidth step picture1.width for j = 0 to scaleheight step picture1.height paintpicture picture1.picture, i, j next next and replace picture1 with the name of your picturebox or imagebox control. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Variables 72.0 Is Variant slower then other types? Easy Compatibility:VB3 VB4 VB5 Yes. VB must determine the type of the variable for every access. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Variables 73.0 What does it mean to pass by reference? Medium Compatibility:VB3 VB4 VB5 When you pass by reference, you get the actual variable. (You pass by reference by default.) In contrast, when passing by value, you get a copy of the variable. The net effect is passing by value prevents you from changing the variable =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Variables 74.0 How should I format dates so that they look correct in all date and langauge formats? Medium Compatibility:VB3 VB4 VB5 Instead of defining your own format, like this: myStr = format$(myDate, "mm:dd:yy") use the predefined types, like this: myStr = format$(myDate, "Short Date") =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Variables 75.0 How can I get a pointer to a string, object, or variable? Medium Compatibility:VB4 VB5 For strings, use the undocumented function StrPtr. If you need a pointer to a object, use ObjPtr. Finally, if you need a pointer to a variable use VarPtr. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 76.0 How can I pass an array to a API function? Easy Compatibility:VB3 VB4 VB5 Pass the first element(usually zero) of the array. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 77.0 How can I undo the last action in a textbox? Easy Compatibility:VB3 VB4 VB5 Use this code: Sendmessage(myHwnd, EM_UNDO, 0 , 0) =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 78.0 What is NULL? Medium Compatibility:VB3 VB4 VB5 NULL is a constant equal to zero. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 79.0 How can I get a pointer to a string, object, or variable? Medium Compatibility:VB4 VB5 For strings, use the undocumented function StrPtr. If you need a pointer to a object, use ObjPtr. Finally, if you need a pointer to a variable use VarPtr. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 80.0 How can I put a toolbar in my application? Medium Compatibility:VB4 VB5 Create a new form with all your buttons on it. Under VB5, you'll want to set the border property to "4 - ToolWindow". Put the following declarations in a new module: declare Function SetWindowWord Lib "User32" (ByVal hWnd as Long, ByVal _ nIndex as long, ByVal nNewWord as long) as long Next, put the following code in the load event of the toolbar form. SetWindowWord Me.hWnd, -8, Main.hWnd Replace main with the name of your main form. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 81.0 How can I make a form "Always on top"? Medium Compatibility:VB4 VB5 Put this code in a module: Declare Function SetWindowPos Lib "user32" ( _     ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _     ByVal x As Long, ByVal y As Long, ByVal cx As Long, _     ByVal cy As Long, ByVal wFlags As Long) As Long Private Const SWP_NOSIZE = &H1 Private Const SWP_NOMOVE = &H2 Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 public sub SetFormOnTop(myForm as object) SetWindowPos myForm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE end sub =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 82.0 How can I find out the specifications for all those neat Enum* functions? Expert Compatibility:VB5 If you have VC++ or the MSDN subscription, just look up the Enum function and it will normally contain a link to the arguments specs. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 83.0 Egad! The SetFocus API won't work on some hWnds. (Like America Online.) What should I do? Expert Compatibility:VB4 VB5 Don't go crazy and use AppActivate, like some(names have been removed to protect the guilty) programmers. Use the SetForegroundWindow API. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 84.0 I'm writing a database system. How can I create a number that's is fairly unique, and feasible to implement for ID strings? Expert Compatibility:VB4 VB5 GUIDs, which windows uses to OLE resources, are farely random 128-bit numbers. Where I work we use them heavily to track items in a database. GUID's are great because the are unique. Well, Visual Basic 5.0 comes with a program that create them for you, but what a pain. Wouldn't it be nice to just do it via code? Well now you can with the sample code below. Private Type GUID Data1 As Long Data2 As Long Data3 As Long Data4(8) As Byte End Type Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any,ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long Public Function GetGUID() As String Dim pudtGUID As GUID Dim pstrGUID As String Dim pbytGUID() As Byte Dim plngRet As Long Dim plngLen As Long plngLen = 40 pbytGUID = String(plngLen, 0) CoCreateGuid pudtGUID plngRet = StringFromGUID2(pudtGUID, VarPtr(pbytGUID(0)), plngLen) pstrGUID = pbytGUID If (Asc(Mid$(pstrGUID, plngRet, 1)) = 0) Then plngRet = plngRet - 1 GetGUID = Left(pstrGUID, plngRet) End Function Compliments of David McCarter/Woody Pewitt =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Windows API 85.0 I'm trying to find a way to browse folders, as opposed to files. I can use VB or Win32 to get at files no problem, but haven't yet found a way to look at folders. I'd like it to work both on drive letter and UNC. Expert Compatibility:VB4 VB5 Use the SHBrowseForFolder API function. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-