Solved

InputBox without OK or Cancel

Posted on 2007-03-19
23
432 Views
Last Modified: 2013-11-25
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..
0
Comment
Question by:coldfirre
  • 10
  • 7
  • 5
  • +1
23 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18746708
>>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
..
0
 

Author Comment

by:coldfirre
ID: 18746723
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?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18746735
>>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.
0
 

Author Comment

by:coldfirre
ID: 18746757
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..
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18746826
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
0
 
LVL 8

Expert Comment

by:deadite
ID: 18746950
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.
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18752954
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
 
0
 

Author Comment

by:coldfirre
ID: 18753336
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..
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18753362
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???
0
 

Author Comment

by:coldfirre
ID: 18754462
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?

0
 
LVL 5

Expert Comment

by:mah8473
ID: 18760461
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:coldfirre
ID: 18761228
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?
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18762131
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
0
 

Author Comment

by:coldfirre
ID: 18762348
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
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18762367
is variable "intweight" declared as an Integer? I guess you need to declare it as a String here.
0
 

Author Comment

by:coldfirre
ID: 18762453
hmm it was declared as an integer at first. i declared it as a string. but still there is a type mismatch...
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18762467
Which line of code causes that type mismatch error?
0
 

Author Comment

by:coldfirre
ID: 18762502
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...

0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18762644
Make sure you got code such as:

Dim intweight As String

above:

intweight = objCalculateEx.GetWeight(strError)

?
0
 

Author Comment

by:coldfirre
ID: 18768748
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?
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18768972
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
0
 

Author Comment

by:coldfirre
ID: 18769056
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...
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 18777596
>>it works now when i changed the function to exclude strError
if strError is not been used or referred in your function GetWeight then we no need to pass it into your function.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now