Solved

extracting nums

Posted on 1998-08-11
6
239 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 51
TT Auto Dashboard 13 95
vbModal 12 57
Copy a range from 1..n excel sheets to one destination sheet 2 55
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

792 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