Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a form in VB.NET in which users will need to make new jobs and so on which means the drop down list will need to change all the time. The information is stored in either RTF files or text files. I need to know how to do this... when the form opens, I need that combobox to load its selections from a text file or RTF file. Can somebody show me a way of doing this?

 

Thank you

Posted
Use a System.IO.StreamReader to read the file into an ArrayList. Then set that ArrayList as the DataSource for the ComboBox.
        Dim myStream As New IO.StreamReader("file path")
       Dim fileLines As New ArrayList

       While myStream.Peek <> -1
           fileLines.Add(myStream.ReadLine())
       End While

       myStream.Close()
       Me.ComboBox1.DataSource = fileLines

Posted

One more thing....

 

I have a button on that form that says find job. When the user presses this button it needs to load a text file depending on what the option was they choose from the drop down list. Now I know how to do this if the list is hard coded. You just do if and elseif commands... but I do not know how to code it for something like this where the drop down list can change all the time. Any code examples?

 

Thanks

Posted
You must know something about the value they are selecting. What does it represent? Can it be any value at all or are there only certain legal values? You may well be able to use a Select statement if you know what the values can be. If it is the name of the file, then you simply pass that name to the method that opens the file.
Posted

more...

 

Well for example all of the files in the directory are in this format: Job #xxxx

The xxxx can be any set of numbers, like Job #3454

 

The drop down list pulls in a textfile that contains the Job numbers. For example the test file it reads looks like this:

 

Job #3525

Job #325432

Job #2334

 

And so on.

 

So lets say the user selects Job #2334 from the drop down list, how do I tell VB.NET to go out and load the RTF file Job#2334?

 

Thanks!

Posted
I'll assume that the job file name is in the form "JobXXXX.rtf" for this example. If its not then you can adapt it accordingly:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim selectedItem As String = CStr(Me.ComboBox1.SelectedItem)
       Dim selectedJobNum As Integer = selectedItem.Substring(selectedItem.IndexOf("#"c) + 1)

       Process.Start(String.Format("C:\\MyJobFolder\\Job{0}.rtf", selectedJobNum))
   End Sub

This will open the file in the default program for RTF file type, which would probably be Word or Wordpad. If you want to use the file in some other way then do so, but the call to String.Format would be the same to create the file path.

Posted (edited)

Not working....

 

For some reason this is not working. I keep getting this error.....

 

The system cannot find the file specified.

 

It never changes the 0 to the job number that is selected from the drop down list...

Edited by laroberts
Posted

Nope still not working even after I change that. I do not think its the code thats the problem.... How should I format the name of the files for it to load? Another words should they be called "Job#xxxx" or "#0000" or just"xxxx"

 

I think thats the problem and I am not sure exactly how this code is formating it.

 

Thank you.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...