Jump to content

Open a file for reading contents


Recommended Posts

Hi,

This code intented to do all the combinations of 2 digit numbers but has to be stoped anytime and must return at the point it stopped before. I thought of saving the vector`s index and passed it again when the code restarted. I was succesful in writing the vector`s index in a FileOpne.txt archive but did not manage to read it and pass the index to the $aArrayComb vector. Does anybody could help me with that ?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0

#ce ----------------------------------------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <Misc.au3>

$aArrayComb = '0123456789'
$aArrayComb = StringSplit($aArrayComb, "")

Local Const $sFilePath = "C:\FileOpen.txt"

; Abrir O Arquivo
Local $hFileOpen = FileOpen($sFilePath, $FO_READ + $FO_OVERWRITE)

If $hFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "There is not a previous point break.")
EndIf

HotKeySet("{ESC}", "Terminate")
$chave = ""

For $1 = 1 To $aArrayComb[0]
   For $2 = 1 To $aArrayComb[0]
      For $3 = 1 To $aArrayComb[0]
         $chave &= "Combination : " & $aArrayComb[$1] & $aArrayComb[$2] & $aArrayComb[$3] & "   Position : " & $1 & $2 & $3 & @CRLF
         Consolewrite($chave & @crlf)
      Next
   Next
Next

Func Terminate()
   $pos = $1 & $2 & $3
   FileWrite("C:\FileOpen.txt", $pos)
   Exit
 EndFunc

 

Link to comment
Share on other sites

Add a paused function:

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
$Paused = $Paused

;your code here

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • Moderators

MadAndroid,

all the combinations of 2 digit numbers

Apart from the fact that the script produces all the combinations of 3-digit numbers, why do you need to do this?

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

computergroove,

Thankyou but I didn`t get the point. My problem is to make the code returns to the point it was early terminated. I put a function called by the "ESC" key so I could stop it anytime but I wish I could restart it from there....

Link to comment
Share on other sites

  • Moderators

MadAndroid,

an academic exercise of algoritmics

Then why do you wish to save the results in a file with the specific "Combination" & "Position" headings? To me that seems a strange thing for a simple algorithm test to do.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

M23,

I don`t know how to manipulate archives in Autoit. The examples "Notepad1 or Notepad2 that come with the software`s instalation shows how to write I that was as far as I could do.

I have the algoritm in "natural language" to implement and chose to do in Autoit. So, after have read the content of the archive c:\FileOpen.txt I need to read the first digit o the number and pass it to the vector of the first "for". In my code I opened the archive to read its content with this lines:

Local $hFileOpen = FileOpen($sFilePath, $FO_READ + $FO_OVERWRITE)

If $hFileOpen = -1 Then
   MsgBox($MB_SYSTEMMODAL, "", "There is not a previous point break.")
EndIf

What I expected is that the MsgBox opens to me as the archive didn`t exists the first time the code runned but it didn`t worked and I don`t know why. So I decided to ask for help in this point at least. 

 

Link to comment
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
 Share

×
×
  • Create New...