input boxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    input boxes

    I have a form that I want to use an input box to enter an item in a combo box. How would I go about doing this so if a person has an item that isn't in the list he could click a button then the inputbox would appear and the person would enter the item in the inputbox then click OK and the item would be in the list?
    Could this be done?

    lee123
    Last edited by Killer42; Nov 13 '07, 02:57 AM.
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    Yes.

    However, it would be easier in the Validation event to check if it is a new entry and just add it to the list.

    Edit: Above was for VB.NET, but it looks like you are using VB6. I've forgotten exactly what event to use. Is there an Exit or Leave event?

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by SammyB
      Edit: Above was for VB.NET, but it looks like you are using VB6. I've forgotten exactly what event to use. Is there an Exit or Leave event?
      For what, the combobox? If so, then yes, it does have a Validate event.

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Originally posted by Killer42
        For what, the combobox? If so, then yes, it does have a Validate event.
        OK, thanks, Killer. So, in the Validate event compare the .Text with each of the items in the combo. If it is new, then just add it to the combo.

        Comment

        • Mohan Krishna
          New Member
          • Oct 2007
          • 115

          #5
          Originally posted by lee123
          I have a form that I want to use an input box to enter an item in a combo box. How would I go about doing this so if a person has an item ...
          lee123
          Hi lee123

          May this code in VB 6 help you?

          Code:
              Dim ibStr As String, idx As Integer, foundFlag As Boolean
              foundFlag = False
              Combo1.ListIndex = 0
              ibStr = InputBox("Enter a Name : ", "New Name")
              For i = 0 To Combo1.ListCount - 1
                  If ibStr = Combo1.List(i) Then foundFlag = True
              Next i
              If Not foundFlag Then Combo1.AddItem (ibStr)
          Please reply whether it does!

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by Mohan Krishna
            May this code in VB 6 help you? ...
            Thanks for that. However, you overlooked a very important step in this kind of processing. That is, to drop out of the loop as soon as you get a hit.

            Comment

            • lee123
              Contributor
              • Feb 2007
              • 556

              #7
              ok i'll try it but what does killer42 mean by "to drop out of the loop as soon as you get a hit." when i did this question i over looked one this about my project and that is i have used a shape control to indicate where a certain item goes in a storage unit for logo mats. another words: i have 69 shapes (circles) called: ( shape1 through shape69 ) that are blackened. well here is what i have in my code:

              Code:
              If Combo1 = "ALBERTOS" Then
                  Shape39.FillStyle = 0
                  Shape39.FillColor = vbBlack
                  Shape40.FillStyle = 0
                  Shape40.FillColor = vbBlack
                  Shape41.FillStyle = 0
                  Shape41.FillColor = vbBlack
                  Shape42.FillStyle = 0
                  Shape42.FillColor = vbBlack
                  Shape43.FillStyle = 0
                  Shape43FillColor = vbBlack
                  Text2.Text = "B" 'this is the section it goes in
                  Text2.FontBold = True
                  Text2.FontSize = 27
              Else
                  Shape39.FillStyle = 1
                  Shape39.FillColor = H80000003
                  Shape40.FillStyle = 1
                  Shape40.FillColor = H80000003
                  Shape41.FillStyle = 1
                  Shape41.FillColor = H80000003
                  Shape42.FillStyle = 1
                  Shape42.FillColor = H80000003
                  Shape43.FillStyle = 1
                  Shape43.FillColor = H80000003
              End IF
              this is why i asked this question i want to be able to update this to add a new mat to the combo box plus shade in a shape as well because there are 12 units with 69 spaces each unit has a letter (A - L).

              lee123

              Comment

              • Mohan Krishna
                New Member
                • Oct 2007
                • 115

                #8
                Originally posted by Killer42
                Thanks for that. However, you overlooked a very important step in this kind of processing. That is, to drop out of the loop as soon as you get a hit.
                Sorry! I just made an idea for that!

                ThanQ

                Comment

                • lee123
                  Contributor
                  • Feb 2007
                  • 556

                  #9
                  so really there is nothing no one can do to help.

                  ok thanks

                  lee123

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by lee123
                    so really there is nothing no one can do to help.
                    I wouldn't say that, at all.

                    For a start, if you are using VB6 then I would recommend you use control arrays rather than separate names for each one. Using an array means you can reuse code via things like For loops, making your code much smaller.

                    And if all you want to do is click a button, get a prompt and add a value to a combo box, as described in the first post, that can be done pretty simply. For example...

                    [CODE=vb]Private Sub Command1_Click( )
                    Combo1.AddItem InputBox("Blah blah =>", "Enter something")
                    End Sub[/CODE]I've just tested this, and it works.

                    Comment

                    • lee123
                      Contributor
                      • Feb 2007
                      • 556

                      #11
                      well i am using vb6 and ill give you code a try thanks killer42

                      lee123

                      Comment

                      • lee123
                        Contributor
                        • Feb 2007
                        • 556

                        #12
                        will this work for the shapes i have that needs to be darkened as well.

                        lee123

                        Comment

                        • lee123
                          Contributor
                          • Feb 2007
                          • 556

                          #13
                          hey killer42 i tried your code it works fine but when you exit it program then enter it the item you just entered is gone it's not there why?

                          lee123

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #14
                            Originally posted by lee123
                            hey killer42 i tried your code it works fine but when you exit it program then enter it the item you just entered is gone it's not there why?
                            All you're doing is adding items into the text held in the combobox control. This will be lost as soon as you exit the program.

                            Carrying information over to another execution of your program is another story entirely. You would need to store it in a file, or the registry, or a database or something.

                            Comment

                            • lee123
                              Contributor
                              • Feb 2007
                              • 556

                              #15
                              yea thats what i thought thanks anyway

                              lee123

                              Comment

                              Working...