Is it possible to have one textbox reading three input integer from the user?

aiman_alnasir
aiman_alnasir used Ask the Experts™
on
Is it possible to have one textbox reading three input integer from the user instead of asking three times using inputbox?
Dim Show1, Show2, Show3 As String
        Show1 = InputBox("Enter CID Number: ")
        a = Show1
        Show2 = InputBox("Enter DID Number: ")
        b = Show2
        Show3 = InputBox("Enter TID Number: ")
        c = Show3
 
        dbcmd.Connection = con
 
dbcmd.CommandText = "Select * From table Where CID = " & a & " and DID = " & b & " and TID = " & c

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jorge PaulinoIT Pro/Developer
Top Expert 2008

Commented:
Yes, you can.
You can separate the values by something (empty space, ";", ",", etc) and then split the three values.
I think it's a good answer for 20 points :)

Author

Commented:
How ?

I want to read three value from one textbox? Can you provide me with the code !

Chris BottomleySoftware Quality Lead Engineer
Top Expert 2011

Commented:
Hello aiman_alnasir,

LIke this:

Regards,
Chris
Sub splitter()
Dim strShow As Variant, a, b, c As String
        strshow = Split(InputBox("Enter CID Number: ") & ",", ",")
        If UBound(strshow) = 3 Then
            a = strshow(0)
            b = strshow(1)
            c = strshow(2)
        End If 
End Sub

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Chris BottomleySoftware Quality Lead Engineer
Top Expert 2011

Commented:
Ah

I've just looked at your membership aiman_alnasir.  I asumed you were a limited member with limited points.  I understand the comment now as yes 20 points out of an unlimited stock is not a lot.

Chris
Jorge PaulinoIT Pro/Developer
Top Expert 2008

Commented:
>>  I asumed you were a limited member with limited points
I didn't have VB to test the code, so I just dropped a comment. But 20 point is also too low for a code snippet :)
@chris_bottomley,
Just a comment about your variable declaration: if is it's for VB6 or VBA, the "a" and "b" it will assume as Variant and not as String. You can only do that in .NET versions and you "old" VB way you need to declare individually.
It's not a problem, as you know, but just to clarify. :)

Author

Commented:
Believe it or not! I dont know anything about the points that you are talking about. I dont know if there is limited point for some member or not && however, I will look at it.  O.k, about my concern, please see my comments below;
        Dim strShow As Object
        Dim a, b, c As String
        'Are you sure it is reading from textbox
        strShow = Split(InputBox("Enter CID Number: ") & ",", ",")
'This code is it after sql statment or before! On both it's not working       
If UBound(strShow) = 3 Then
            a = strShow(0)
            b = strShow(1)
            c = strShow(2)
        End If

Open in new window

Chris BottomleySoftware Quality Lead Engineer
Top Expert 2011

Commented:
The script certainly works I tested it albeit in VBA.  IT does a sanity check to ensure three datums with comma seperators.

As for points, take a look around, you own previous posts were 500 to 125 as I recall.  The point is they are yours to use and as a premium member you have an unlimited supply albeit each question is limited to 500 tops.

How many points you assign depends on how soon you want an answer, how many people may be interested to post alternatives and how hard it is.  I have never seen a premium member post 20 points myself although limited members do since sometimes that is as many points as they have.  The assignment of points is however very personal so do as you wish but take a look at some of the questions, the answers and the number of points assigned and perhaps it will help you get appropriate help.

Are you sure you are entering three parameters ... and I have corrected the observer declaration error below.

Note if you use a setting for option base in your code can you let me know as I have assumed the default value of 0

Chris
Sub splitter()
Dim strShow As Variant
Dim a As String
Dim b As String
Dim c As String
        strshow = Split(InputBox("Enter CID Number: ") & ",", ",")
        If UBound(strshow) = 3 Then
            a = strshow(0)
            b = strshow(1)
            c = strshow(2)
        End If 
End Sub

Open in new window

Author

Commented:
It is reading from inputbox and I ONLY need to read from the textbox1.text ONLY.
I want the textbox1.text asked me;
1- Enter CID Number:       (If I press Button1 it should ask me to Enter DID Number: and so on ..ect) than I want to check the three entry if it is exist on the database or not?

'I will do the ckecking part from the databse

myform.jpg
Chris BottomleySoftware Quality Lead Engineer
Top Expert 2011

Commented:
Good luck with that, in your original question you started with an input box and I have maintained that in the response.

Chris

Author

Commented:
I know it is not easy to do so. This is why I asked if it is possible to have one textbox reading three input integer from the user instead of asking three times by using inputbox? I don't know what do you mean by "started with an input box and I have maintained that in the response".

Author

Commented:
I don't think there is a solution.
Chris BottomleySoftware Quality Lead Engineer
Top Expert 2011

Commented:
There is a solution as given by paulino, with the sample from me.  Yes the sample for ease used the input box, but for 20 points and no worked example what do you want?

All you have to do is work the split into your form code replacing the input box with the text box returned string.

It is easy to do as described and as implied by your points assignment..

Chris

Commented:
Hi aiman_alnasir,

I have produce some sample code that should get you going on your request. Tinker around with the code below a little, and see what's happening. All you have to do is put in the necessary commas "," after each number entry in the textbox. An example would be like: 2,58,789.  Then the code will parse each comma delimited entry. You could replace my sample For Loop code...within the If Statement to your likings. You will see in my second sample what I'm talking about.  I hope this is some help to your need. :- ) There are two code samples here:


'-- Sample 1 ' 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '-- Split textbox of comma delimeter and place values in a String array: Strng() '
        Dim Strng() As String = TextBox1.Text.Split(",")
 
        If Strng.Count = 3 Then
            '-- Loop three times and display each Strng value in message box '
            For i As Integer = 0 To 2
                MessageBox.Show(Strng(i))
            Next
        End If
    End Sub
 
'-- Sample 2 '
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '-- Declare local variables '
        Dim a As String = ""
        Dim b As String = ""
        Dim c As String = ""
 
        '-- Split textbox of comma delimeter and place values in a String array: Strng() '
        Dim Strng() As String = TextBox1.Text.Split(",")
 
        If Strng.Count = 3 Then
            '-- Assign variables
            a = Strng(0)
            b = Strng(1)
            c = Strng(2)            
        End If
 
        '-- Your DB Connection and CommandText Code '
        dbcmd.Connection = con
        dbcmd.CommandText = "Select * From table Where CID = " & a & " and DID = " & b & " and TID = " & c
    End Sub

Open in new window

Chris BottomleySoftware Quality Lead Engineer
Top Expert 2011

Commented:
modus_operandi / aiman_alnasir

I'm not sure why the post but I assume a request has been made to delete the Q.  In this case I would say that barrislb:at post 24888865 has the most relevant and complete post that answers the question.

Note the question was to take three values and input them in one pass, the post by barrislb does exactly that and I see no response from aiman_alnasir to indicate a problem.

I would be surprised at an action that closes the question and refunds the points as I feel the experts involved have entered relevant information that meets the original question.

Chris

Commented:
Thanks, Chris, for your backing...in your previous post. :- )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial