On 23/feb/08, at 12:46, Lucio Liberi wrote:
Sto provando a scrivere qualcosa in KeyDown, ma non riesco, anche se
adesso sono diventato un genio... Lui capisce che ho pigiato '.' e
qualcosa la fa, ma non riesco...
Dim tempstring As string
if Key="." then
tempstring=replace(me.text,".",",")
me.text=tempstring
end if
sembra facile, ma quando entro il punto '.' lui me lo mette davanti
ai numeri già inseriti:
123. ---> .123
cioè, intercetta il punto, ma lo mette all'inizio del testo.
Come se scrivere
me.text=tempstring
portasse il 'cursore' all'inizio della stringa...
Questo è troppo, anche per me che sono un genio...
Grazie.
L.
Function KeyDown(Key As String) As Boolean
if key = "." then
dim insertionPoint as integer = me.selStart
if instr(me.text, ",") = 0 then
me.text = left(me.text, insertionPoint) + "," + mid(me.text,
insertionPoint+1)
me.selStart = insertionPoint+1
end if
return true
end if
End Function
In ogni caso io trovo sia meglio utilizzare l'evento TextChange.
Massimo Valle
P.S: la procedura sopra riportata non tiene conto di altri possibili
casi.
|