|
-
Oct 14th, 2004, 12:04 AM
#1
Thread Starter
Member
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
-
Oct 14th, 2004, 12:12 AM
#2
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.
-
Oct 14th, 2004, 12:15 AM
#3
VB Code:
Private Sub List1_DblClick()
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
-
Oct 14th, 2004, 12:24 AM
#4
that adds multiple CLS's ???
-
Oct 14th, 2004, 12:26 AM
#5
Thread Starter
Member
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?
-
Oct 14th, 2004, 12:27 AM
#6
have u seen this
VB Code:
txtBat.Text = "cls" & _
vbCrLf & txtBat.Text
-
Oct 14th, 2004, 12:29 AM
#7
Thread Starter
Member
No. I have no idea what that does. Will it help?
-
Oct 14th, 2004, 12:29 AM
#8
u mean u want to add something to the second line ?
-
Oct 14th, 2004, 12:30 AM
#9
No. I have no idea what that does. Will it help?
that reply was for dglienna
-
Oct 14th, 2004, 12:33 AM
#10
Thread Starter
Member
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.
-
Oct 14th, 2004, 12:40 AM
#11
how many lines are r there at the end. Just 1 line or more than a line ?
-
Oct 14th, 2004, 12:42 AM
#12
Thread Starter
Member
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.
-
Oct 14th, 2004, 12:48 AM
#13
VB Code:
Dim strTemp() As String
Dm 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
-
Oct 14th, 2004, 01:13 AM
#14
Thread Starter
Member
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
-
Oct 14th, 2004, 07:35 AM
#15
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:
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) from the down shift
strTemp(1) = List1.Text 'overwrite
txtBat.Text = Join(strTemp, vbCrLf)
I forgot the last part ... reassembly of the string with Join().
-
Oct 14th, 2004, 10:44 AM
#16
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:
Text1.SelStart = InStr(1, Text1.Text, vbNewLine) + 1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|