Written By TheVBProgramer.
This VB6 tutorial explains how the InputBox works. It Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a string containing the contents of the text box.
Usage:
stringvariable = InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
The arguments to the InputBox function are described below:
Argument |
Description |
prompt |
Required. String expression displayed as the message in the dialog box. The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used. |
title |
Optional. String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar. |
default |
Optional. String expression displayed in the text box as the default response if no other input is provided. If you omit default, the text box is displayed empty. |
xpos and ypos |
Both optional. Numeric expressions that specify custom positioning of the box on screen (by default, the box is displayed in the center of the screen, which is usually desired). |
helpfile and context |
Both optional. Can be used if a help file has been set up for the application. If either one of these arguments are used, they both must be used. |
Remarks
If the user clicks OK or presses ENTER , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string ("").
In the example given in the previous topic, an InputBox was used to obtain the user's name. Recall that a string variable (strName) was declared and used to store the result of the InputBox function:
Dim strName As String
strName = InputBox("Enter your name:", "Input Test")
Note that the InputBox function in this example used "Enter your name:" as the required prompt argument, and "Input Test" as the optional title argument (which caused that text to be displayed in the title bar of the dialog box). When the program was first run, the InputBox looked like this:

The user then entered his name into the text area of the InputBox:

When the user clicked OK, the string "Harry" was stored in the variable strName. Had the user clicked Cancel, the zero-length string ("") would have been stored in strName.
The next example shows how the default argument is used.
Let's say you need the user to enter an account number, but the majority of the time the program will be processing account "ABC-123". You could provide the string "ABC-123" as the third argument to InputBox:
strAcctID = InputBox("Enter account ID:", "Input Test", "ABC-123")
When the program is run, the text entered as the default argument shows up pre-filled and highlighted in the text entry area of the InputBox:

The user can either accept that and click OK, or they can type the "ABC-123" to enter whatever is required and then click OK.
If you wish, set up another "Try It" project, copy folder where you saved the original "Try It" project over to a new folder, open the copied project, and replace the cmdTryIt_Click event with the following code:
Private Sub cmdTryIt_Click()
Dim strAcctID As String
strAcctID = InputBox("Enter account ID:", "Input Test", "ABC-123")
Print "Data for account ID "; strAcctID; " will be processed."
End Sub
When you run the project and click the "Try It" button, the InputBox with the default entry as shown ablove will be displayed. If you accept it and click OK, the output should look like this:

Download the VB project files for the example above here.
inserting a function F(x) from input box.
Hello,
I have written a code that solves equations by several different numerical methods, such as newton raphson method, bi-section method,secant method,etc
Instead of changing the equation everytime in the code, I would like to input the equation F(x), for example F(X)=x^2-4,by using the input box.
But i have problems with the inputbox, is it possible to do this with inputbox?
Below private function is called from different private subs.
instead of;
Private Function F(X)
F =X^2-4
End Function
i would like user to input F(X) by inputbox as below, but it does not work..
Private Function F(X)
F =inputbox("please write the function F(X) for finding the roots by "Newton Raphson Method",F)
End Function
Thank You
declare F as String in Global
declare F as String in Global
inputbox in visual basic 6.0
we were using a frame to group controls inside a form, inside that frame are 4 option buttons , one of those option button says input box that activates a welcome message that has a code of
reply = inputbox ("type your name please", "sample inputbox", 1100, 150)
if reply ="larry" then
msgbox " hi larry! welcome", " sample message box"
if reply <> "larry" then
msgbox "access denied, you're an intruder", " log off!"
end
end if
but, whenever i play it it says compile error
our teacher says we must add something, she said something about a message box.
what do you think should i add?
Hi, I figured out your
Hi, I figured out your problem. At the end of your equation add
End If
End If
Instead of
End
End if
Tell MsgBox What Buttons To Display
When using the Message Box in this format, you must declare what type of buttons to display. For example your message box should be:
MsgBox " hi larry! welcome", vbOKOnly, " sample message box"
vbOKOnly = OK button on your message box
vbOKCancel = OK and Cancel buttons
vbAbortRetryIgnore = Abort, Retry and Ignore buttons
vbYesNoCancel = Yes, No and Cancel buttons
vbYesNo = Yes and No buttons
vbRetryCancel = Retry and Cancel buttons
I forgot to mention...
I should have mentioned, if you want to know what button was pressed on your message box start with a variable and use this format instead.
A = MsgBox (" hi larry! welcome", vbYesNo, " sample message box")
Don't forget to use the left and right brackets. The above example displays a message box with yes and no buttons. When one of them is clicked, the corresponding value is transfered to the A variable. For example, if Yes is clicked, A will equal 6. If No is clicked, A will equal 7. The following lists the numbers that are returned when they are clicked:
OK= 1
Cancel = 2
Abort = 3
Retry = 4
Ignore = 5
Yes = 6
No = 7
Hope this helps you.
can i insert option buttons
can i insert option buttons inside the inputbox
hi you can u help me i need
hi you can u help me i need to know how to write input box code but at the end you terminate that input box with the word end
You Jealous?
You Jealous?
how to coding search name use database in vb6 n use input box?
how to coding search name use database in vb6 n use input box?
inputbox
hi ,
if in inputbox user selects cancel instead of ok then i t gives error i.e. type mismatch ...
how i can solve it ...help me out
This no longer works in 2010
This no longer works in 2010
i want to input a name
i want to input randoms name only how can i? maximum 1-10 names
Need Help
how can i make user to use inputbox to enter integer only?
if user enter other than interger, such as string
msgbox will come out say error, need to insert number only, please try again
It would go like: If
It would go like:
If isnumeric(strVariable) then
dblVariable = strVariable
else
dummy = msgBox("You must input a variable!",vbcritical)
end if
I just put vbcritical in to be fancy.
printer code
how can used the button to print a text in the textbox to a printer using visual basic 6.0
Great!
Very good tutorial for beginners, great upload!
Search codes
what are the codes that can be used to search a record using input box in vb6 which is connected by datacontrol. please help me out
try: temp=
try:
temp= val(inputbox("enter number"))
Restrict the Characters
Hi...
i want to restrict the user to enter only the numbers from 1 to 9 in the input box. Can you please
reply as soon as possible with source code....
Thanks in advance....
enter 1-9 in a input box
try to use looping . if the user enter a invalid input, loop in inputbox. if the user enter a valid input exit the loop.
if i write following
if i write following code:
dim temp as integer
temp= inputbox("enter number")
' if i click on Ok button without giving default value and without entering any value in the input box, then program gives error, how can i debug it
how does one fix the problem
how does one fix the problem 'InputBox' is a namespace and cannot be used as an expression?
How to put helpfile [, helpfile, context]
Thanks for above information.
Can You Please provide me some example for putting Helpfile [, helpfile, context] in Inputbox.
Thnaks & Regards.
sab
hi this is user
thank u very much
thank you very much!
thank you very much!
:D
Pretty cool thanks
Post new comment