Create Mask for the function gap detection

2 posts / 0 new
Last post
Robert van den ...
Offline
Joined: 08/08/2018 - 07:37
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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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