Text1_KeyPress

emia
08-08-2009, 04:16 AM
I have Problem:

Text1.Text ; MultLine = True

I need Real-Time to catch that string. First I need get last_line that string, detect last_line , is enter type "="

if first char is enter "=" ,
Text1.BackColor = RED
And if same_line that Last char is same "="
Doing Msgbox, String, Something

if same_line, only Left "=", and vbCrLf
Text1.BackColor = YELLOW


this code where wrong please!


Problem (1)
Use Option Explicit;
How to correct "Dim yyy As String/Long/Integer... ? ;

Problem (2)
If Text1.Text only press ENTER, that Array() Error #9
"Run-time error '9': Subscript out of range"

Problem (3)
I no sure total need "lines" in Text1.Text, if used
Dim line_to_Array(65535) As String 'Is large problem ?

Problem (4)
What mean "8454016" ?





'Option Explicit


'///////////////////////////////////////

Private Sub Form_Load()
Text1.Text = ""

'Dim line_to_Array() As Variant
Dim last_string As String
Dim output_A As String


End Sub


'//////////////////////////////


Private Sub Text1_KeyPress(KeyAscii As Integer)

'Detect:
'Step 1 , Get Last Line Text String

If KeyAscii = 13 Then
line_to_Array = Split(Text1.Text, vbCrLf)
'
If IsArray(line_to_Array) = True Then
last_string = line_to_Array(UBound(line_to_Array))
Else
last_string = ""
End If




End If



'Step 2,
'Confirm First Chr = "=" Chr(61)
'Text1.BackColor = &HC0C0FF 'red

If Mid$(last_string, 1, 1) = Chr(61) Then
Text1.BackColor = &HC0C0FF


'If confirm First,Left 1 = Chr(61), and Right 1 = Chr(61)
If Mid$(last_string, Len(last_string), 1) = Chr(61) Then

'Text1.Text = &H80FF80 'green
Text1.Text = &H80FF80

'"=Text Happy=" Return "Text Happy"
output_A = Mid$(last_string, 2, Len(last_string) - 2)

Debug.Print output_A
Exit Sub

End If





End If 'Left=




End Sub '/Private Sub Text1_KeyPress(KeyAscii As Integer)

emia
08-08-2009, 06:49 AM
I found unknow bug ?
I enter =ABCD= + ENTER

SHOW THIS ?
8454016

What is this "8454016" ?

vb5prgrmr
08-08-2009, 10:57 AM
First problem is that you have Option Explicit commented out, uncomment it!

Next problem is you are setting the text of text1 to &H80FF80 which equals 8454016...

In immediate window type in...

?&H80FF80

and you will get 8454016

but I see above that you are setting the backcolor of the text1 to what looks like red. Is that what you are trying to do with &H80FF80? That is set the backcolor of text1?


Good Luck

emia
08-08-2009, 11:12 AM
oh, is Text1.Text = &H80FF80
= Text1.BackColor = &H80FF80

(1) but can you tell me Option Explicit, how to Correct DIM it?

(2) How to make-sure is that line, the first char "=" , changed BackColor?
"=AB CD, changed .Backcolor to "RED"
"ab=cd, no changed? , nothing

(3) When Confirm is enter First Char "=", but is no correct, press "backspace" or "delete" first "="
how to .BackColor to "white" ?


If KeyAscii = 61 Then
Text1.BackColor = &HC0C0FF 'red
End If


thanks!




'Option Explicit

'///////////////////////////////////////

Private Sub Form_Load()
Text1.Text = ""

Dim last_string As String
Dim output_A As String


End Sub


'//////////////////////////////


Private Sub Text1_KeyPress(KeyAscii As Integer)

'Detect:
'Step 1 , Get Last Line Text String
'Dim line_to_Array() As Variant

Dim last_string As String
Dim output_A As String
Dim c As String

c = Text1.Text



'detect last_line press First Chr "=", that Text1.BackColor = red? "
'Correct ?
If KeyAscii = 61 Then
Text1.BackColor = &HC0C0FF 'red
End If




