Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-10-2008
Member
 
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
Reply With Quote
  #2  
Old 11-10-2008
Member
 
Join Date: Jun 2006
Posts: 620
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....
Reply With Quote
  #3  
Old 11-10-2008
Member
 
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
Reply With Quote
  #4  
Old 11-10-2008
Member
 
Join Date: Jun 2006
Posts: 620
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 11:28 PM.