-
I want format number of TextBox of VB6.0
I can't format Texbox.DataFormat. I want format TextBox type Number, i set syntax Texbox.DataFormat = "#,##0" (or "Number") my computer error in here
-
I beleave that option need DataField too.
Not use to type numbers in formated DataForm , its not function.
For display, format text box in Form_Load.
For edit, create function in TextBox_KeyPress our KeyDown/Up methods.
-
What error are you getting?
Try
Code:
Private Sub Text1_LostFocus()
Text1.Text = Format(Text1.Text, "#,##0")
End Sub
Last edited by Hack; 12-22-2010 at 07:10 AM.
-
It's work
Code:
'---------------------------------------------------------------------------------------
' Procedure : mask
' Author : http://www.vb4all.pl/content/view/226/25/
' Date : 22/12/2010
' Purpose : I found it in http://www.vb4all.pl/content/view/226/25/
' Instructions: Copy the declarations and code below and paste directly into your VB project.
' Controls: CommandButton name "Command1" and TextBox name "Text1"
'---------------------------------------------------------------------------------------
Option Explicit
Public massk As String
Function onlyNum(wj As String) As String
Dim d, i As Integer
d = Len(wj)
For i = 1 To d
If IsNumeric(Mid(wj, i, 1)) Then
onlyNum = onlyNum & Mid(wj, i, 1)
End If
Next i
End Function
Public Function mask(Inn As TextBox, msk As String)
Dim dlw As Integer
Dim dlm As Integer
Dim st As Integer
Dim Oout As String
Dim i, j As Integer
dlw = Len(onlyNum(Inn.Text))
dlm = Len(msk)
j = 0
' Function
For i = 1 To dlm
If Mid(msk, i, 1) = " " Then
j = j + 1
If dlw >= j Then
Oout = Oout & Mid(onlyNum(Inn.Text), j, 1)
st = i
Else
Oout = Oout & Mid(msk, i, 1)
End If
Else
Oout = Oout & Mid(msk, i, 1)
End If
Next
' This is my line - ThickF
' if last numer is not 0
If Mid(Oout, 5, 1) <> " " And Mid(Oout, 5, 1) <> "0" Then
Mid(Oout, 5, 1) = "0"
' End my line
End If
Inn.Text = Oout
Inn.SelStart = st
End Function
Private Sub Command1_Click()
Text1.Text = "1234567"
End Sub
Private Sub Form_Load()
massk = " , "
End Sub
Private Sub Text1_Change()
Call mask(Text1, massk)
End Sub
Private Sub Text1_GotFocus()
Call mask(Text1, massk)
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Call mask(Text1, massk)
End Sub
Similar Threads
-
Replies: 1
Last Post: 07-07-2006, 05:37 AM
-
By +Pablo in forum ASP.NET
Replies: 2
Last Post: 12-27-2005, 05:20 PM
-
By George in forum oracle.general
Replies: 0
Last Post: 04-01-2003, 01:00 AM
-
By George in forum oracle.general
Replies: 0
Last Post: 04-01-2003, 12:57 AM
-
By George in forum oracle.general
Replies: 0
Last Post: 04-01-2003, 12:56 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|