Results 1 to 4 of 4

Thread: How to add file content to combobox

  1. #1
    Join Date
    Jun 2006
    Posts
    206

    How to add file content to combobox

    i am using apache POI to add rows to excel file.
    I need to create combobox (list box) in my excel file.
    do you know if it's possible ? how can I do it ?

    Thanks

  2. #2
    Join Date
    Jun 2006
    Posts
    623
    try this:

    Code:
    Dim sName(20) As String 
    Dim sNum(20) As String 
    
    Private Sub Form_Load() 
        Open "textfile.txt" For Input As #1 
        Index = 0 
        Do Until EOF(1) 
            If Index > 19 Then 
                MsgBox "Sorry, Only 20 Numbers/Names at one time please.", vbCritical, "Users" 
                Exit Do 
            End If 
            Index = Index + 1 
    
            Input #1, sNum(Index), sName(Index) 
            Combo1.additem = sNum(Index) 
        Loop 
        Close #1 
    
    End Sub 
    
    Private Sub Combo1_Click 
        call Combo1_Change 
    End Sub 
    
    Private Sub Combo1_Change 
        Text1.text=sName(combo1.value) 
    End Sub
    This is untested

    please let me know if it works

    BTW. This will let you have up to 20 numbers and names. any more than that and you'll have to increase the no. 20's and the no. 19 by the same amount....

  3. #3
    Join Date
    Jun 2006
    Posts
    206
    I have a problem with this tho

    Private Sub cboCentreNumber_Change()
    txtCentreDescription.Text = sName(cboCentreNumber.Text)
    End Sub

    i get a subscript out of range error

    Any ideas

    Thanks again

  4. #4
    Join Date
    Jun 2006
    Posts
    623
    try this new code:

    Code:
    Dim sName(20) As String 
    Dim sNum(20) As String 
    
    Private Sub Form_Load() 
        Open "textfile.txt" For Input As #1 
        Index = 0 
        Do Until EOF(1) 
            If Index > 19 Then 
                MsgBox "Sorry, Only 20 Numbers/Names at one time please.", vbCritical, "Users" 
                Exit Do 
            End If 
            Index = Index + 1 
    
            Input #1, sNum(Index), sName(Index) 
            Combo1.AddItem sNum(Index) 
         
        Loop 
        Close #1 
    
    End Sub 
    
    Private Sub Combo1_Click() 
        Call Combo1_Change 
    End Sub 
    
    Private Sub Combo1_Change() 
        Text1.Text = sName(Combo1.Text) 
    End Sub
    ps: you might want to lock text1

Similar Threads

  1. Unable to search content in PDF file on Windows 7.
    By Sherise in forum Operating Systems
    Replies: 5
    Last Post: 29-04-2011, 11:13 AM
  2. Extracting content from a scan file
    By Emiliio in forum Windows Software
    Replies: 5
    Last Post: 03-02-2010, 12:10 PM
  3. Store content of file in array of bytes
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 01:25 PM
  4. saving console content to file
    By puk284 in forum Software Development
    Replies: 2
    Last Post: 01-05-2009, 08:02 AM
  5. EventID 364: content file download failed
    By Wil|loW in forum Server Update Service
    Replies: 5
    Last Post: 12-09-2007, 11:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,450,625.61603 seconds with 17 queries