|
-
Nov 7th, 2005, 09:31 AM
#1
Thread Starter
Member
Repeating Numbers
Do anyone have any code that could tell if a series of nine numbers are repeating? I am checking to see if a SSN is all repeating numbers. For example, a person's SSN is 999999999.
Thanks
Shannon
-
Nov 7th, 2005, 09:47 AM
#2
Re: Repeating Numbers
VB Code:
Const TESTDATA = "999999999"
Dim lngIndex As Long
Dim bDifferent As Boolean
For lngIndex = 1 To 9
If Mid$(TESTDATA, lngIndex, 1) <> Left$(TESTDATA, 1) Then
bDifferent = True
Exit For
End If
Next
If bDifferent Then
MsgBox "They are not the same"
Else
MsgBox "They are the same"
End If
-
Nov 7th, 2005, 09:51 AM
#3
Thread Starter
Member
Re: Repeating Numbers
But it could be any numbers from 0-9. Would you have to create a function for each? I thought about testing positions 1 & 2 to see if they are the same and if they aren't exit the function and if they are test position 2 & 3 and then repeat the process. Would that work?
Thanks
Shannon
-
Nov 7th, 2005, 09:56 AM
#4
Re: Repeating Numbers
Just convert it to a string, and loop through checking to see if all of the characters are the same.
VB Code:
Private Function IsRepeating(lNumber As Long) As Boolean
Dim lTemp As Long, sTest As String, iCount As Integer
IsRepeating = True
lTemp = Left$(CStr(lNumber), 1)
sTest = CStr(lNumber)
For iCount = 1 To Len(sTest)
If Mid$(sTest, iCount, 1) <> CStr(lTemp) Then
IsRepeating = False
Exit For
End If
Next iCount
End Function
EDIT: Looks like MartinLiss beat me to it.
Last edited by Comintern; Nov 7th, 2005 at 09:58 AM.
Reason: Ooops!
-
Nov 7th, 2005, 11:09 AM
#5
Re: Repeating Numbers
 Originally Posted by odamsr
But it could be any numbers from 0-9. Would you have to create a function for each? I thought about testing positions 1 & 2 to see if they are the same and if they aren't exit the function and if they are test position 2 & 3 and then repeat the process. Would that work?
Thanks
Shannon
I just took what Martin posted, and put it into a Function. Just enter the number string you wish to test in text1.text
VB Code:
Option Explicit
Private Function AreNumbersAlike(plngCheckNum As Long) As Boolean
Dim lngIndex As Long
Dim bDifferent As Boolean
For lngIndex = 1 To 9
If Mid$(plngCheckNum, lngIndex, 1) <> Left$(plngCheckNum, 1) Then
bDifferent = True
Exit For
End If
Next
AreNumbersAlike = bDifferent
End Function
Private Sub Command1_Click()
If AreNumbersAlike(Val(Text1.Text)) Then
MsgBox "They are different"
Else
MsgBox "They are all the same"
End If
End Sub
Modify as necessary.
-
Nov 7th, 2005, 11:15 AM
#6
Fanatic Member
Re: Repeating Numbers
Just glanced over this thread..but if you are checking for valid SSN's to see if someone is just putting in bogus numbers...you could also just check the two center numbers. Aren't they the State? Those numbers could only be fifty different numbers. Sorry if I missed the point.
-
Nov 7th, 2005, 02:06 PM
#7
Member
Re: Repeating Numbers
 Originally Posted by birthjay
Just glanced over this thread..but if you are checking for valid SSN's to see if someone is just putting in bogus numbers...you could also just check the two center numbers. Aren't they the State? Those numbers could only be fifty different numbers. Sorry if I missed the point.
No that's not true, so it wouldn't work.
-
Nov 7th, 2005, 02:14 PM
#8
Addicted Member
Re: Repeating Numbers
VB Code:
dim i as byte
for i=1 to 9
if sSSN = string$(9, cstr(i)) then
msgbox "Bogus SSN"
exit for
end if
next i
-
Nov 7th, 2005, 03:30 PM
#9
Re: Repeating Numbers
odamsr, you might wajht to take a look at this thread.
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
|