Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 06-10-2006, 04:33 PM   #1
duff88
College Prospect
 
Join Date: Aug 2005
Programming help

With VB6, how can I do a program that will, with a button click, copy a line from a text file and paste it in a text box? Like, let's say I have this text file:

Code:
Sakic Yzerman Gretzky Hull Orr Howe Messier Bourque Roy Berg

I want my program to copy a random name to the text box every time I click on the button. The first click my give me Berg, while the second give me Hull.

If you know how to do this, can you give me a code that could help?

duff88 is offline   Reply With Quote
Old 06-10-2006, 04:40 PM   #2
MJ4H
Coordinator
 
Join Date: Jan 2002
Location: Hog Country
A simple to understand way of doing it would be to open the text file as an input file

f=freefile
Open "sample.txt" for input as #f

Then read in the names into an array

do
line input #f, name(x)
x=x+1
loop until eof(f) = true

Then select the random name
n=int(rnd(1)*x)
text1.text = name(n)

Being careful to dimension and declare the proper variables, of course.
MJ4H is offline   Reply With Quote
Old 06-10-2006, 05:11 PM   #3
duff88
College Prospect
 
Join Date: Aug 2005
Quote:
Originally Posted by MattJones4Heisman
A simple to understand way of doing it would be to open the text file as an input file

f=freefile
Open "sample.txt" for input as #f

Then read in the names into an array

do
line input #f, name(x)
x=x+1
loop until eof(f) = true

Then select the random name
n=int(rnd(1)*x)
text1.text = name(n)

Being careful to dimension and declare the proper variables, of course.

Thanks for such a quick answer! I'm going to look into it tommorow after work and I'm going to post again to tell if I was able to do it or not. Thanks again!
duff88 is offline   Reply With Quote
Old 06-10-2006, 07:07 PM   #4
MJ4H
Coordinator
 
Join Date: Jan 2002
Location: Hog Country
Sure. If you need elaboration let me know.
MJ4H is offline   Reply With Quote
Old 06-10-2006, 11:00 PM   #5
duff88
College Prospect
 
Join Date: Aug 2005
Thanks, it worked! I asked this on multiple VB forums and got no good answers, I kinda knew you guys would help me!

Thanks again, really appreciated!
duff88 is offline   Reply With Quote
Old 06-10-2006, 11:09 PM   #6
aran
High School Varsity
 
Join Date: Jan 2005
Location: New Jersey, USA
I'm curious: why are you doing this in VB6!? Especially when VB.NET and C# are available and significantly better.
aran is offline   Reply With Quote
Old 06-11-2006, 02:30 AM   #7
21C
College Prospect
 
Join Date: Jul 2001
Location: Newcastle, Australia
Quote:
Originally Posted by aran
I'm curious: why are you doing this in VB6!? Especially when VB.NET and C# are available and significantly better.
I suppose it depends on your comfort zone.

My learning curve on VB6 has been over 4-5 years and I feel reasonably comfortable with it. I dl-ed VB 2005 ( or whatever the hell it's called ) and found it too different to go and learn. I've stuck with what I already know.
21C is offline   Reply With Quote
Old 06-11-2006, 09:27 AM   #8
MJ4H
Coordinator
 
Join Date: Jan 2002
Location: Hog Country
Quote:
Originally Posted by aran
I'm curious: why are you doing this in VB6!? Especially when VB.NET and C# are available and significantly better.

If you are interested in getting a project working quickly and you already know VB6 well enought to get by, why would you want to learn an entirely new program (and vb.net is near enough to an entirely different language to use that analogy) just to make that project. It really is overkill for a lot of projects (and I have used both extensively). Plus VB6 usually makes faster, lighter, and easier to distribute packages (in my experience) for small projects.
MJ4H is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 02:27 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.