Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB 6.0 Pro ed. Accessing-Data from files


  • Please log in to reply

#1
System366

System366

    New Member

  • Member
  • Pip
  • 2 posts
:whistling: :rofl: :blink: :help: :help: :lol: :) :D :rofl:

Hio all,

I am currently programming in VB 6.0 pro ed. and was wundering if any1 could give me the general source code for accesing a random seed line Data from a .txt file please?

I basicly want it to open the .txt file and put 1 line from the txt file into a label and choosing the line from the txt file at random evry time a commadn button is pressed so lyk.

Label1
Command_Button1

Label1 displays data from the .txt file
Command_Button1 changes label1 to a new line of data from the .txt file at random

Thanks in advance for ur help... Please E-mail me with a reply or goto my forum at Http://system366.conforums.com as i will not be coming here often.

Edited by System366, 15 November 2006 - 08:25 PM.

  • 0

Advertisements


#2
skate_punk_21

skate_punk_21

    Malware Removal Expert

  • Retired Staff
  • 1,049 posts
did you get any help for this System366?
  • 0

#3
System366

System366

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Unfortunatley i did not :whistling:

oh well... i even tryed reading the chapter on it in Introduction to Visual Basic 6.0... but to understand it i have to read lyk half the freekin book and its massive n i dont have time :blink:
  • 0

#4
paper

paper

    Member

  • Member
  • PipPip
  • 48 posts
That is easy. Assume you want to pick the line from the first 5 lines of the file in.txt which is in the same folder as your .vbp or exe:

Private Sub Command1_Click()

Dim totalLine As Long, n As Long, i As Long, aLine As String
totalLine = 5 'change the number to what you want
Open App.Path & "/in.txt" For Input As #1 'change the path to what you want
Randomize
n = Int(totalLine * Rnd + 1)
For i = 1 To n
Line Input #1, aLine
Next i
Close #1
Label1 = aLine

End Sub
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP