Solved

Find numeric part of a text field

Posted on 2007-04-01
3
223 Views
Last Modified: 2010-04-30
Hi,
   I have the house numbers coming from the MSAccess text field.
  (The database can be oracle, anyway)
  In my vb6 code I have to assign the next house no.
  A sample may be
  100
  200-A
  2-F
 40
 
 I want to see the numeric part of each of these and find the highest and add 1
 The requirment is to find the next house number  to propose .(In this case it should be 201)
   
0
Comment
Question by:sgs1970
[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
3 Comments
 
LVL 12

Expert Comment

by:StuFox100
ID: 18834903
hI sqs1970
This link has a few options on how to locate the numbers only:
http://www.thescripts.com/forum/thread388326.html
Using the above you should be able to convert the variables to an array of numbers and find the max.
Cheers
Stu
0
 
LVL 14

Accepted Solution

by:
Matti earned 125 total points
ID: 18835154
Hi!

This is a quick and simple function that I made for you.

Private Sub Command1_Click()
MsgBox finnumber("12 - A")
End Sub

Private Function finnumber(s As String) As String
Dim mychr As String * 1, myasc As Integer
For i = 1 To Len(s)
mychr = Mid$(s, i, 1)
myasc = Asc(mychr)
Select Case myasc
Case 48 To 57
finnumber = finnumber + mychr
Case Else
End Select
Next i
End Function


Matti
0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 18835296
i'd make a few amendments....
1/to handle addresses like 24A 22nd Street          you only want the 24.
2/ return a number.  an int would be ok usually but there are a couple of 33000 numbers around.

Private Function AddressNumber(sAddress As String) As long
      Dim mychr As String * 1, sTemp as string, i as integer
      For i = 1 To Len((sAddress)
            mychr = Mid$(s, i, 1)
            
            Select Case Asc(mychr)
                  Case 48 To 57
                        sTemp = sTemp & mychr
                  Case Else
                        if sTemp <> "" then
                              'have already found the number
                              'so stop looking
                              Exit For
                        end if
            End Select
      Next i
      AddressNumber = val(sTemp)
      
End Function
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!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 …
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…
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…

691 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