realbasic-nug.it
[Top] [All Lists]

Re: numeri decimali

To: REALbasic NUG Italian <realbasic-nug dot it at lists dot realsoftware dot com>
Subject: Re: numeri decimali
From: Massimo Valle <maxduepuntozero at yahoo dot it>
Date: Sat, 23 Feb 2008 13:46:46 +0100
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug dot it at lists dot realsoftware dot com
References: <CA36FDEF-10B1-480B-9EE6-730DB0F14FA0 at tin dot it>

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.


<Prev in Thread] Current Thread [Next in Thread>