|
-
Jun 5th, 2000, 05:42 PM
#1
Thread Starter
Addicted Member
I am trying to write an algorithm that takes a PCN/mobile number and converts it to its new format. Eg 0956 will become 07956, 0370 will become 07770 etc etc I have all the rule sets and have nearly got there. The problem arises because the function must be designed to accept a whole PCN
find the prefix part and find the suffix part.
eg 0956 123456 --> 07956 123456
(normal 6 number suffix and normal 4 number prefix)
but what happens when the number is 0961 4258160 here there is a seven number suffix how do we know where to chop the suffix part????
Note virtually impossible to use length as prefix lengths can be 4/5/6/7 and suffix lengths can be 6/7. Has anyone got any ideas at all?
-
Jun 5th, 2000, 06:33 PM
#2
Fanatic Member
Something like this should do it.
You pass the number to change.
The old code.
The new code.
Code:
Private Function changeNumber(stNumber As String, stOld As String, stNew As String) As String
Dim ilen As Integer
ilen = Len(stOld)
If Left$(stNumber, ilen) = stOld Then
changeNumber = stNew & Right$(stNumber, Len(stNumber) - ilen)
End If
End Function
'e.g.
myNumber = changeNumber ("0956 123456", "0956", "07956")
myNumber = changeNumber (stCurrentNumber ,stOldCode, stNewCode)
Hope it helps
Iain, thats with an i by the way!
-
Jun 5th, 2000, 07:24 PM
#3
Fanatic Member
Sorry, just realised that my last post was complete crap.
This should be more like what you are after.
Code:
Option Explicit
'the number of code changes
Const iNumberOfCodes = 2
'the number of numbers needing cahnging
Dim iNumberOfNumbersToChange As Long
'array to hold numbers
Dim stNumberArray() As String
'type to hold rules
Private Type myCodeChange
stOldCode As String
stNewCode As String
End Type
'array of type
Dim myCodes(1 To iNumberOfCodes) As myCodeChange
Private Sub changeAllNumbers()
Dim i As Integer
'loop for as many number need to be changed
For i = 1 To iNumberOfNumbersToChange
'stNumberArray is the array of numbers that need changing
stNumberArray(i) = changeNumber(stNumberArray(i))
Next i
End Sub
Private Function changeNumber(stNumber As String) As String
Dim i As Integer
'iNumberOfCodes is the number of number changes.
'e.g. if you have 0123 = 012345 and 0234 = 9876
'then iNumberOf Codes = 2
For i = 1 To iNumberOfCodes
'if the oldcode = the start of number
If Left$(stNumber, Len(myCodes(i).stOldCode)) = myCodes(i).stOldCode Then
'change the codes around
changeNumber = myCodes(i).stNewCode & Right$(stNumber, Len(stNumber) - Len(myCodes(i).stOldCode))
Exit Function
End If
Next i
End Function
Hope that is better.
Opps. Got a bit wrong. Now it works 
[Edited by Iain17 on 06-06-2000 at 02:44 PM]
Iain, thats with an i by the way!
-
Jun 5th, 2000, 08:57 PM
#4
Fanatic Member
Opps, again i got it a bit wrong cos i didn't actually test it. That'l teach me.
The above code work now though.
Iain, thats with an i by the way!
-
Jun 6th, 2000, 07:59 PM
#5
Thread Starter
Addicted Member
This looks good!, thanks for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|