PDA

View Full Version : Programming help


duff88
06-10-2006, 04:33 PM
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:

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?

MJ4H
06-10-2006, 04:40 PM
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.

duff88
06-10-2006, 05:11 PM
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!

MJ4H
06-10-2006, 07:07 PM
Sure. If you need elaboration let me know.

duff88
06-10-2006, 11:00 PM
Thanks, it worked! I asked this on multiple VB forums and got no good answers, I kinda knew you guys would help me! :D

Thanks again, really appreciated!

aran
06-10-2006, 11:09 PM
I'm curious: why are you doing this in VB6!? Especially when VB.NET and C# are available and significantly better.

21C
06-11-2006, 02:30 AM
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.

MJ4H
06-11-2006, 09:27 AM
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.