Results 1 to 7 of 7

Thread: Need help on VBasic Code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    133

    Post Need help on VBasic Code

    Hello there.

    I need help. I'm developing a Business program. Here are some of the problems I am working on.

    1. How could I make a text box ONLY allowing letters and spaces, but not numbers / special characters without using the MaskedBox control and making it uppercase.

    2. If I had a text box, or MaskedBox Control and I entered 30000 ... how could I automatically insert a decimal like 300.00 then when I set the focus back on the text back, put it back to 30000

    3. How can I automatically align text in a list box AND textbox/richbox control so I can get text & numbers to be aligned such as:


    assuming the ......... isn't there
    and the text is aligned to the left and numbers aligned to the right on the same line.

    DESCRIPTION OF ITEM... $1.00
    SOME OTHER ITEM...... $10.00


    4. How can I get records to load in a list box without waiting for the
    Do while not Data1.recordset.eof
    List1.additem data1.recordset![somefield]
    data1.recordset.movenext
    loop



    If anyone has time and could reply, I would greatly appreciate it! Thanks guys!

  2. #2
    Hyperactive Member DovyWeiss's Avatar
    Join Date
    Feb 2002
    Location
    Miami Beach, FL
    Posts
    366
    #1: In the KeyPress event (off the top of my head)
    VB Code:
    1. If Not (Instr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ", Chr$(KeyPress))) And KeyPress <> 8 Then KeyPress = 0

    #2: When it loses focus, divide the Val(myTextBox.Text) by 100 and use Format$() to get the format you want, then put it in. I suggest setting the Tag property to the old value. When it gets focus, set it back from the Tag.

    #3: Set the tab stops of the listbox/textbox using the SendMessage API. Check MSDN for examples. For listboxes, however, I prefer the ListView control which supports columns.

    #4: I'm not sure what you mean, but it sounds like you should data-bind the listbox.
    Last edited by DovyWeiss; Dec 23rd, 2002 at 06:26 PM.

  3. #3
    Hyperactive Member DovyWeiss's Avatar
    Join Date
    Feb 2002
    Location
    Miami Beach, FL
    Posts
    366
    I edited #1 and #2 above in my answer.

    Hope this solves everthing!

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    1) In the KeyPress event check for valid values of KeyAscii. Note that this does not stop someone from cutting and pasting invalid text.
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.     Select Case KeyAscii
    3.         Case 65 To 90 'A-Z
    4.         Case 97 To 122 'a-z
    5.         Case 48 To 57 'numbers
    6.         Case 8 'allow backspace
    7.         Case Else
    8.             KeyAscii = 0 'key is invalid
    9.     End Select
    10. End Sub

    2)I concur with DovyWeiss use the GotFocus/LostFocus events to set the value accordingly.

    3)Try a Fixed Width Font such as Courier New

    4)Not sure what you mean.

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    4. Add a DoEvents after adding to the listbox. This gives the listbox a chance to refresh and display the value which has just been added.
    VB Code:
    1. Do While Not Data1.Recordset.Eof
    2.     List1.Additem Data1.Recordset![somefield]
    3.     DoEvents    '<======
    4.     Data1.Recordset.MoveNext
    5. Loop

  6. #6
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    I think he wants all the dots to be under each other, or aligned to the right. He put an example:

    DESCRIPTION OF ITEM...$1.00
    SOME OTHER ITEM...... $10.00
    asdf

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    133

    Thanks

    The first 3 definately helped. Thanks guys!

    What I mean by the 4th question is this...

    Let's say I have a listbox with these selections

    BLUE SKY
    BLACK KNIGHT

    Both are choices to which you can make on a listbox.

    How would I get BLUE to be aligned to the left side of the listbox and SKY aligned to the right

    Same with BLACK.. aligned to the left, and KNIGHT aligned to the right.

    THANKS AGAIN!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width