I need to copy text form a text box

for example:

My text box has


in it and i want to copy the text 18.5 i already have it selected i just need to copy it or put it into a var

Edited 7 Years Ago by drabsch: n/a

for copy

Clipboard.SetText text1.SelText

for paste in other textbox

text2.SelText = Clipboard.GetText()

First of all, var (variance takes up unneccesary space or memory. Declare your text as an integer. i.e.

dim x as Integer
x = Text1.Text

The next question is? - Where do you want to copy the the temperature Integer? Into a database or just for calculation. There is different options to what you want to do...

i found some info and i am using the code:

Private Function find(first, second)
pos = InStr(1, Text1.Text, first, vbTextCompare)
pos2 = InStr(1, Text1.Text, second, vbTextCompare)
start = pos + Len(first)
length = pos2 - start
Text1.SelStart = start
Text1.SelLength = length - 2
End Function

to find and select the text.

Now I understand. You wanted to search a text box when certain criteria is passed. You can also do the same with the following -

Option Explicit
Private Declare Function SendMessage Lib "User32" _
        Alias "SendMessageA" (byval _
        hWnd as Long, _
        byval wMsg as Integer, _
        byval wParam as string, _
        lParam as Any) as Long


Private Sub Form_Load()

    With List1
        .AddItem "18.5" 'or whatever you would like to add, whether from a file or database...
        End With

End Sub

Private Sub Text1_Change()
    List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, _
                      Text1, byval Text1.Text)
End Sub

Note that 'Sendmessage' generates errors in Vista....

This article has been dead for over six months. Start a new discussion instead.