Solved

text file to series of listboxes

Posted on 2014-02-12
4
216 Views
Last Modified: 2014-02-12
i have  text file that contains the previously saved contents of a group of listboxes.

here is a sample

ListBox4
ListBox3
06410 3x5 SAFETY                                        
06416 3x4 RED                                          
06418 3x4 BROWN                                        
06458 3x4 BLUEMIST                                      
ListBox2
06420 4x6 RED                                          
06421 4x6 BROWN                                        
06423 3x10 BROWN                                        
06425 3x4 SLATE                                        
06434 3x5 COFFEE                                        
06440 3x5 GREETING                                      
06443 3x4 NAVY                                          
06444 4x6 NAVY                                          
06445 3x10 NAVY                                        
ListBox1
06426 4x6 SLATE                                        
06428 3x10 SLATE                                        
06429 4x6 CHURCH&CHURCH  
MainListBox
01234 3x5 TURQUOISE                                    
06399 0x0 NOT-IN-SERVICE                                
06459 4x6 BLUEMIST                                      
06460 3x10 BLUEMIST                                    
06473 4x6 ROUNDBROWN                                    
06474 3x10 ROUNDBROWN                                  
06476 3x4 ROUNDBROWN                                    
06485 3x4 DESIGNERBLUE                                  
06486 4x6 DEIGNERBLUE                                  
06487 3x10 DESIGNERBLUE                                
06491 3x4 DESIGNERBROWN                                
06492 4x6 DESIGNERBROWN                                
06493 3x10 DESIGNERBROWN                                
08008 3x5 ESCBURGUNDY                                  
08028 3x10 ASHEVILLEPOLICE                              
08038 4x6 SHARPESLAWNLOGO                              
08040 4x6 H.T.HACKNEY                                  
08043 4x6 ABTECH                                        
08053 4x6 BB&T                    



what i want to do is read through the file and repopulate the appropriate listboxes with the text lines below each listbox

my question is .. .how do i get the string i read in to map to the corresponding list box on my form.

here is what i have so far

                FileOpen(fileNum, "c:\ini\" + txtSaveFile.Text.ToString, OpenMode.Input)
                Do Until EOF(fileNum)
                    fileString = LineInput(fileNum)
                    If fileString.StartsWith("List") Or fileString.StartsWith("main") Then
                        BoxString = fileString
                    Else
                        'point to listbox contained in  -BoxString
                        'add filestring to that listbox
                    End If
                Loop
0
Comment
Question by:CASorter
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 500 total points
ID: 39854151
Make boxString a global variable, in your else add the InsertData(fileString) and also make sure to add the new subroutine InsertData.  Also make sure to put an upper case M in main or check against the lower case value.


                FileOpen(fileNum, "c:\ini\" + txtSaveFile.Text.ToString, OpenMode.Input)
                Do Until EOF(fileNum)
                    fileString = LineInput(fileNum)
                    If fileString.StartsWith("List") Or fileString.StartsWith("Main") Then
                        BoxString = fileString
                    Else
                        InsertData(fileString)
                    End If
                Loop 


    Private Sub InsertData(fileString As String)
        Select Case boxString
            Case "ListBox1"
                ListBox1.Items.Add(fileString)
            Case "ListBox2"
                ListBox2.Items.Add(fileString)
            Case "ListBox3"
                ListBox3.Items.Add(fileString)
            Case "ListBox4"
                ListBox4.Items.Add(fileString)
            Case "MainListBox"
                MainListListBox.Items.Add(fileString)
            Case Else
        End Select
    End Sub

Open in new window

0
 

Author Comment

by:CASorter
ID: 39854181
now...  thats thinking "outside the box"

lol...

thanks

let you know if it works....


i would consider this an "old school" solution...  which is good.. i like that better...

but i never know when i should look for System.Reflection.Assembly.GetExecutingAssembly().Location to get the equivalant of the old app.path.....
0
 

Author Closing Comment

by:CASorter
ID: 39854338
thank you!
0
 
LVL 9

Expert Comment

by:dustock
ID: 39854402
No problem, glad my old school style came in handy!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now