Jump to content
Sign in to follow this  
rkr

while loop

Recommended Posts

hi, i am new to autoit. i prepared the attached code which will replace particular values in the file. the program works well in the first pass, but the while loop is not working in the second go. could anyone look into the attached code. If the ';#' in the code are replaced with '#', then the program works well.

sacs-read.au3

GMS Det Leg.txt

Share this post


Link to post
Share on other sites

Please pay attention to the forum purpose when posting threads:

Quote

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moved to support.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You should be modifying the text file directly and not trying to automate Notepad.


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

@rkr it would be helpful if you explained just what you are trying to do, and what your expected outcome is - it may be clear to you, but not necessarily to others just from looking at your code. Also, there is bound to be a better way to do this if you share exactly what you are trying to accomplish. For example, just looking at the code, you can convert all of this:

run("notepad","",@SW_MAXIMIZE)
winwaitactive("Untitled - Notepad")
send("!F")
send("o")
winwaitactive("Open")
send($file_location)
Send("{ENTER}")
Send($file_name)
Send("{ENTER}")
WinWaitActive("GMS Det Leg.txt - Notepad")

To this:

ShellExecute("Notepad.exe", $file_location & $file_name)

We are happy to assist further, if you explain what you are trying to do in more detail. I am going to posit that your best bet will be reading the file into an array, and then changing the values accordingly. More information from you will help us help you.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
8 hours ago, JLogan3o13 said:

@rkr it would be helpful if you explained just what you are trying to do, and what your expected outcome is - it may be clear to you, but not necessarily to others just from looking at your code. Also, there is bound to be a better way to do this if you share exactly what you are trying to accomplish. For example, just looking at the code, you can convert all of this:

run("notepad","",@SW_MAXIMIZE)
winwaitactive("Untitled - Notepad")
send("!F")
send("o")
winwaitactive("Open")
send($file_location)
Send("{ENTER}")
Send($file_name)
Send("{ENTER}")
WinWaitActive("GMS Det Leg.txt - Notepad")

To this:

ShellExecute("Notepad.exe", $file_location & $file_name)

We are happy to assist further, if you explain what you are trying to do in more detail. I am going to posit that your best bet will be reading the file into an array, and then changing the values accordingly. More information from you will help us help you.

i will try to explain it here in detail..

if you open the text file 'GMS Det Leg.txt'- it has 2 lines -> LOADCN   P   1.166  &      LOADCN   R   1.166  .. the autoit pgrm should open the notepad replace the numerals 1.166 based on an equation (here, just increase by 1 and 1.5 respectively for each lines) and the notepad is to be saved/closed. this should repeat till the top line become LOADCN   P   9.166 .. i believe my intention is clear... thanks for all suggestion  
   

Share this post


Link to post
Share on other sites

You're still ignoring the best advice, already given here

Now, no your intend is unclear: as you repeatedly increment the same values in the same file, you could as well replace once by the final values (resp. 9.166 and 13.166). That, or save to distinct files at every step in your loop.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

If i was you, seeing that you really want to go that way, changing the file, i also wouldn't open the file with notepad, instead i would use

_ReplaceStringInFile

