Test an input value for number

Test an input value for number

Anonymous
Not applicable
2,366 Views
4 Replies
Message 1 of 5

Test an input value for number

Anonymous
Not applicable

I have a macro which takes an input from a user form text box and stores it as a Double.  I need a way to test the input to make sure it is numerical before storing it, as it crashes the macro if the user enters a non-numerical input.  Is there a simple way to test for numerical input?  Thanx.

0 Likes
Accepted solutions (1)
2,367 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi LonesomeJoe,

 

You can use IsNumeric for this.

 

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Here's an iLogic example.

 

oInput = InputBox("Enter a number", "iLogic", "")

numericCheck = IsNumeric(oInput)

If numericCheck = True Then
MessageBox.Show("Input is numeric", "iLogic")
Else
MessageBox.Show("Input is NOT numeric.", "iLogic")
End If

 

VBA example:

 

 

Public Sub NumericCheck()
oInput = InputBox("Enter a number", "iLogic", "")

Dim NumericCheck As Boolean
NumericCheck = IsNumeric(oInput)

If NumericCheck = True Then
MsgBox ("Input is numeric")
Else
MsgBox ("Input is NOT numeric.")
End If

End Sub

 

 

EESignature

Message 3 of 5

Anonymous
Not applicable

Thanx, Curtis!  I knew there was a way to do this but I could not remember WHAT it was!  Thanx.

0 Likes
Message 4 of 5

estringer
Advocate
Advocate

Is there a way to get the numeric value from the InputBox and start PartsListNumber from that or add it to the PartsListNumber? I found some code that takes all of the parts lists from a DWG and creates a new tab in Excel for each instance but I would like to have some control over the numbering of the tabs so that the tabs align with the actual location/floor level on our project. See the code below.

 

		oInput = InputBox("Input the first floor level number below", "First Floor Level", "")

		numericCheck = IsNumeric(oInput)

		If numericCheck = True Then
		MessageBox.Show("Input is numeric", "iLogic")
		Else
		MessageBox.Show("Input is NOT numeric.", "iLogic")
		End If


        'specify the start cell
        oOptions.Value("StartingCell") = "A" & startRow

        'specify the XLS tab name
        'here the file name is used 
        oOptions.Value("TableName") = "Embeds For Level-" & PartsListNumber 'without extension

        'choose to include the parts list title row
        'in this example "Ye Old List of Parts" is written to the StartingCell 
        oOptions.Value("IncludeTitle") = False

        'choose to autofit the column width in the xls file
        oOptions.Value("AutoFitColumnWidth") = True

        ' export the Partslist to Excel with options
        oPartslist.Export(fileName, PartsListFileFormatEnum.kMicrosoftExcel, oOptions)

        PartsListNumber = PartsListNumber + 1
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Have you tried Val("StringNumericalValue"), or CDblAny("StringNumericalValue").  Both of those are in the 'System' iLogic snippets, under Strings.  But both are for returning Double (not Integer) data type from a String.  You could then attempt to convert the Double to an Integer using something like CInt() or Int(), also both in the System snippets under Math. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)