Skip to main content

Create Mask for the function gap detection

I created a script for the gap detection and build some code so that would check if a letter from a string is numeric or not. I got it working but what i don't understand is that every space, dot en minus sign is recognized by the IsNumeric function als numeric. Why is that? I would expected that only number would be a valid numeric. 

Brian Element Fri, 09/14/2018 - 18:42

HI Robert,

The reason why the - and period are considered numbers is that a number can be negative or it can have a decimal so this won't work for you.

Here is an alternate way to create your mask.


Option Explicit
Dim SampleRecord As String
Dim sMask As String

Sub Main
	Dim i As Integer
	Dim sChar As String
	SampleRecord = "Rob .ert10"
	
	'loop through each character
	For i = 1 To Len(SampleRecord)
		'extract each character
		sChar = Mid(SampleRecord, i, 1)
		'test to see if the character is numeric by testing its ASCII code
		If Asc(sChar) > 47 And Asc(sChar) < 58 Then
			sMask = sMask & "N"
		Else
			sMask = sMask & "C"
		End If
	Next i
	MsgBox sMask
End Sub