If those are the only 2 lines in it, it's even easier, you don't need to read the file, simply overwrite the same lines as you want, with that function.

Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Garrik
      Hi guys!
       
      I need some help here, is there a way to use Random with While? 
      I need this script to run in between 1 and 4 times but I dont know how to do it, can you please help me?
       
      dim $i=1
      While $i<=4
      Sleep(3000)
      Send("{LWINDOWN}r{LWINUP}")
      Sleep(3000)
      Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
      Sleep(3000)
      WinActivate("tags: Bloc de notas","")
      Sleep(3000)
      Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
      Sleep(3000)
      Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
      Sleep(3000)
      Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
      $i=$i+1
      WEnd
    • By tentacole
      Afternoon!
      This is my first post, so I apologize if this is in the wrong place. 
      I've created a while loop to click in a certain area of an application, and have the y axis change at the end of each loop. My loop continues to click at x:27, x:10, even though the $y is adding 15 at the end of each loop. I did a Send($x) and Send($y) into a Notepad to see if the $y had changed after each loop, and the 15 was being added to $y each loop. (If this makes sense)
       
      I'm unsure where I'm going wrong, and would be extremely grateful if someone can point me in the correct direction to fix this. 
      Local $rDirectory = "H:\oDemandProject\fList.txt" Local $rLine = _FileCountLines($rDirectory) Local $x = 27 Local $y = 10 While $rline > 0 WinActivate("OnDemand", "-> 1") WinWaitActive("OnDemand", "-> 1") ControlClick("OnDemand", "", "[CLASS:AfxFrameOrView120u; INSTANCE:1]", "left", 4, $x, $y) $y += 15 $rLine -= 1 WEnd  
    • By mrflibblehat
      Hi All,
      I am developing an IRC Bot and have come across a small problem. Everything works fine until the ConnectToIRC function is called. This is when a while Loop is in play, I assume this is because the while loop is hogging the program and blocking other commands.
      so my question, Is there a way around this or a way I could do this differently so that I can receive data when it comes in and also use controls on the gui?
      If I remove the while loop inside the ConnectToIRC function, Other gui buttons work correctly (Close Button for example)
      Thanks for any help or insight you may provide.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GUIEdit.au3> #Include <ScrollBarConstants.au3> #include <ComboConstants.au3> #Include <Array.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("AutoIT IRCBot", 537, 339, 192, 124) $Edit1 = GUICtrlCreateEdit("", 8, 8, 521, 257, $ES_AUTOVSCROLL + $WS_VSCROLL) $btnSend = GUICtrlCreateButton("Send", 456, 304, 73, 25) $inIRCServ = GUICtrlCreateInput("irc.freenode.net", 8, 272, 97, 21) $inPort = GUICtrlCreateInput("6667", 112, 272, 65, 21) $inChat = GUICtrlCreateInput("", 288, 304, 161, 21) $btnCon = GUICtrlCreateButton("Connect", 184, 272, 73, 25) $Combo1 = GUICtrlCreateCombo("Channel", 288, 272, 161, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseBot") GUICtrlSetOnEvent($btnCon, "ConnectToIRC") GUICtrlSetOnEvent($btnSend, "IRCSend") GUISetState(@SW_SHOW) TCPStartup() ;~ Read INI Values Global $vIRCNick = IniRead("ircbot.ini", "information", "Nick", "AutoITIRCBot") Global $vIRCAltNick = IniRead("ircbot.ini", "information", "AltNick", "AutoITIRCBot_") Global $vIRCRealName = IniRead("ircbot.ini", "information", "RealName", "AutoITIRCBot") Global $vIRCChannels = IniRead("ircbot.ini", "information", "Channels", "#AutoITIRCBot") $vChanArr = StringSplit($vIRCChannels, "|") While 1 Sleep(100) WEnd Func ConnectToIRC() GUICtrlSetState($btnCon, $GUI_DISABLE) GUICtrlSetState($inIRCServ, $GUI_DISABLE) GUICtrlSetState($inPort, $GUI_DISABLE) $vIRCServer = TCPNameToIP(GuiCtrlRead($inIRCServ)) $vIRCPort = GuiCtrlRead($inPort) $vConnect = TCPConnect($vIRCServer, $vIRCPort) TCPSend($vConnect, "USER " & $vIRCNick & " 0 0 :" & $vIRCRealName & @CRLF) TCPSend($vConnect, "NICK " & $vIRCNick & @CRLF) For $i = 1 to Ubound($vChanArr) -1 TCPSend($vConnect, "JOIN " & $vChanArr[$i] & @CRLF) GUICtrlSetData($Combo1, $vChanArr[$i], $vChanArr[$i]) Next While 1 $vRecv = TCPRecv($vConnect, 4096) If $vRecv <> "" Then GuiCtrlSetData($Edit1, $vRecv, 1) EndIf Wend EndFunc Func CloseBot() Exit EndFunc Ini File
      [information] Nick=UKTestBot AltNick=UKTestBot_ RealName=UKTestBOT Channels=#test333|#test222
    • By TrickyDeath
      Hello everyone,

      Have a tricky question:
       
      How i manage to exit from loop, but not from script?
      (ExitLoop it is ok, but runned out of ways, how to use it in my script )
       
      With this i have a problem:
      If i unpause (F2) the script, it will continue the loop.
      While scrip is paused (F2) i can restart it (F1), but:
      While script is paused (F2), and i open  my form (F3), and try to press button on it, it will not work, cause active loop is paused at background. (I hope i understand right the method)
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("{F1}", "RunScript") HotKeySet("{F2}", "Pause") HotKeySet("{F3}", "OpenForm") Global $Pause $GUI_Create_Form = GUICreate("Settings", 175, 95) $Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25) $Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button_Save MsgBox(0, "Notification", "Settings have been saved!", 1) GUISetState(@SW_HIDE) Case $Button_Cancel GUISetState(@SW_HIDE) EndSwitch WEnd Func RunScript() Local $Numbers = 1 While 1 $Numbers = $Numbers + 1 Sleep(250) ToolTip("Numbers:" & $Numbers, 0, 0) WEnd EndFunc ;==>RunScript Func Pause() $Pause = Not $Pause While $Pause Sleep(100) ToolTip('Scrpit is "Paused"', 0, 0) WEnd ToolTip("", 0, 0) EndFunc ;==>Pause Func OpenForm() GUISetState() EndFunc ;==>OpenForm All i want is, brake the counter loop with hotkey.
      Can anyone help me to give a logical answare?
      (I do need the form with buttons, to store data / save settings)
    • By amymichellea
      I've been using AutoIt for about the past two weeks. The code I've created is supposed to open an excel file, combine the first two columns of information into a third column. Then take that new information from the third column and input it into a url. Finally, it saves the file as a .csv and closes it. This code is going to be run everyday at the end of the day and that's where my problem starts.

      Currently, I've got a code that works but I've got a For loop right now that has defined parameters and I think what I really want is a While loop. The number of rows that will exist in the excel file will change on a daily basis, and that's why I think I need a While loop so I can tell it to continue combining the information from the first two columns until the rows stop.

      I've tried searching this forum and the rest of the internet for an answer to my problem and all I've found are examples closer to mine from 2007 or 2008. Unfortunately, they mention a function called "_ExcelSheetUsedRangeGet" which when inputted into AutoIt gives me an error about the function not existing. I also can't find the function in a help file, so I don't know where to go from here. And I tried reading up on the post titled "Yet Another -- ExcelCOM UDF" but that didn't help me either.

      Any and all help would be greatly appreciated.

      Here's my code that's working with the For loop:


      ; ***************************************************************
      ; This should open an excel file with "NameCurrentDate."
      ; The excel file starts with two columns, "HobsonsID" and "TourDate"
      ; This creates a third column called "URL Code" that is a combination of Column 1 and 2
      ; Then it creates a fourth column called "URL"
      ; This column contains the URL to the QR Code with the personalized information
      ; Then it saves the file as a .csv.
      ; *****************************************************************

      #include <Excel.au3>

      $today = @MON & "." & @MDAY & "." & @YEAR;
      $sFilePath1 = @ScriptDir & "\TourRecon" & $today & ".xlsx" ;This file should already exist
      $oExcel = _ExcelBookOpen($sFilePath1)

      If @error = 1 Then
      MsgBox(0, "Error!", "Unable to Create the Excel Object")
      Exit
      ElseIf @error = 2 Then
      MsgBox(0, "Error!", "File does not exist - Shame on you! The path you gave me is" & $sFilePath1)
      Exit
      EndIf

      _ExcelWriteCell($oExcel, "URL Code", 1, 3) ;Puts the Column header "URL Code" in the first row, Column 3

      For $i = 2 To 8 ;Loop
      _ExcelWriteCell($oExcel, "=A" & $i & "&-B" & $i, $i, 3) ;Combines Column 1 and Column 2, puts output in Column 3
      Next

      _ExcelWriteCell($oExcel, "URL", 1, 4) ;Puts the Column header "URL" in the first row, Column 4

      For $j = 2 To 8 ;Loop
      _ExcelWriteCell($oExcel, "=CONCATENATE(CONCATENATE(""http://admissions.calpoly.edu/"", C" & $j & "), "".html"")", $j, 4) ;Write to the Cell
      Next ;This puts a URL into Column 4, starting at Row 2

      $sFilePath = @ScriptDir & "\TourRecon" & $today & ".csv";
      $sType = "csv";
      _ExcelBookSaveAs($oExcel, $sFilePath, $sType)
      If Not @error Then MsgBox(0, "Success", "File was Saved!", 3)
×
×
  • Create New...