Results 1 to 6 of 6

Thread: I got 2 probelms please help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    first probelm i want to take the first letter out of a textbox like say if the textbox.text = "Welcome" then i want A ="W"
    and then i want the textbox to say "elcome"

    second probelm

    i want it where they can only type in 0 and 1


  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Hi,there.
    Try this code:

    Dim a As String
    Dim b As String
    a = "Welcome"
    b = Mid(a, 2)
    Text1 = b

    It will return you "elcome". I didn't get what you want to do with "W"

    Larisa

  3. #3
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    For your secont question code:

    Private Sub Text1_KeyPress(KeyAscii As Integer)

    If KeyAscii > Asc("1") Or KeyAscii < Asc("0") Then
    KeyAscii = 0 'block the letters
    Exit Sub
    End If

    End Sub

    And if you want to display only one number , than you have to set MaxLength property to 1.
    But you going to run into one problem, you can delete number in a text box only by highligh and press delete. There probably should be additional code. I will try to play with that.

    Larisa


  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    OK. This is better:

    Private Sub Text1_KeyPress(KeyAscii As Integer)

    KeyAscii = IIf(KeyAscii = Asc("1") Or KeyAscii = Asc("0") Or KeyAscii = vbKeyBack, KeyAscii, 0)
    End Sub

    Larisa

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    lg no see i dont want to also get rid of the w i want to keep it as b and have text1.text be elcome and have b = w do you see

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    I don't think I got it. Do you want something like that:

    Dim a As String
    Dim b As String
    Dim s As String
    a = "welcome"
    b = Mid(a, 2)
    Text1 = b
    c = Mid(a, 1, 1)
    Text2 = c

    b will return you "elcome"
    c will return you "w"

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