473,406 Members | 2,705 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,406 software developers and data experts.

Data Files

I have a long list of jokes and I wish to select them randomly from a
big file. What is teh best way to select them? Ordinary Text or XML?
Also how do I index them? I know howto read text files so I suppose I
could use a separator of some sort bewteen jokes but I am thinking
that they may all need to be read into an array first?

Thanks

K.
Aug 1 '08 #1
3 1240
On Aug 2, 2:33 am, kronec...@yahoo.co.uk wrote:
I have a long list of jokes and I wish to select them randomly from a
big file. What is teh best way to select them? Ordinary Text or XML?
Also how do I index them? I know howto read text files so I suppose I
could use a separator of some sort bewteen jokes but I am thinking
that they may all need to be read into an array first?

Thanks

K.
If you can list your jokes line by line in a text file:

You can read your text content using StreamReader,
and assign the content to a multi-line textbox:

'------Code Begins-------
Imports System.IO

Using reader As New StreamReader("c:\jokes.txt")
' I recommend setting "Wordwrap" to False for
' textbox not to force long lines to be misaligned.

TextBox1.Text = reader.ReadToEnd

End Using
'----Code Ends--------

After loading all the jokes into a textbox(even you can hide the
textbox by making its visible property to False), and now you can
select them randomly as you can use textbox's "lines" property with
Random class:

'------Code Begins-------
' Like that:
Dim rand As New Random
Dim selectedRand As String
selectedRand = TextBox1.Lines _
(rand.Next(0, TextBox1.Lines.Length))
' eg: Display random joke in MsgBox
MsgBox(selectedRand)
'-----Code Ends------

Plus, you can make the textbox read-only not to be modified by user,
and make it invisible not to be seen by user depending on your wish.

Hope this helps,

Onur Güzel

Aug 2 '08 #2


kimiraikkonen wrote:
On Aug 2, 2:33 am, kronec...@yahoo.co.uk wrote:
I have a long list of jokes and I wish to select them randomly from a
big file. What is teh best way to select them? Ordinary Text or XML?
Also how do I index them? I know howto read text files so I suppose I
could use a separator of some sort bewteen jokes but I am thinking
that they may all need to be read into an array first?

Thanks

K.

If you can list your jokes line by line in a text file:

You can read your text content using StreamReader,
and assign the content to a multi-line textbox:

'------Code Begins-------
Imports System.IO

Using reader As New StreamReader("c:\jokes.txt")
' I recommend setting "Wordwrap" to False for
' textbox not to force long lines to be misaligned.

TextBox1.Text = reader.ReadToEnd

End Using
'----Code Ends--------

After loading all the jokes into a textbox(even you can hide the
textbox by making its visible property to False), and now you can
select them randomly as you can use textbox's "lines" property with
Random class:

'------Code Begins-------
' Like that:
Dim rand As New Random
Dim selectedRand As String
selectedRand = TextBox1.Lines _
(rand.Next(0, TextBox1.Lines.Length))
' eg: Display random joke in MsgBox
MsgBox(selectedRand)
'-----Code Ends------

Plus, you can make the textbox read-only not to be modified by user,
and make it invisible not to be seen by user depending on your wish.

Hope this helps,

Onur G�zel
Thanks, do you mean each joke per line? Otehrwise how would I know
where one joke started and the otehr ended? So just put each jok in a
very long line in the text file?

regards

K.
Aug 2 '08 #3
On Aug 2, 11:08*am, kronec...@yahoo.co.uk wrote:
kimiraikkonen wrote:
On Aug 2, 2:33 am, kronec...@yahoo.co.uk wrote:
I have a long list of jokes and I wish to select them randomly from a
big file. What is teh best way to select them? Ordinary Text or XML?
Also how do I index them? I know howto read text files so I suppose I
could use *a separator of some sort bewteen jokes but I am thinking
that they may all need to be read into an array first?
Thanks
K.
If you can list your jokes line by line in a text file:
You can read your text content using StreamReader,
and assign the content to a multi-line textbox:
'------Code Begins-------
Imports System.IO
Using reader As New StreamReader("c:\jokes.txt")
' I recommend setting "Wordwrap" to False for
' textbox not to force long lines to be misaligned.
TextBox1.Text = reader.ReadToEnd
End Using
'----Code Ends--------
After loading all the jokes into a textbox(even you can hide the
textbox by making its visible property to False), and now you can
select them randomly as you can use textbox's "lines" property with
Random class:
'------Code Begins-------
' Like that:
*Dim rand As New Random
Dim selectedRand As String
selectedRand = TextBox1.Lines _
(rand.Next(0, TextBox1.Lines.Length))
' eg: Display random joke in MsgBox
MsgBox(selectedRand)
'-----Code Ends------
Plus, you can make the textbox read-only not to be modified by user,
and make it invisible not to be seen by user depending on your wish.
Hope this helps,
Onur G zel

Thanks, do you mean each joke per line? Otehrwise how would I know
where one joke started and the otehr ended? So just put each jok in a
very long line in the text file?

regards

K.- Hide quoted text -

- Show quoted text -
Yes, the way i mentioned was assuming each joke was seperated line by
line in a text file. I don't know how you store your jokes so that was
just a way of doing it. Also you can use string's split method
depending how your jokes (strings) are stored and will be delimited.
http://msdn.microsoft.com/en-us/libr...ing.split.aspx

Thanks,

Onur Güzel
Aug 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nelson Minar | last post by:
I'm writing some code to upload photos to Flickr. The Photo Upload API requires documents be POSTed via a multipart/form-data request. I was surprised to learn that Python 2.3's HTTP clients don't...
2
by: Ivan | last post by:
Hi, SQL Server 2000 SP3 Windos 2000 Server SP4 I have a DTS package that imports data from a dBase IV databse with files located in two folders (dBF1 and dBF2). I use a transform data task...
15
by: Xarky | last post by:
Hi, Is it possible to make use of data files in C? If yes can someone tell how or suggest me a site from where I can learn them. Thanks in Advance for your patience.
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
12
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in programming so you'll have to bear with me... My...
11
by: E.T. Grey | last post by:
Hi, I have an interesting problem. I have a (LARGE) set of historical data that I want to keep on a central server, as several separate files. I want a client process to be able to request the...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
9
by: LucasLondon | last post by:
Hi, Sorry, this is a bit of a lengthy one but I guess too much information is better than less! I have an excel worksheet that I update regulary with latest values from downloaded CSV files....
0
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media....
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.