Results 1 to 16 of 16

Thread: Adding Text To Textfield

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60

    Adding Text To Textfield

    I have a problem tat is when I double-click on a text (sentence or number), it will add to the textbox automatically, but it adds to the 1st line/top of the textbox. However, there is already something which I have declared at the top of the textbox. Can I modify my code so that if I double-click it, it will add to the lines after my 1st line and not b4 tat, so tat my 1st line will always be on the top of the text box and those I double-click on will add to the lines below my 1st line?

    My code:

    Private Sub List1_DblClick()
    txtBat.Text = "cls" & _
    vbCrLf & txtBat.Text
    txtBat.Text = "start /w Hi.vbs" & _
    vbCrLf & txtBat.Text
    txtBat.Text = "start telnet " & List1.Text & _
    vbCrLf & txtBat.Text

    End Sub

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    start it out with

    Private Sub List1_DblClick()
    txtBat.Text = txtBat.Text & _
    vbCrLf & "start /w Hi.vbs" & _
    vbCrLf & "start telnet " & List1.Text & _
    vbCrLf

    and it will be added to the bottom.

    you may have to modify it, as I took out the Cls, which I think that you wanted to have clear the text. I may have been wrong.

  3. #3
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    VB Code:
    1. Private Sub List1_DblClick()
    2.     If Len(Trim(txtBat.Text)) = 0 Then
    3.         txtBat.Text = "cls"
    4.     Else
    5.         txtBat.Text = txtBat.Text & vbCrLf & "cls"
    6.     End If
    7.     txtBat.Text = txtBat.Text & vbCrLf & "start /w Hi.vbs"
    8.     txtBat.Text = txtBat.Text & vbCrLf & "start telnet " & List1.Text
    9. End Sub

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    that adds multiple CLS's ???

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60
    Ok, thanks, I know what ur code does, it will attach the sentence right at the bottom of the textbox, but here is something really troublesome, that is right on top, there is something which I have to declare, which is the 1st sentence I told u about in my 1st post. Then right at the bottom there is also something I have to declare as well, so if ur codes add the sentence right to the bottom, it won't work as well. The ideal choice is to add it right below my first sentence, is there any way to do this?

  6. #6
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    have u seen this
    VB Code:
    1. txtBat.Text = "cls" & _
    2. vbCrLf & txtBat.Text

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60
    No. I have no idea what that does. Will it help?

  8. #8
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    u mean u want to add something to the second line ?

  9. #9
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    No. I have no idea what that does. Will it help?
    that reply was for dglienna

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60
    Yah, lets say that my textbox has already some default sentences.

    Tetxbox:

    1st line: This is my first line.

    3rd line: **This is where I want to insert the text when I double-click on it.**

    Last line: This is the end.

  11. #11
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    how many lines are r there at the end. Just 1 line or more than a line ?

  12. #12

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60
    There are no exact number of lines. Because I would want to add in more things manually again or maybe I would just double-click to add more sentence into the textbox. It would be best if all those that I double-click will just add right below my first sentence/line. Then there will be no errors.

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    VB Code:
    1. Dim strTemp() As String
    2. Dm lngLine As Long
    3.  
    4. strTemp = Split(txtBat.Text, vbCrLf)
    5. Redim Preserve strTemp(Ubound(strTemp) + 1)
    6. For lngLine = Ubound(strTemp) To 1 Step -1
    7.    strTemp(lngLine) = strTemp(lngLine - 1)  'shift lines down
    8. Next
    9. 'strTemp(0) = strTemp(1)
    10. strTemp(1) = List1.Text  'overwrite

  14. #14

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60
    Erm, I quite of get what ur code mean, it shift down the lines, rite. But how do I integrate it with my code?

    I tried it like tat but it didn't work:

    Private Sub List1_DblClick()

    Dim strTemp() As String
    Dim lngLine As Long

    strTemp = Split(txtBat.Text, vbCrLf)
    ReDim Preserve strTemp(UBound(strTemp) + 1)
    For lngLine = UBound(strTemp) To 1 Step -1
    strTemp(lngLine) = strTemp(lngLine - 1) 'shift lines down
    Next
    'strTemp(0) = strTemp(1)
    strTemp(1) = List1.Text 'overwrite

    If Len(Trim(txtBat.Text)) = 0 Then
    txtBat.Text = "cls"
    Else
    txtBat.Text = txtBat.Text & vbCrLf & "cls"
    End If
    txtBat.Text = txtBat.Text & vbCrLf & "start /w Hi.vbs"
    txtBat.Text = txtBat.Text & vbCrLf & "start telnet " & List1.Text
    End Sub

  15. #15
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Say you have..

    The quick red fox
    jumped over
    the lazy dog


    ...and List1.Text = "INSERTED TEXT"

    I assumed you wanted the output to be...

    The quick red fox
    INSERTED TEXT
    jumped over
    the lazy dog


    If thats the case then...

    VB Code:
    1. Dim strTemp() As String
    2. Dim lngLine As Long
    3.  
    4. strTemp = Split(txtBat.Text, vbCrLf)
    5. ReDim Preserve strTemp(UBound(strTemp) + 1)
    6. For lngLine = UBound(strTemp) To 1 Step -1
    7. strTemp(lngLine) = strTemp(lngLine - 1) 'shift lines down
    8. Next
    9. 'strTemp(0) = strTemp(1) from the down shift
    10. strTemp(1) = List1.Text 'overwrite
    11. txtBat.Text = Join(strTemp, vbCrLf)

    I forgot the last part ... reassembly of the string with Join().

  16. #16
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I think things are becoming overly complicated. Just make sure the first line in the text box contains the vbNewLine characters (vbCrLf) and then run the following code.

    VB Code:
    1. Text1.SelStart = InStr(1, Text1.Text, vbNewLine) + 1
    2.     Text1.SelText = "Inserted Text" & vbNewLine

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