If KeyAscii = 13 Then 'press enter
line_to_Array = Split(c, vbCrLf)
'
If IsArray(line_to_Array) = True Then
last_string = line_to_Array(UBound(line_to_Array))
Else
last_string = ""
End If

End If



'Step 2,
'Confirm First Chr = "=" Chr(61), 'Text1.BackColor = &HC0C0FF 'red

If Mid$(last_string, 1, 1) = Chr(61) Then
'Text1.BackColor = &HC0C0FF 'red <!-Nothing


'If confirm First,Left 1 = Chr(61), and Right 1 = Chr(61)
If Mid$(last_string, Len(last_string), 1) = Chr(61) Then

Text1.BackColor = &H80000005 'white



'"=Text Happy=" Return "Text Happy"
output_A = Mid$(last_string, 2, Len(last_string) - 2)

Debug.Print output_A
Exit Sub

End If





End If 'Left=


'//






End Sub '/Private Sub Text1_KeyPress(KeyAscii As Integer)



'/////////////////////////////////

vb5prgrmr
08-08-2009, 07:56 PM
1 Just remove the single tick from in front of it.

2 and 3 Not quite sure of what you are trying to say but here are some string handling functions to look up in VB's help

Len
Left
Mid
Right
Instr
UCase
LCase


Good Luck

emia
08-08-2009, 11:47 PM
would you help me this code is oke?
But I no feel to Detect "Left,1 = "=" ?


Option Explicit


Private Sub Form_Load()
Text1.Text = ""

End Sub

'//////////



Private Sub Text1_KeyPress(KeyAscii As Integer)

'Detect:
'Step 1 , Get Last Line Text String

Dim last_string As String
Dim output_A As String
Dim c As String
Dim line_to_Array() As String

c = Text1.Text




If KeyAscii = 8 Then
Text1.BackColor = &HFFFF& 'yellow
End If


If KeyAscii = 61 Then
Text1.BackColor = &HC0C0FF 'red
End If




'Debug.Print KeyAscii, Len(c), InStr(c, vbCrLf)


If KeyAscii = 13 And Len(c) > 0 Then 'press enter
line_to_Array = Split(c, vbCrLf)
last_string = line_to_Array(UBound(line_to_Array))
End If '//If KeyAscii = 13 And Len(c) > 0 Then 'press enter



'/$$$
Debug.Print IsArray(line_to_Array), last_string



'Step 2,
'Confirm First Chr = "=" Chr(61)

If Mid$(last_string, 1, 1) = Chr(61) Then

If Mid$(last_string, Len(last_string), 1) = Chr(61) Then
Text1.BackColor = &H80000005 'white
output_A = Mid$(last_string, 2, Len(last_string) - 2)
Text1.Text = Text1.Text & vbCrLf & "<" & output_A & ">" & vbCrLf
Text1.SelStart = Len(Text1.Text) + 1
' Debug.Print output_A
Exit Sub

End If

End If '//If Mid$(last_string, 1, 1) = Chr(61) Then



'//






End Sub '/Private Sub Text1_KeyPress(KeyAscii As Integer)

vb5prgrmr
08-09-2009, 11:39 PM
Okay, are you trying to detect the equals sign (=) and to see if it is the first character of a string? If so then...


If Left(SomeString, 1) = "=" Then

Or

If Mid(SomeString, 1, 1) = "=" Then



Good Luck

emia
08-10-2009, 04:48 AM
Thanks.
When start Form1, type "A"
only
List1.Additem "97"
List1.Additem "" ? empty ?

I not understand why "empty" ?

Please!



Private Sub Form_Load()
Text1.Text = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
List1.Clear

Dim t1 As String
t1 = Text1.Text

List1.AddItem KeyAscii
List1.AddItem Mid$(t1, 1, 1)


End Sub

vb5prgrmr
08-10-2009, 04:47 PM
Okay, the reason the list is empty is because the .AddItem method is expecting a string and you are passing it an integer. So...

Private Sub Text1_KepPress(KeyAscii As Integer)
List1.AddItem Chr(KeyAscii) & "=" & CStr(KeyAscii)
End Sub



Good Luck

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum