i have sample code in vb6
can you pls help me convert to vb.net pls
here's my sample code
Function autoname(ctl2 As Control, KeyAscii As Integer)
Dim tem
Dim rtem
Dim tps
Dim css As Integer
Dim i As Integer
If KeyAscii = 8 Or KeyAscii = 13 Then
GoTo en
ElseIf KeyAscii >= 123 And KeyAscii <= 126 Then
KeyAscii = 0
GoTo en
ElseIf KeyAscii >= 91 And KeyAscii <= 96 Then
KeyAscii = 0
GoTo en
ElseIf KeyAscii >= 33 And KeyAscii <= 64 Then
KeyAscii = 0
GoTo en
ElseIf KeyAscii >= 65 And KeyAscii <= 90 Then
ElseIf KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
Else
KeyAscii = ValidChars(KeyAscii)
End If
If ctl2.SelLength = 0 Then
ctl2.Text = ctl2.Text & Chr(KeyAscii)
ElseIf ctl2.SelLength > 0 And KeyAscii = 32 Then
ctl2.Text = ctl2.Text & " "
ctl2.SelStart = Len(ctl2.Text)
KeyAscii = 0
Exit Function
ElseIf ctl2.SelLength > 0 Then
ctl2.Text = Left(ctl2.Text, Len(ctl2.Text) - ctl2.SelLength) & Chr(KeyAscii)
End If
ctl2.SelStart = Len(ctl2.Text)
If KeyAscii = 32 Then
If DoubleSpace(ctl2.Text) = " " Then
GoTo er
End If
tem = Trim(ctl2.Text)
tem = Split(tem, " ")
If Len(tem(UBound(tem))) > 2 And UBound(tem) > 0 Then
If InStr(tem(UBound(tem)), vbCrLf) = 0 Then
If Len(tem(UBound(tem))) > 2 Then List2.AddItem tem(UBound(tem))
Else
Dim ttem
ttem = Split(tem(UBound(tem)), vbCrLf)
If Len(ttem(UBound(ttem))) > 2 Then List2.AddItem ttem(UBound(ttem))
End If
Else
Set tem = Nothing
tem = Split(ctl2.Text, vbCrLf)
If InStr(Trim("" & tem(UBound(tem)) & ""), " ") = 0 Then
If Len(Trim("" & tem(UBound(tem)) & "")) > 2 Then List2.AddItem Trim("" & tem(UBound(tem)) & "")
Else
rtem = Split(Trim("" & tem(UBound(tem)) & ""), " ")
If Len(rtem(UBound(rtem))) > 2 Then List2.AddItem rtem(UBound(rtem))
End If
End If
'RemoveDups List2
er:
Else
tps = Split(ctl2.Text, " ")
If UBound(tps) = 0 Or InStr(tps(UBound(tps)), vbCrLf) > 0 Then
Set tps = Nothing
tps = Split(ctl2.Text, vbCrLf)
End If
css = Len(ctl2.Text)
For i = 0 To List2.ListCount - 1
If Len(tps(UBound(tps))) > 0 Then
If StrComp(tps(UBound(tps)), Left(List2.List(i), Len(Trim("" & tps(UBound(tps)) & ""))), vbTextCompare) = 0 Then
ctl2.Text = ctl2.Text & Right(List2.List(i), Len(List2.List(i)) - Len(Trim("" & tps(UBound(tps)) & "")))
ctl2.SelStart = css
ctl2.SelLength = Len(ctl2.Text) - css
Exit For
End If
Else
Exit For
End If
Next i
End If
If KeyAscii <> 13 Then KeyAscii = 0
en:
End Function
Private Sub text1_KeyPress(KeyAscii As Integer)
autoname text1, KeyAscii
End Sub
This post has been edited by jigulo: 12 October 2010 - 02:10 AM

New Topic/Question
Reply




MultiQuote





|