home *** CD-ROM | disk | FTP | other *** search
- DefInt A-Z
-
- Sub AddZeros (txt As Control, mask As String, dotcount As Integer, wheredot As Integer)
- If dotcount = 1 Then ' if a decimal is there
- string1$ = txt.Text ' assign text to temp string
- temp$ = Left$(string1$, wheredot - 1) ' if key is a decimal, shift dollars immediately
- trimtemp$ = RTrim$(temp$) ' to the left of the decimal
- nspaces = Len(temp$) - Len(trimtemp$)
- If InStr(mask, "$") > 0 Then ' leave dollar sign alone if there
- Mid$(string1$, 2, Len(temp$) - 1) = Space(nspaces) + Right$(trimtemp$, Len(trimtemp$) - 1)
- Else
- Mid$(string1$, 1, Len(temp$)) = Space(nspaces) + RTrim(temp$)
- End If
- For i = 1 To Len(txt.Text) ' add zeros after decimal if not there
- If Mid$(string1$, i, 1) > "/" And Mid$(string1$, i, 1) < ":" Then numthere = 1
- If i > wheredot And numthere = 1 And Mid$(string1$, i, 1) = " " Then Mid$(string1$, i, 1) = "0"
- Next i
- numthere = 0 ' reset
- txt.Text = string1$
- End If
- End Sub
-
- Sub IsADot (mask As String, dc As Integer, where As Integer)
- ' check to see if the mask contains a decimal
- dc = 0
- where = 0
- For i = 1 To Len(mask)
- If Mid$(mask, i, 1) = "." Then
- dc = dc + 1 ' n of decimals -> dotcount
- where = i ' location of decimal -> wheredot
- End If
- Next i
-
- End Sub
-
- Sub KeyData (txt As Control, ky As Integer, mask As String, dotcount As Integer, wheredot As Integer)
- ' ky is keyascii from a keypress event
- If ky <> 8 Then ' if ky not Backspace
- posn = txt.SelStart + 1 ' posn = 0 prior to this statement
- If posn > txt.MaxLength Then ky = 0: Exit Sub
- If posn < txt.MaxLength Then
- If ky = Asc(Mid(mask, posn, 1)) Then ' keep as a separate If statement
- txt.SelStart = txt.SelStart + 1 ' if cursor is just before immutable
- If Asc(Mid(mask, posn + 1, 1)) <> 32 Then
- txt.SelStart = txt.SelStart + 1 ' if 2nd immutable is there
- posn = posn + 1
- End If
- ky = 0 ' and immutable is typed, jump over it
- Exit Sub
- End If
- End If
- If (ky < 47 Or ky > 58) And ky <> 46 And ky <> 45 Then
- ky = 0 ' accept only numbers and decimals and a minus
- Exit Sub
- End If
- If dotcount = 1 And posn > wheredot And ky = 46 Then
- ky = 0 ' if a decimal is typed after the decimal pt.
- Exit Sub
- End If
- string1$ = txt.Text
- posn = txt.SelStart + 1 ' get cursor position
- Do While Mid(mask, posn, 1) <> " "
- posn = posn + 1 ' jump over an immutable char(s)
- Loop
- If dotcount = 1 And posn < wheredot And ky = 46 Then
- temp$ = Left$(string1$, wheredot - 1) ' if key is a decimal, shift dollars immediately
- trimtemp$ = RTrim$(temp$) ' to the left of the decimal and get ready to
- nspaces = Len(temp$) - Len(trimtemp$) ' enter cents
- If InStr(mask, "$") > 0 Then
- Mid$(string1$, 2, Len(temp$) - 1) = Space(nspaces) + Right$(trimtemp$, Len(trimtemp$) - 1)
- Else
- Mid$(string1$, 1, Len(temp$)) = Space(nspaces) + RTrim(temp$)
- End If
- posn = wheredot
- End If
- If (posn > Len(string1$)) Then 'if cursor is at the end then append keystroke to end
- string1$ = txt.Text + Chr$(ky)
- Else 'else place keystroke in correct position in text
- Mid(string1$, posn, 1) = Chr$(ky)
- End If
- txt.Text = string1$ ' reassign string to text
- txt.SelStart = posn
- ky = 0
- Else ' ky is a backspace
- string1$ = txt.Text
- posn = txt.SelStart ' get cursor position
- If posn > 0 Then
- If Mid(mask, posn, 1) = " " Then ' not an immutable character
- Mid(string1$, posn, 1) = " "
- Else
- If posn > 1 Then ' immutable character here
- Do While posn > 1 And Mid(mask, posn, 1) <> " "
- posn = posn - 1 ' backup over one or more immutables
- Loop
- Mid(string1$, posn, 1) = " " ' erase next char to left
- Else
- posn = posn + 1 ' immutable character in first column
- End If
- End If
- End If
- txt.Text = string1$
- If posn > 0 Then txt.SelStart = posn - 1 ' reposition cursor
- ky = 0 ' cancel the keystroke
- End If
- End Sub
-
- Sub KeyDelete (txt As Control, ky As Integer, mask As String)
- ' ky is keycode from KeyPress
- If ky = 46 Then ' delete pressed
- posn = txt.SelStart + 1
- If Mid$(mask, posn, 1) = " " Then ' not just to left of immutable char
- string1$ = Space$(Len(txt.Text))
- i = 1
- j = 1
- Do
- If i = posn Then j = j + 1 ' position of char being deleted
- If Mid$(mask, i, 1) <> " " Then ' an immutable
- Mid$(string1$, i, 1) = Mid$(txt.Text, i, 1) ' put immutable into string
- i = i + 1
- j = j + 1
- Else
- If Mid$(mask, j, 1) <> " " Then ' not an immutable
- x = 0
- Do
- x = x + 1
- Mid$(string1$, i, 1) = Mid$(txt.Text, j + x, 1)
- Loop Until Mid$(mask, j + x, 1) = " " Or j + x >= Len(txt.Text) - 1
- Else
- Mid$(string1$, i, 1) = Mid$(txt.Text, j, 1) ' put an immutable
- End If
- i = i + 1
- j = j + 1
- End If
- Loop Until i = Len(string1$)
- txt.Text = string1$ ' reassign Text
- txt.SelStart = posn - 1 ' reposition cursor
- Else
- ' cursor is immediately to the left of immutable char, so do nothing
- End If
- ky = 0 ' cancel the <delete> keystroke
- End If
-
- End Sub
-
- Sub PutCursor (txt As Control, mask As String)
- PlaceCursor = 1
- Do ' locate cursor after any immutable chars
- If Mid$(mask, PlaceCursor, 1) = " " Then Exit Do
- If PlaceCursor = Len(mask) Then Exit Do
- PlaceCursor = PlaceCursor + 1
- Loop
- txt.SelStart = PlaceCursor - 1
- End Sub
-
-