Solved

extracting nums

Posted on 1998-08-11
6
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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