473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Loading Text File Into A List Box...

3
I everyone-
I need help with this code of mine,
it has to be fixed a little...( IN VB NET 2005)
I have some text files,and every text file has two words
(in different languages)
and they are seperated by (=) equal mark , I want at form load- to load all the text file into a listbox (without an extension),and with click on one of the files it will pick a sentence from that file randomly and split it into two words by the (=) as told, and display the two words in two textboxes (one each)
please I need the whole code fixed. It just a little thing ,isn't it?

visual basic code:--------------------------------------------------------------------------------
Imports System.IO
Imports System.Text

Public Class Form1

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

Private FileName As String = "D:\test.txt"
Private FileEncoding As Encoding = Encoding.UTF8

Private Sub List1_Click()

Dim lines As String() = File.ReadAllLines(FileName, FileEncoding)
Dim Line As String = lines(Int(Rnd() * (UBound(lines) + 1)))
Dim Pos As Long = Line.IndexOf(" ")

Dim FileName As String
FileName = List1.ListIndex
Dim FileName
FileName = Split(FileName, " = ")
Text1.Text = FileName (0)
Text2.Text = FileName (1)
End Sub
End Class


--------------------------------------------------------------------------------

PLEASE - IT IS VERY IMPORTANT TO MY PROJECT :)
Aug 9 '06 #1
3 9150
eyalhz
3
:( :( :(
Come on everybody!
NO ONE KNOWS HOW TO HELP ME WITH IT?????
Please , where are all the expert?
You are asking an expert questions and know the answer,
and for my little code here ,you don't have a solution?
Aug 10 '06 #2
krodman
12
I'm assuming that D:\test.txt has all the files you need on separate lines. If this is incorrect let me know, and I'll try again


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize(Date.Now.Millisecond)

Dim reader As New StreamReader("D:\test.txt")

Do While reader.Peek <> -1
Dim fileName As String = IO.Path.GetFileNameWithoutExtension(reader.ReadLin e)

List1.Items.Add(fileName)

Loop

reader.Close

End Sub

Private Sub List1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles List1.Click
Dim filePath As String = "D:\" & List1.SelectedItem
Dim content As String = My.Computer.FileSystem.ReadAllText(filePath)
Dim lines() As String = Split(content, vbCrLf)
Dim RanNum As New Random
Dim lineNumber As Integer = RanNum.Next(0, lines.Length - 1)
Dim words() As String = Split(lines(lineNumber), " = ")

TextBox1.Text = words(0)
TextBox2.Text = words(1)

End Sub
Aug 13 '06 #3
I'm assuming that D:\test.txt has all the files you need on separate lines. If this is incorrect let me know, and I'll try again


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize(Date.Now.Millisecond)

Dim reader As New StreamReader("D:\test.txt")

Do While reader.Peek <> -1
Dim fileName As String = IO.Path.GetFileNameWithoutExtension(reader.ReadLin e)

List1.Items.Add(fileName)

Loop

reader.Close

End Sub

Private Sub List1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles List1.Click
Dim filePath As String = "D:\" & List1.SelectedItem
Dim content As String = My.Computer.FileSystem.ReadAllText(filePath)
Dim lines() As String = Split(content, vbCrLf)
Dim RanNum As New Random
Dim lineNumber As Integer = RanNum.Next(0, lines.Length - 1)
Dim words() As String = Split(lines(lineNumber), " = ")

TextBox1.Text = words(0)
TextBox2.Text = words(1)

End Sub
Fixed it guy - just ran a streamreader and put contents into an array split by the vbCrLF

Cheers anyway
Dec 7 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marc H. | last post by:
Hello, I recently converted one of my perl scripts to python. What the script does is simply search a lot of big mail files (~40MB) to retrieve specific emails. I simply converted the script...
1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
12
by: teoryn | last post by:
I've been spending today learning python and as an exercise I've ported a program I wrote in java that unscrambles a word. Before describing the problem, here's the code: *--beginning of file--*...
3
by: Holmes | last post by:
Hello Ran into a bit of a problem here and have now exhausted my resources to getting this working What I am trying to do is load and show a simple vb form with a listbox in it Dim...
6
by: Venkatesh | last post by:
Hello All, I have couple of doubts regarding the concept of on-demand javascript loading using javascript code. I could see on the net different techniques for achieving this - techniques like:...
1
by: FreeXenon | last post by:
OK, I am having a lot of problems loading an XML file via a Server-Side JavaScript based ASP page. Below is the code that I am using as well as the different methods of loading the XML file and the...
1
by: icfai | last post by:
hi friends.... I have got a problem regarding loading of multiple assemblies, actually its required for an editor which implements the intellisenseas in vb or dotnet. for that it is required to...
15
by: pdhb_1 | last post by:
I'm trying to run Apache2.2.6 with php. However, I keep getting a long list of error messages in the log file indicating that includes are failing. For example, "PHP Warning: PHP Startup:...
2
by: Jeff | last post by:
Hi I'm trying to achieve a scenario where I have c# files that are compiled dynamically, the assemblies are then loaded in a different AppDomain, I call a simple method from the object, and then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.