Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Default result of cancel in an input box

Posted on 1999-07-12
8
Medium Priority
?
215 Views
Last Modified: 2010-05-02
In a VB program I have an input box in which there is a ok button and a cancel button.  I would like to know how to change the default result of clicking the cancel button.  Right now it is set so that when the cancel button is clicked, "" is returned as a result.  The problem is that sometimes the input box is required to be blank.  As a result, any code to follow the cancel response "" (exit that part of the program), runs when someone enters a blank in the input box.  There has to be some way to get around this.  Any ideas?

Thanks in advance
Cat
0
Comment
Question by:Calico_Cat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1524023
Write your own inputbox function.
Not a lot of work..
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1524024
set the defaultvalue to be {BLANK} or a . or somthing and check for it in the return value
0
 

Author Comment

by:Calico_Cat
ID: 1524025
Thanks for the help guys, but the problem is, i don't know how to write my own input box function, I don't know how to change the default value.  That was what i was asking.  Help?...Please?....
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1524026
to write your own, just add a new form, put a textbox and two command buttons on it.  I can write one for you if you want.  Just post your email address so I can send it to you.
0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1524027
otherwise to use the defaultvalue method just do this>
retval = inputbox("Type input and press ok","Title",".")
if retval = "." then
    'the input was not canceled but the user did not type anything
elseif retval = "" then
    'The inputbox was canceled
else
    'the user typed somthing and did not cancel
end if
0
 

Author Comment

by:Calico_Cat
ID: 1524028
I am rejecting your answer as it has been BeedleGuis who has answered my question.  BeedleGuis i'll try resetting the default value but it you wouldn't mind showing me the code for creating your own input box i would really appreciate it.  If i don't use it in this case i could probably use it some other time.  Thanks both of you.  BeedleGuis the question points are open for you if you want them.  My email is csingle@ee.ualberta.ca
0
 
LVL 2

Accepted Solution

by:
BeedleGuis earned 200 total points
ID: 1524029
hopefully you have VB 6?  If not here is some sample code to use, just create a new form with two command buttons a label and a textbox.  Then place this code in the form replacing any control names as needed:

Option Explicit
Public Canceled As Boolean
Public StrValue As String
Private Sub Command1_Click()
    StrValue = Text1.Text
    Me.Hide
End Sub

Private Sub Command2_Click()
    StrValue = Text1.Text
    Canceled = True
    Me.Hide
End Sub
Public Sub PostOpen(sPrompt As String, sDefault As String, sTitle As String)
    Label1.Caption = sPrompt
    Text1.Text = sDefault
    Me.Caption = sTitle
End Sub


Then when you call the input box:
Use this

Private Sub Command1_Click()
Form2.PostOpen "Type Input", "", "Input Box"
Form2.Show vbModal
If Not Form2.Canceled Then
    MsgBox Form2.StrValue
Else
    MsgBox "Input Canceled"
End If

End Sub

instead of this:
Private Sub Command2_Click()
    Dim strval As String
    strval = InputBox("Type Input", "Input Box")
    If strval <> "" Then
        MsgBox strval
    Else
        MsgBox "Input Canceled"
    End If
End Sub

0
 

Author Comment

by:Calico_Cat
ID: 1524030
Thank you so much for the help.  It's actually working and this is a skill that i will be able to use over and over again. Thanks

Cat
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question