Link to home
Start Free TrialLog in
Avatar of coldfirre
coldfirre

asked on

InputBox without OK or Cancel

I am getting a user to key in 3 fields whereby there is no need for the user to click OK or Cancel in VB. I used InputBox but the user has to click OK to move on to the next box. Is there any way to work around this?

I am using VB 6.0.. Thanks for any advise..
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

>>I am getting a user to key in 3 fields whereby there is no need for the user to click OK or Cancel in VB
>>Is there any way to work around this?

try create your own form, and place your textboxes there, I think that mostly make sense to your requirement.

You can then call that form by using command like this:

...
yourFormName.show vbmodal
..
Avatar of coldfirre
coldfirre

ASKER

i am using this in an application that does not allow to create my own forms. this app is a vb6.0 application. calling vb functions will be ok, but not to the extent of creating my own forms. any other solutions?
>>I am getting a user to key in 3 fields whereby there is no need for the user to click OK or Cancel in VB

if user no need to click OK or Cancel button, how can we know the user has finished entering the value? Anyway, OK and Cancel buttons are built-in for inputbox, don't think you can hide it generally.
they are supposed to scan using a handheld scanner. so after each time there is an insertion, it should automatically go to the next inputbox..
Just not too sure if inputbox is best suit you here...

if you want use inputbox, you may try like this:

Private Sub Command1_Click()
    Dim v1 As String, v2 As String, v3 As String
    v1 = InputBox("Enter value 1", "Value 1")
    If v1 <> "" Then
        v2 = InputBox("Enter value 2", "Value 2")
        If v2 <> "" Then
            v3 = InputBox("Enter value 3", "Value 3")
            If v3 <> "" Then
                MsgBox "v1 = " & v1 & vbCrLf & _
                       "v2 = " & v2 & vbCrLf & _
                       "v3 = " & v3
            End If
        End If
    End If
End Sub
If it is a hand held scanner (like bar code); it should add a carriage return after a scan.  You could have it read a text line or text area and submit once it detects a CR.
Deadite is correct most handheld scanners add a Carraige return as the last character of the scanned text (barcode)

So you can add code on the KeyUp event of your textbox(s) to either move to the next textbox or submit your form.....I'm not sure you'll be able to do this with an inputbox though.

Private Sub txtScannedText_KeyUp(KeyCode As Integer, Shift As Integer)
   if trim(txtScannedText) <> "" then
       If KeyCode = vbKeyReturn Then
           ' set focus to next textbox on form OR
           'if all textboxes have values entered then submit form
       End If
   endif
End Sub
 
hi guys.. thanks for all the inputs.. i will try out to see if the inputbox will work with the handheld scanner..if you think i can use something other than the inputbox do let me know..

once i work it out.. will give the points! thanks..
as ryancys says ideally you'd build your own form rather than use inputbox as you'd have more control over how/what the user inputs and can validate what has been entered.

Not sure why your say you are "using this in an application that does not allow to create my own forms", being that this is a VB6.0 application surely if your writing code to open and read the InputBox you could create your own form to accept the values the Inputbox will recieve???
i am not totally sure about being able to create my own forms in the application itself. however i do know that i can call an activex or exe or a custom made vb app to work with the application.

if so, how can i create a form just for the user to key in 3 fields of which the first 2 fields must be equal. i checked on the handheld scanner, it does not seem to provide a carriage return after scanning. so i may have to write something that will cater for automatic return. any thoughts?

Maybe we're not on the same page here?

Your "Application" is a VB6.0 App isn't it? I assume you have access to the source code as you say you can "call an activex or exe or a custom made vb app to work with the application."  I'm assuming you will need to modify your "Application" in order to do this? Why then couldn't you add a new form within the Application?

I'm not sure I'm following you here. You may need to be a little more clear with what your "Application" is, and indeed what level of VB knowledge you have to better help me assist you with your problem.

In addition how did you test the Scanner to see if it adds a carriage return to the end of the scanned barcode? A reeeeally simple way is to open MSExcel and scan your barcode, if the cursor jumps to a new cell after the scan you can assume a carriage return is being added. Otherwise you could test it in code with the _KeyUp event I posted previously, which is more than likely what you'll need to do in order to achieve a solution to your problem....assuming you go down the adding a new form path
oh sorry i did not make it clear enough. yes, the app is a vb6.0 app. i should consider myself a beginner with the level of vb knowledge.

