---
title: "Läsa random rad i txt-fil?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/11155-läsa-random-rad-i-txt-fil"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Quid"
published: "2001-08-16T14:26:00.000Z"
updated: "2001-08-17T00:42:00.000Z"
replies: 2
views: 229
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/11155-läsa-random-rad-i-txt-fil"
---

# Läsa random rad i txt-fil?

## #1 — Quid, 2001-08-16T14:26Z

Hur går jag till väga om jag vill läsa en random rad i en txt-fil?

Permalänk: https://www.webforum.nu/p/11155

## #2 — Koplik, 2001-08-16T14:35Z

Hmmm...
Vad jag kom på...
Jag antar att du har skapat ett FileSystemObject och öppnat filen och så.

Filen innehåller typ... 50 rader.. ok :)
Kör då:

```
Set FSO = Server.Create("Script.FileSystemObject")

Set Read = FSO.OpenTextFile("FIL.Txt", 1, 1, False)

Randomize()
Tal = Round(Rnd() * 49)

For cLoop = 0 To Tal 
Read.ReadLine
Next

Response.Write Read.ReadLine
```

Kanske går att hoppa till en rad så man slipper min loop, men det funkar nog!

Lycka till! :)

Permalänk: https://www.webforum.nu/p/283874

## #3 — Brimba, 2001-08-17T00:42Z

```
Set FSO = Server.Create("Script.FileSystemObject")
Set Read = FSO.OpenTextFile("FIL.Txt", 1, 1, False)
strText = Read.ReadAll
numRows = ubound(split(strText,vbcrlf))+1

Randomize()
Tal = Round(Rnd() * (numRows-1))

For cLoop = 0 To Tal
Read.SkipLine
Next

Response.Write Read.ReadLine
```

Kanske :)

Permalänk: https://www.webforum.nu/p/283875

---

Tråden på webben: https://www.webforum.nu/amne/asp/11155-läsa-random-rad-i-txt-fil
