Sign in to follow this  
Followers 0
address

Line from text file is sent and then deleted

18 posts in this topic

Can you help me please?

Line from text file is sent and then deleted from the text file. And it should be random line.

Share this post


Link to post
Share on other sites



address,

"sent" where exactly? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

How is this any different from your other topic Please stick to one at a time, otherwise we're doing double duty for the same subject. Also, a little effort on your part wouldn't hurt.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Melba23

Like Send command or send into console. And by random line I mean random number of line like line 2 where text file consists 6 lines.

BrewManNH

I thought it's a different kind of script. Thought how to do it for many days but couldn't come up with anything. No idea how to delete from text file what been sent.

Edited by address

Share this post


Link to post
Share on other sites

address,

Go and read the Help file pages about _FileReadToArray, Random, Send, _ArrayDelete, _FileWriteFromArray. Then try to write something yourself. :)

Come back if you run into difficulties, but not for at least 12 hours to give you time to actually do what I have just suggested. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

BrewManNH

I thought it's a different kind of script. Thought how to do it for many days but couldn't come up with anything. No idea how to delete from text file what been sent.

Different from what exactly? Because you're asking the same thing you asked in the post I linked to. What is this script for anyways? It sounds like a spam tool. Also, where is the code from what you've already tried?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Pasting in your code would help as well. Giving vague descriptions of a problem without code is like wanting to walk forward with your face against a brick wall: You'll get nowhere fast and in the end your face is sore =/


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

;Go and read the Help file pages about _FileReadToArray, Random, Send, _ArrayDelete, _FileWriteFromArray. Then try to write something yourself.

;read random line from text file then send it, then delete what was sent

#include <file.au3>
#include <Array.au3>

For $i = 1 to 6
$sFile = @ScriptDir & "Test.txt"

_FileReadToArray($sFile, $arraywherewhattextcontainsstores)

Send ($arraywherewhattextcontainsstores)
_ArrayDelete($arraywherewhattextcontainsstores, $i)

next

Edited by address

Share this post


Link to post
Share on other sites

address,

That was only 9 hours! ;)

You have the basis of a script to do what you want there, but you need to learn more about arrays - I recommend the Arrays tutorial in the Wiki. :)

Next, I see no sign of Random in that script - and that was one of your requirements. Once you have learnt about arrays you will quickly see how Random will help you choose from the various lines of the file stored in the array. And although you have _ArrayDelete to remove the line from the array, you still need to rewrite the changed array back to the file - I suggested _FileWriteFromArray so take a look at that as well. :)

So, a bit more work needed from you yet. But you have made a good start - spend the next 3 hours looking at those points and see how far you get. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

;Go and read the Help file pages about _FileReadToArray, Random, Send, _ArrayDelete, _FileWriteFromArray. Then try to write something yourself.
;read line from text file then send it, then delete what was sent

#include <file.au3>
#include <Array.au3>
Dim $array
;For $i = 1 to 6
$file = @ScriptDir & "test.txt"
$file = FileOpen("test.txt",1)
_FileReadToArray($file, $array)


For $x = 1 To $array[0]
     If $array[$x] = Random(0, 1, 1) Then ;find random line
   Send($x) ;send it
          _FileWriteToLine($file,$x,"",1) ;delete it
          $checkfile = FileOpen("whatwasdeleted.txt",1) ;create check file
          FileWriteLine($checkfile,$array[$x]) ;write what was deleted
          FileClose($checkfile) ;close check file
     EndIf
Next
FileClose($file) ;close main file

Share this post


Link to post
Share on other sites

address,

You are definitely getting there. :)

I would do it like this: ;)

#include <File.au3>
#include <Array.au3>

Global $aArray, $sFile = @ScriptDir & "test.txt"

; Just to test - here is the content of the file BEFORE we run the script
MsgBox(0, "File Before", FileRead($sFile))

; Read the file into the array
_FileReadToArray($sFile, $aArray)

; How many lines are in the file - this is set when we read the file
$iMax_Index = $aArray[0]

; Pick one at random
$iIndex = Random(1, $iMax_Index, 1)

; Send it
;Send($aArray[$iIndex])
MsgBox(0, "Line Sent", $aArray[$iIndex]) ; We show it for testing

; Delete it from the array
_ArrayDelete($aArray, $iIndex)
; Reduce the count
$aArray[0] -= 1

; Now rewrite the file - note we use the base parameter of 1 to avoid writing the count
_FileWriteFromArray($sFile, $aArray, 1)

; And again just to test - here is the content of the file AFTER we have run teh scriot
MsgBox(0, "File After", FileRead($sFile))

I used a file like this to test:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6

Please ask if you have any questions. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Melba23, thank you very much

Can you help me with this please?

This loop runs 56 times. A randomly selected line from text file is inserted between lines 2 and 4. The previous action is skipped at irregular intervals (factor >0.7). The loop continues to run after all lines have been written to the console. No line occurs twice.

#include <File.au3>
#include <Array.au3>
Global $aArray, $sFile = @ScriptDir & "files.txt"

