Solved

extracting nums

Posted on 1998-08-11
6
241 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
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!

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Copy a row 12 69
Protecting vb6 & .Net code Obfuscation 18 181
converting visio 2010 to powerpoint 2010  - formatting issues 5 108
VB script to continue despite error 2 48
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

735 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