i have the following lines in excel 2003 macro and i would like to add default value = 0 to Inputbox both to fcutno and lcutno, how do i do that?

fcutno = InputBox("first CutNo#")
    comm.Parameters(0) = fcutno
    lcutno = InputBox("last CutNo#")
    comm.Parameters(1) = lcutno

thanks
gvilbis
gvilbisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
fcutno = InputBox("first CutNo#", "This is the Title", "this is the default")
0
[ fanpages ]IT Services ConsultantCommented:
Hi,

Further to MartinLiss' reply, I would also consider testing the value of the InputBox entry prior to setting the parameters.

For example, if you are expecting a numeric value to be entered:

  fcutno = InputBox("first CutNo#", "This is the Title", 0) 

  If IsNumeric(fcutno) Then
     comm.Parameters(0) = CLng(fcutno)
  Else
     comm.Parameters(0) = 0
  End If

Open in new window


...and similarly for the second parameter.


BFN,

fp.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Well as long as we're checking things you might also want to check if the Cancel button is clicked and you can do that like this

fcutno = InputBox("first CutNo#", "This is the Title", 0) 

Select case True
    Case StrPtr(fcutno) = 0
        Msgbox "You clicked 'Cancel'"
        Exit Sub ' Optional
    Case IsNumeric(fcutno)
        comm.Parameters(0) = CLng(fcutno)
    Case Else
     comm.Parameters(0) = 0
End Select

Open in new window

0
[ fanpages ]IT Services ConsultantCommented:
Case StrPtr(fcutno) = 0

...Yes, that does work at present, & you may also press the [Esc] key to "cancel" the input.

However, the use of the unsupported/undocumented function StrPtr() carries some risk in case it is ever removed from the Visual Basic for Applications code statement library in future updates to Microsoft Excel/Office/VBA.

A useful addition if there is a requirement for detection of cancelling the input value in any respect.
0
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.