; Read the file into the array
_FileReadToArray($sFile, $aArray)
$iCount = 0
$iMax_Index = $aArray[0]; How many lines are in the file - this is set when we read the file
; Pick one at random
$iIndex = Random(1, $iMax_Index, 1)

For $i = 0 To 55
    ConsoleWrite("1" & @CRLF) ; Line 1
    ConsoleWrite("2" & @CRLF) ; Line 2
If $iCount < $iMax_Index And Random(0, 1, 1) > 0.7 Then ; Skip the next two lines randomly
  ConsoleWrite($aArray, $iIndex[$iCount]& @CRLF) ; Line 3 is a random line
  $iCount += 1
    EndIf
    ConsoleWrite("4" & @CRLF) ; Line 4


; Delete it from the array
_ArrayDelete($aArray, $iIndex)
; Reduce the count
$aArray[0] -= 1
; Now rewrite the file - note we use the base parameter of 1 to avoid writing the count
_FileWriteFromArray($sFile, $aArray, 1)

Next

Subscript used with non-Array variable.:
ConsoleWrite($aArray, $iIndex[$iCount]& @CRLF)
ConsoleWrite($aArray, $iIndex^ ERROR
Edited by address

Share this post


Link to post
Share on other sites

address,

How about explaining what you are trying to do first? I do not mind working on complex coding problems, but I like to know why I am spending my time doing it. I can think of no obvious reason for what you are trying to code - so please let me know. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Melba23, learning and real life implementation could be to fill programs like 1C, SPSS etc.

Share this post


Link to post
Share on other sites

address,

This produces as many "blocks" as there are lines in the file and inserts random non-repeating lines from the file into the blocks at random:

#include <File.au3>
#include <Array.au3>
Global $aArray, $sFile = @ScriptDir & "files.txt"

; Read the file into the array
_FileReadToArray($sFile, $aArray)
$iCount = 0
$iMax_Index = $aArray[0]; How many lines are in the file - this is set when we read the file

; Now we run through the loop
For $i = 1 To $aArray[0]

    ; Choose a random index
    If $aArray[0] = 1 Then ; We need this as Random(1, 1) returns 0
        $iIndex = 1
    Else
        $iIndex = Random(1, $aArray[0], 1)
    EndIf

    ; Write the static lines
    ConsoleWrite("Static 1" & @CRLF) ; Line 1
    ConsoleWrite("Static 2" & @CRLF) ; Line 2

    ; Write the line randomly
    If Random() > 0.5 Then
        ConsoleWrite($aArray[$iIndex] & @CRLF) ; Line 3 is a random line
        ; Delete that line from the array
        _ArrayDelete($aArray, $iIndex)
        ; Reduce the count
        $aArray[0] -= 1
    EndIf

    ; Write the final static line
    ConsoleWrite("Static 4" & @CRLF & @CRLF) ; Line 4

Next

Are we getting close yet? :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Melba23, thank you very much. Now this is too awesome.

Slight problem, when I delete sent lines

#include <File.au3>
#include <Array.au3>
Global $aArray, $sFile = @ScriptDir & "files.txt"
; Read the file into the array
_FileReadToArray($sFile, $aArray)
$iCount = 0
$iMax_Index = $aArray[0]; How many lines are in the file - this is set when we read the file
; Now we run through the loop
For $i = 1 To 55
    ; Choose a random index
    If $aArray[0] = 1 Then ; We need this as Random(1, 1) returns 0
        $iIndex = 1
    Else
        $iIndex = Random(1, $aArray[0], 1)
    EndIf
    ; Write the static lines
    ConsoleWrite("Static 1" & @CRLF) ; Line 1
    ConsoleWrite("Static 2" & @CRLF) ; Line 2
    ; Write the line randomly
    If Random() > 0.5 Then
        ConsoleWrite($aArray[$iIndex] & @CRLF) ; Line 3 is a random line
        ; Delete that line from the array
        _ArrayDelete($aArray, $iIndex)
        ; Reduce the count
        $aArray[0] -= 1
  _FileWriteFromArray($sFile, $aArray, 1)
    EndIf
    ; Write the final static line
    ConsoleWrite("Static 4" & @CRLF & @CRLF) ; Line 4
Next

Static 1
Static 2
population32.sav
Static 4
Static 1
Static 2
Static 4
Static 1
Static 2
0
D:MiscPics??? ???????datafiles to spss ???2.au3 (33) : ==> Subscript used with non-Array variable.:
$aArray[0] -= 1
$aArray^ ERROR
>Exit code: 1   Time: 0.210

If no lines left it writes "0" into text file and then gives error. Can it be that instead of 0 it just keeps sending lines 1 2 and 4 until For Next loop ends?

Edited by address

Share this post


Link to post
Share on other sites

address,

Just change the If line to read:

If $iIndex > 0 And Random() > 0.5 Then

Now if there are no more lines left it skips that part. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Are we getting close yet? ;)

This is a fun game. :)

Edited by czardas

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0