-
April 13th, 2014, 04:00 AM
#1
[VB6] - how mask the textbox?
i'm building a data base program, using the data control. but the mask edit control isn't updated(only when i execute the program). so i'm trying transform the textbox for use these mask: "AA-AA-AA" (i belive the 'A' is for accept numbers and letters). but i don't get right results or i don't use the right event
can anyone advice me, please?
heres my actual code:
Code:
Private Sub Text1_Change()
Text1.text = FormatText(Text1.text)
End Sub
Private Function FormatText(text As String) As String
Dim i As Long
Dim newstring As String
For i = 1 To Len(text)
newstring = newstring & Mid(text, i, 1)
If IsMultiple(i, 2) = True And i + 1 <= Len(text) Then newstring = newstring & "-"
Next
FormatText = newstring
End Function
Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
If Number Mod Multiple = 0 Then
IsMultiple = True
End If
IsMultiple = False
End Function
-
April 13th, 2014, 11:17 AM
#2
Re: [VB6] - how mask the textbox?
You always end up setting to FALSE
Code:
Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
If Number Mod Multiple = 0 Then
IsMultiple = True
End If
IsMultiple = False
End Function
Set the FALSE condition BEFORE you check the Mod.
-
April 13th, 2014, 11:53 AM
#3
Re: [VB6] - how mask the textbox?
Originally Posted by dglienna
You always end up setting to FALSE
Code:
Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
If Number Mod Multiple = 0 Then
IsMultiple = True
End If
IsMultiple = False
End Function
Set the FALSE condition BEFORE you check the Mod.
you have right. but now i'm rebuild the function for just 1 function, but i continue with errors
Code:
Private Function FormatText(Text As String) As String
Dim i As Long
Dim newstring As String
If Text = "" Then FormatText = ""
For i = 1 To Len(Text) - 1 Step 2
newstring = newstring & Mid(Text, i, 2)
newstring = newstring & "-"
Next
FormatText = newstring
End Function
i need convert any string to style: "AA-AA-AA"
but i must review the function
-
April 13th, 2014, 01:42 PM
#4
Re: [VB6] - how mask the textbox?
Look at the MASKED TEXTBOX. That's where you set a format, ONCE.
-
April 13th, 2014, 01:48 PM
#5
Re: [VB6] - how mask the textbox?
Originally Posted by dglienna
Look at the MASKED TEXTBOX. That's where you set a format, ONCE.
but seems not be updated, when i 'scrool' the records using the Data control
-
April 14th, 2014, 03:37 PM
#6
Re: [VB6] - how mask the textbox?
You can try one of the following way .as Dglinena suggested in #2.
Code:
Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
If Number Mod Multiple = 0 Then
IsMultiple = True
Else
IsMultiple = False
End If
End Function
Function IsMultiple(ByVal Number As Integer, ByVal Multiple As Integer) As Boolean
If Number Mod Multiple = 0 Then
IsMultiple = True
exit function
End If
isMultiple=false
End Function
Last edited by firoz.raj; April 14th, 2014 at 04:00 PM.
Reason: Correction
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
|
Click Here to Expand Forum to Full Width
|