Cool Visual Basic
 
Main
Frequently Asked Questions
VB Helpdesk
Message Boards
Library
Downloads
View Guestbook
Add to Guestbook
Product Reviews
Bookstore
Links
Newsgroups
Vendors
Affiliates
Cooltech.org

Cool VB FAQ


Text Format

The best Visual Basic FAQ(Frequently Asked Quesitions) file on the internet. Do you have a problem that's got you stumped? Do you have the answer to one? We've done our best to make this the best resources for the questions and the answers. Post a question, or a answer to one, by sending email to VBQA@beadsandbaubles.com.

      Root

            User Interface

  • How can I create a window with a small title bar?

    Compatibility:VB3  VB4  VB5

    Just set the WindowStyle property to "Sizable Toolwindow" or "Fixed Toolwindow".

     

     

  • How can I show another form from a command button?

    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
    

     

     

  • How do you make a message box that asks the user if they want to exit the program?

    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
    

     

     

  • How do I create message boxes with those cool red X's?

    Compatibility:VB3  VB4  VB5

    Easy. Try this:

    MsgBox "My Message", vbCritical, "My Title"
    

     

     

  • Can I create a label that is vertically oriented?

    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
    

     

     

  • How come I get funny black boxes in my text box?

    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.

     

     

  • I want create a text box that displays "x" instead of the users input. Can I do that in VB?

    Compatibility:VB3  VB4  VB5

    Sure. Just set the PasswordChar property of the text box or rich text box to your favorite character.

     

     

  • How can I run another program from a command button?

    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
    

     

     

  • I want create a text box that displays "x" instead of the users input. Can I do that in VB?

    Compatibility:VB3  VB4  VB5

    Sure. Just set the PasswordChar property of the text box or rich text box to your favorite character.

     

     

  • Why is it that Chr$(13) does not insert a new line?

    Compatibility:VB3  VB4  VB5

    In order to insert a new line, use the VB Constant vbCrLf, or use chr$(13) & chr$(10).

     

     

  • How can I undo the last action in a textbox?

    Compatibility:VB3  VB4  VB5

    Use this code:

    	Sendmessage(myHwnd, EM_UNDO, 0 , 0)
    

     

     

  • How can I create a textbox that let's you insert tabs?

    Compatibility:VB3  VB4  VB5

    Simply set tabstop on all the controls in a particular form to false.

     

     

  • How can I use VB to view a JPEG, GIF, or XBM?

    Compatibility:VB3  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.

     

     

  • 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?

    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
    

     

     

  • How do I implement hotkeys for text boxes?

    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.

     

     

  • 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?

    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
    

     

     

  • How can I tile a image on a form?

    Compatibility:VB3  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.

     

     

    LinkExchange
    LinkExchange Member Free Home Pages at GeoCities


    Copyright 2000, David J Berube<Form1@aol.com>. All Rights Reserved.