Welcome to Dream.In.Code
Become a VB Expert!

Join 149,547 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,575 people online right now. Registration is fast and FREE... Join Now!




Transfering data from a .txt file to a combo box in VB6 help

 
Reply to this topicStart new topic

Transfering data from a .txt file to a combo box in VB6 help

oXiDe
18 Nov, 2007 - 09:34 AM
Post #1

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 37



Thanked: 1 times
My Contributions
hi im making a project that needs to load text from .txt files into combo boxes. Here was my failed try.

CODE
Private Sub LoadSC_CDKeys()
  
Dim SCCDKey As String
Open App.Path & "\CD Keys\StarCraft.txt" For Input As #12
Do Until EOF(12)
Line Input #12, SCCDKey

End Sub


and also if someone could post the code that would refresh a form by clicking on a cmd button, i would be forever thankful :l
User is offlineProfile CardPM
+Quote Post

Ken Halter
RE: Transfering Data From A .txt File To A Combo Box In VB6 Help
18 Nov, 2007 - 10:04 AM
Post #2

New D.I.C Head
*

Joined: 18 Nov, 2007
Posts: 35



Thanked: 6 times
My Contributions
QUOTE(oXiDe @ 18 Nov, 2007 - 10:34 AM) *

hi im making a project that needs to load text from .txt files into combo boxes. Here was my failed try.

CODE

Private Sub LoadSC_CDKeys()
  
Dim SCCDKey As String
Open App.Path & "\CD Keys\StarCraft.txt" For Input As #12
Do Until EOF(12)
Line Input #12, SCCDKey

End Sub


and also if someone could post the code that would refresh a form by clicking on a cmd button, i would be forever thankful :l


I just noticed this editor removes indentation. Oops. Need a new editor

CODE

Option Explicit

Private Sub Command1_Click()
   'I'm passing the combo box so its name
   'doesn't need to be hard coded in the LoadSC_CDKeys sub
   Call LoadSC_CDKeys(Combo1)
End Sub

Private Sub LoadSC_CDKeys(TheCombo As ComboBox)
   Dim iFile As Integer
   Dim sCDKeys() As String
   Dim iItem As Integer
  
   'Instead of hardcoding a file number (12 in your case)
   'use Freefile to ask VB which numbers are available
   iFile = FreeFile
  
   'Notice I've changed your path, so I can test the code
   Open "C:\Temp\StarCraft.txt" For Input As iFile
  
   'Read the entire file and break it all up into
   'an array in one line of code
   sCDKeys = Split(Input$(LOF(iFile), iFile), vbCrLf)
  
   'Close the file
   Close iFile

   'Now, fill the combo and get outta here
   With TheCombo
      .Clear 'get rid of anything currently loaded
      'Loop thru the array, adding as we go
      For iItem = 0 To UBound(sCDKeys)
         If Len(sCDKeys(iItem)) > 0 Then 'no blanks allowed
            .AddItem sCDKeys(iItem)
         End If
      Next
      
      'Now, select the first item in the combo
      If .ListCount > 0 Then
         .ListIndex = 0
      End If
      
   End With

End Sub

Ken Halter - MS-MVP-VB

Please always use code tags when posting your code => code.gif

This post has been edited by PsychoCoder: 18 Nov, 2007 - 10:13 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Transfering Data From A .txt File To A Combo Box In VB6 Help
18 Nov, 2007 - 10:14 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
@Ken,

I noticed you gave him the entire solution so that now he doesn't even need to wrote any code to do his homework assignment. Here at </dream.in.code> we don't operate that way, we don't just offer complete assignment solutions, we want them to work towards the answer so we just push them in the right direction smile.gif

So please keep that in mind the next time you want to help someone, I know its hard not to do that, but if we all did that they wouldn't learn anything smile.gif
User is online!Profile CardPM
+Quote Post

oXiDe
RE: Transfering Data From A .txt File To A Combo Box In VB6 Help
18 Nov, 2007 - 10:35 AM
Post #4

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 37



Thanked: 1 times
My Contributions
thx so much it worked

hey but he made it easy and understandable & told me what everything does..
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:35PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month