i cannot modify the application as i do not have the source code. but the application allows me to call an activex or exe which can be another separate application. i did test the scanner to see if it adds a carriage return. i opened up a notepad and an excel and it did not jump to a new cell.

here is what i want to do.
1. if possible, create an activex or exe that i can call from the app. this activex or exe then can have the 3 fields that i wanted.
2. then save the data of the 3 fields into the database.
3.it will check if the first 2 fields are equal. if they are not, it shud return a value fail. if they are, it shud return a value pass.

here is an example of an activex or exe that i called from the app.

 Set objCalculateEx = CreateObject("calc_weight.cls_mweight")
intweight = objCalculateEx.GetWeight(strWeight_list, strSQL, strError)
if intweight =0 then
msgbox("There is no weight available")
Rem the code continues..

what i am doing here is i have an activex called calc_weight. i have a few functions inside this calc_weight for example getweight. i was wondering if i can add another function that i can call which can allow me to allow the user to key in the 3 fields as mentioned above. and i want to be able to return either a "pass" or "fail" to the parameter intweight(as an example).

or create a new activex or exe for this same purpose..does this help?
hmmmm.....a little clearer....but still pretty Fuzzy....

Your example above is of something that already works right? This isn't code attempting to achieve your solution to this problem?? above it looks like you're creating an instance of a class object (ActiveX) and that is going off and doing something and then returning a result to your "Application".....

Given that you are requiring some user interaction you are going to have to approach this differently....and the scope of your requirements are a little hard for me to determine.....have you made an attempt at any of this yourself?

If so can you post your code as it is probably a lot easier for me to assist you.....with an emphasise on assist....unfortunately I can't write this for you...only point you in the right direction

Here's a couple of tutorials that may make your required approach clearer :
http://kandkconsulting.tripod.com/VB/Tutorials/activex_exe_tutorial.htm
http://www.tutorialsweb.com/activex/activex.htm
it returns me an error saying there is a type mismatch. i am not sure what i am doing wrong..

here is the code in the application that calls the activex:-

Set objCalculateEx = CreateObject("calc_weight.cls_mweight")
strError=""
intweight = objCalculateEx.GetWeight(strError)
if intweight ="Pass" then
msgbox("Same weight")
else
msgbox("different weight")
Rem the code continues..


here is the codes to the function i added to the current activex that i have..

Function GetWeight(ByRef strError As String) As String
       
    Dim strWeightx  As String
    Dim strWeighty  As String
    Dim strName  As String
   
    On Error GoTo err_handler
   
    strWeightx = InputBox("Key in Weight1", "Weight")
    strWeighty = InputBox("Key in Weight2", "Weight")
    strName = InputBox("Key in your name", "Name")
   
    If strWeightx = strWeighty Then
        GetWeight = "Pass"
    Else
       GetWeight = "Fail"
    End If    
    Rem Then i would like to add codes to save this 3 values to the database, have not written them cos
    Rem the sub could not call the function at all...
End Function
is variable "intweight" declared as an Integer? I guess you need to declare it as a String here.
hmm it was declared as an integer at first. i declared it as a string. but still there is a type mismatch...
Which line of code causes that type mismatch error?
i stepped thru the code in the application and then when it got to the point where i am calling intweight

intweight = objCalculateEx.GetWeight(strError)

then it gives me the type mismatch error.. i do not know how to step thru the code and then jump to stepping the code in the activex...

Make sure you got code such as:

Dim intweight As String

above:

intweight = objCalculateEx.GetWeight(strError)

?
strangely, it works now when i changed the function to exclude strError.

however, it works only when i am stepping through the code and not automatically. why is this so? that means it hangs when the application calls an inputbox in the function...
but if i step through each line in the code it works... any thoughts?
Is your ActiveX running on the same machine as the application? Or on a server? If on the server it will hang because noone is sitting at the server to enter the text into your inputbox
the activex is running on the same machine as the application.. i have the application both on my pc and the activex is on my pc as well.. but seems like it hangs for no reason...
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial