×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

simple vb question

simple vb question

simple vb question

(OP)
I am writing a bit of code to run with a macro in SW. I have the following:

If txtNumber.Text <> IsNumeric Then
    MsgBox ("Use only numbers.")
    GoTo waithere
    End If

The IsNumeric give an error "The argument is not optional" I have a test box being populated with 5 characters I want to ensure that only numbers are uses else give the error "use only numbers"

Any thoughts on making this work.

Thanks,

Josh

RE: simple vb question

If you are using isnumeric then it should return some value like true or false.  So the arguement should also be given in your if statement stating the message box pops up for isnumeric value = true or false.  I havent done much VBA and am not a programmer, but I learnt VB once so I know this much.  Try passing an arguement as true or false for IsNumeric and it should work.

Regards

vik

RE: simple vb question

(OP)
I found a way to make this work.

If (Not IsNumeric(txtNumber.Text)) Then
    MsgBox ("Use only 5 digit number at end of file name.")
    GoTo waithere
    End If

RE: simple vb question

from VB help (where else???)

CODE

MyVar = "45 Help"    ' Assign value.
MyCheck = IsNumeric(MyVar)    ' Returns False.

I could be the world's greatest underachiever, if I could just learn to apply myself.
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: simple vb question

Just one question jmongan.  What is the purpose of the GoTo waithere?  Something I have not seen when using an event driven language like VBA (not even sure it is considered good progarmming practice anymore).

Regg

RE: simple vb question

(OP)
Regg,

To be honest with you I dont know the purpose. I am about 3 days into programming with VB. I found that code on the www, copied it and tweaked it to look for txt.number.txt.

RE: simple vb question

Regg

You're right, but you must be tolerant. Some of us are not programmers (or didn't learn this type of object/event driven language at school). Some hepful macros are done just "by gathering" some lines of code and a lot of trial and error. They may not look nice or reveal a good programming practice, but if they work then they are fine!

Regards

RE: simple vb question

GoTo isn't such a bad call, really.  It's not common, but sometimes nothing else will do.  I use it to break out of loops or set an exit/cleanup strategy for a subroutine (rather then just Exit Sub).  GoTo is also good for error handling.

"waithere" must be the name of a line in the program.  Look for a line that says "waithere:"--the colon denotes that it is the name for a line used for GoTo.

RE: simple vb question

If the help for your VB or VBA is unavailable, look for a file named "VBUI6.chm".  I keep a shortcut to it on my desktop.

RE: simple vb question

Very few programmers nowadays use "GOTO" command.

If you want users to limit data entry to 5 digit numbers, you should use the following two functions in VB (or VBA):

1. Set your text box length to 5;
2. Use "IsNumeric()" command.

Alex

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources