capture text

usetheforce2
10-01-2001, 01:15 PM
hey all,

i'm writting an app the requires the user to type in lines of code at a command prompt. When the user presses enter, i want to be able to capture the new line of text the user entered...

Exmaple

080A = CC 04 7B <- user pressed "ENTER"
080B = 86 12 34 <- user pressed "ENTER"
080C = 17 C6 7B <- user pressed "ENTER"

so everytime the user hits enter i would like to get the last line entered (080C = 17 C6 7B) . For this i was using the SelStart, SelLength and SelStart properties of the list box. The problem is that is removes the text from the text box, rather than copy it!!

this is my code:

<pre><font color=blue>Private Sub</font color=blue> text1_KeyPress(KeyAscii <font color=blue>As Integer</font color=blue>)

<font color=blue>Static</font color=blue> Position <font color=blue>As Integer</font color=blue>

<font color=blue>If</font color=blue> KeyAscii = 13 <font color=blue>Then</font color=blue> <font color=green>'&lt;- return</font color=green>
<font color=green>' set start position of last carriage return</font color=green>
text1.SelStart = Position
<font color=green>' get length of new characters since last "enter"</font color=green>
text1.SelLength = Len(text1.Text) - Position
<font color=green>' reset the position for the next carriage return</font color=green>
Position = Len(text1.Text) + 1
<font color=green>' save new text in variable to be proccessed</font color=green>
mystr = text1.SelText
<font color=blue>End If</font color=blue>

<font color=blue>End Sub</font color=blue>

</pre>

any suggestions would be great!

Regan



"The crows seem to be calling his name, thought Caw." - Jack Handy

hashir56
10-01-2001, 01:20 PM
i whould suggest going throght each line by splitting it into an array using the Split metoad and vbcrlf as the thing that devides it. Each time it goies though an index of the array it sees if it is the last line. if it is, it reurns it. Its whould a pritty long thing though.

ChiefRedBull
10-01-2001, 01:26 PM
I would use the Mid$ function instead.
Something along these lines......
<pre><font color=red>Private Sub text1_KeyPress(KeyAscii As Integer)

Static Position As Integer

If KeyAscii = 13 Then '&lt;- return
myStr = Mid$(Text1.Text,Position,Len(Text1.Text-Position))
Position = Len(Text1.Text)+1
End If

End Sub

</pre></font color=red>

Chief


"How are we to learn, if those that know will not teach... ?" - Me.

hashir56
10-01-2001, 01:33 PM
An exampe of the funtion whould go like this:
Private Function GetLastLine(Text as String) As String
Dim sTemp() As String
Dim LastLine As String
sTemp() = Split(Text, vbCrLf)
Text = Trim(Text)
For i = LBound(sTemp) To UBound(sTemp)
LastLine = sTemp(i)
endI:
Next i
GetLastLine = LastLine
end function
just make shure it is before the doevents becase if it goes to another line before the function is called then it'll reurn the new blank line

ChiefRedBull
10-01-2001, 01:41 PM
Thats a good idea Hashir! Using an array - you could store the typed commands and save them to a log or something images/icons/smile.gif
I'm a little confused about your function though -
whats the point of trimming the Text -
<font color=red>Text = Trim(Text) </font color=red>
AFTER youve just read it into the array?
Also, what does
<font color=red>endI:</font color=red>
do?

Chief

"How are we to learn, if those that know will not teach... ?" - Me.

hashir56
10-01-2001, 01:49 PM
yea those 2 were two things i was playing around with. I guess i forgot it erace. images/icons/wink.gif

usetheforce2
10-01-2001, 02:02 PM
thanks guys thats what i was lookin for!

"The crows seem to be calling his name, thought Caw." - Jack Handy

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum