coolness Posted July 31, 2018 Posted July 31, 2018 This is what I have got. Why aint it working guys? #include <File.au3> #include <MsgBoxConstants.au3> $sFile = "text.txt" $lines = _FileCountLines($sFile) $sFile = FileOpen($sFile) $line = FileReadLine($sFile, Random(1, $lines, 1)) MsgBox(4096, "", $line) FileClose($sFile) I would also like to learn how to write text into a txt file, if you know how.
coolness Posted July 31, 2018 Author Posted July 31, 2018 the msgbox gave an error message, so I replaced it with this. MsgBox(4096, "Windy:", ($line)) and it still isn't showing the line in the msgbox. can someone please help?
spudw2k Posted July 31, 2018 Posted July 31, 2018 Works for me. Maybe add some error checking? #include <File.au3> #include <MsgBoxConstants.au3> $sFile = "text.txt" $lines = _FileCountLines($sFile) ConsoleWrite("$lines: " & $lines & @TAB & "@error: " & @error & @CRLF) $sFile = FileOpen($sFile) ConsoleWrite("$sFile: " & $sFile & @TAB & "@error: " & @error & @CRLF) $line = FileReadLine($sFile, Random(1, $lines, 1)) ConsoleWrite("$line: " & $line & @TAB & "@error: " & @error & @CRLF) MsgBox(4096, "", $line) FileClose($sFile) Are you sure your $sFile is called text.txt and is in the same directory as your .au3 script? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
coolness Posted July 31, 2018 Author Posted July 31, 2018 Its called test.txt sorry. It works now. I feel like an idiot. lol.
coolness Posted July 31, 2018 Author Posted July 31, 2018 I am trying to use an input box, to write a line to a txt file. Can you help? #include <File.au3> $text = inputbox("write to txt", " write something: ") $sFile = "test.txt" $sFile = FileOpen($sFile) $line = Filewriteline($text) FileClose($sFile) Why isn't this working?
1957classic Posted July 31, 2018 Posted July 31, 2018 Try this: #include <File.au3> $text = inputbox("write to txt", " write something: ") $sFile = "test.txt" $sFile = FileOpen($sFile, 1) FileWrite($sFile, @CRLF & $text) FileClose($sFile)
spudw2k Posted July 31, 2018 Posted July 31, 2018 4 hours ago, coolness said: Why isn't this working? Because of this line 4 hours ago, coolness said: $line = Filewriteline($text) The FileWriteLine function should have two parameters, the file handle [$sFile], then the text [$text] like this $line = FileWriteLine($sFile, $text) Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now