Solved

extracting nums

Posted on 1998-08-11
6
232 Views
Last Modified: 2010-04-30
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
Comment
Question by:brohans
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
percosolator earned 50 total points
ID: 1468598
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
 

Author Comment

by:brohans
ID: 1468599
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
 
LVL 2

Expert Comment

by:percosolator
ID: 1468600
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:percosolator
ID: 1468601
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
 

Author Comment

by:brohans
ID: 1468602
If (udtParse3.BadData) Then
             MsgBox "Bad Data"
what is the use of this?
0
 
LVL 2

Expert Comment

by:percosolator
ID: 1468603
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now