Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

extracting nums

i got a field po which is "XXX/XXX/XXX" in the database
how do i extract XXX from it and put it 3 textboxes
like    
i have 3 textboxes seperated by "/" on a form....
how do i do that?
0
brohans
Asked:
brohans
  • 4
  • 2
1 Solution
 
percosolatorCommented:
If the data is always going to be "xxx/xxx/xxx" then use this code:


-------------------
Text1 = Mid$(MyString, 1, 3)
Text2 = Mid$(MyString, 5, 3)
Text3 = Mid$(MyString, 9, 3)
-------------------

If the data varies (I.E. "xx/xxx/x") then the coding is not as straight-forward.  Let me know, and I'll dig-out code and modify it to parse varying length fields separated by two "/"'s.

0
 
brohansAuthor Commented:
the string should be "xxx/xx/xxxx"
the method works but if there are changes like in the data?
like "xx/x/xxx" then how to extract them?
0
 
percosolatorCommented:
I will tell you if you don't give me a "D" again.... :)

Let me write the code, and I will post it after testing.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
percosolatorCommented:
ok... I tested the code for all possibilities that I could think of.  Should be water-tight.
--------------------------------
Option Explicit

Private Type mudtText3

    BadData As Boolean
    One As String
    Two As String
    Three As String
   
End Type

Private Sub Form_Load()

    Dim udtParse3 As mudtText3
   
    udtParse3 = Parse3("123/456/789")
    If (udtParse3.BadData) Then
        MsgBox "Bad Data"
    Else
        MsgBox udtParse3.One
        MsgBox udtParse3.Two
        MsgBox udtParse3.Three
    End If
   
    udtParse3 = Parse3("11//22")
    If (udtParse3.BadData) Then
        MsgBox "Uh Oh"
    Else
        MsgBox udtParse3.One
        MsgBox udtParse3.Two
        MsgBox udtParse3.Three
    End If
   
    udtParse3 = Parse3("1/22/333")
    If (udtParse3.BadData) Then
        MsgBox "A boo-boo."
    Else
        MsgBox udtParse3.One
        MsgBox udtParse3.Two
        MsgBox udtParse3.Three
    End If
   
    udtParse3 = Parse3("333/22/1")
    If (udtParse3.BadData) Then
        MsgBox "I don't know what to do."
    Else
        MsgBox udtParse3.One
        MsgBox udtParse3.Two
        MsgBox udtParse3.Three
    End If
   
    udtParse3 = Parse3("1/22-3333")
    If (udtParse3.BadData) Then
        MsgBox "MOMMY!"
    Else
        MsgBox udtParse3.One
        MsgBox udtParse3.Two
        MsgBox udtParse3.Three
    End If

    udtParse3 = Parse3("//")
    If (udtParse3.BadData) Then
        MsgBox "Oh S#$%!"
    Else
        MsgBox udtParse3.One
        MsgBox udtParse3.Two
        MsgBox udtParse3.Three
    End If
End Sub

Private Function Parse3(pstrParse As String) As mudtText3

    Dim udtText3 As mudtText3
   
    Dim intFirst As Integer, _
        intSecond As Integer
   
    intFirst = InStr(pstrParse, "/")
    intSecond = InStr(intFirst + 1, pstrParse, "/")
   
    'ensure that there are two "/"'s, exit the function
    If (intFirst * intSecond = 0) Then
        Parse3.BadData = True
        Exit Function
    End If
   
    udtText3.One = Left(pstrParse, intFirst - 1)
   
    udtText3.Two = _
                    Mid( _
                        pstrParse, _
                            intFirst + 1, intSecond - intFirst - 1)
                           
    udtText3.Three = _
                    Right(pstrParse, _
                            Len(pstrParse) - intSecond)
                           
    Parse3 = udtText3
   
End Function

--------------------------------

0
 
brohansAuthor Commented:
If (udtParse3.BadData) Then
             MsgBox "Bad Data"
what is the use of this?
0
 
percosolatorCommented:
To validate that you have good information in your database.

You don't have to have the if-then-else, but the code will not work if you have invalid data in your database.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now