Can anyone help me how to do this?
It will test if it is valid or invalid.
Input Output
name_123 Valid
name123 Valid
123name invalid
123_name invalid
this will test if the variable name declared is valid or invalid.
Can anyone help me how to do this?
It will test if it is valid or invalid.
Input Output
name_123 Valid
name123 Valid
123name invalid
123_name invalid
this will test if the variable name declared is valid or invalid.
use the mid function..
dim xstr, xstr1 as string
xstr1 = "123name"
xstr = mid(xstr1, 1, 1)
if xstr = "1" then
Msgbox "Invalid"
else
Msgbox "Valid"
end if
Input Output
name_123 Valid
name123 Valid
123name invalid
123_name invalid
Don't really know what you're criteria for a valid filename is since you didn't mention the criteria: that might be helpful. But it appears that you 're not allowed to start the name with a number?
Private sub CheckName()
dim strName as String
strName = txtInput
if isNumeric(left(strName, 1)) then
msgbox "Invalid Name", vbInformation, "String Validation"
Else
msbBox "Valid Name", vbInformation, "String Validation"
Endif
End sub()
Don't really know what you're criteria for a valid filename is since you didn't mention the criteria: that might be helpful. But it appears that you 're not allowed to start the name with a number?
Private sub CheckName() dim strName as String strName = txtInput if isNumeric(left(strName, 1)) then msgbox "Invalid Name", vbInformation, "String Validation" Else msbBox "Valid Name", vbInformation, "String Validation" Endif End sub()
Actually, they want to test the declared variable name, i.e. Dim/Public/Private/Const
However, before I get to that let me suggest I would change your code to test with IsNumeric(Left(...
Now, to answer the origional posters question. Off the top of my head there are only two ways to accomplish what you want. One is to build an Add-In that will check the variables declaration statement and issue a warning if declared wrong.
The second is much easier. Build another program that opens the vb project files (you can read them in notepad to get a head start) and search for the declaration statements of variables. Then check those declarations against the rules you want to apply. Then if you find an incorrectly declared variable you can prompt yourself with whatever information you deem necessary to be able to do a find and replace.
Good Luck
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.