CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [VB6] - how mask the textbox?

    Quote Originally Posted by dglienna View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [VB6] - how mask the textbox?

    Look at the MASKED TEXTBOX. That's where you set a format, ONCE.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [VB6] - how mask the textbox?

    Quote Originally Posted by dglienna View Post
    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

  6. #6
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Smile 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
  •  





Click Here to Expand Forum to Full Width

Featured