Jump to content

Reading TXT File Line by Line and putting in a TXTBOX


Recommended Posts

This code works now..

#include
#include
#include
#include
Local $file = FileOpen(@scriptdir & "\address.txt", 0) ; <--------- file is in same dir as script
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read file to array
local $aLines
_FileReadToArray(@scriptdir & "\address.txt", $aLines)
;Call("address") ; <--------------------- invoke functions directly, not with call
address() ; <--------------------- like this
Func address()
for $1 = 1 to $aLines[0]
if $aLines[$1] = '' then continueloop
local $oIE = _IECreate($aLines[$1],0,1,1,1) ; page to open
if @error <> 0 then ConsoleWrite('Error code = ' & @error & @LF)


;do this...
;do that..


;_IEQuit($oIE) ;close the Internet Explorer
next
EndFunc ;==>address
FileClose($file)

instead of

if @error <> 0 then ConsoleWrite('Error code = ' & @error & @LF)

i want it to process the NEXT LINE instead..

if @error <> 0 then Next $1 ;process next line instead of going to rest of script..

TIA

Link to comment
Share on other sites

How about ContinueLoop?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

hodahel,

I think water is saying that the "if error" stmt can use continue loop. I am writing a message to the console then falling through (which continues the loop). The choice is yours.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hi,

I'm already here:

_IENavigate($oIE, $aLines[$1]&"mysite1.org", 0)   ; navigate to site #1

if @error <> 0 Then _IENavigate($oIE, $aLines[$1]&"/mysite2.org")   ; navigate to site#2

My problem is if site #1 is offline, I want it to navigate to site #2. But my code stops only of "page not found" never navigate to site #2.

Link to comment
Share on other sites

Something like this:

_IENavigate($oIE, $aLines[$1] & "/mysite1.org", 0) ; navigate to site #1
_IELoadWait($oIE, 0, 60000) ; Wait for 1 minute
If @error Then _IENavigate($oIE, $aLines[$1] & "/mysite2.org") ; navigate to site#2
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If you run it from SciTE what do you get in the output pane?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Now, I have an IE form with form name "My Site" a single input field named Input_Field1, I want to read the value of this field and display on message box..

$IEName = _IECreate("www.mysite.com", 0,1,1,1) ; navigate to www.mysite.com
$oForm = _IEFormGetObjByName ($IEName, "My Site") ; get form name which is "My Site"
$name = _IEGetObjByName($oForm,"Input_Field1") ; name of input field
$InputVal = _IEFormElementGetValue($name) ; get the value of Input_Field1
MsgBox(0,"Input Field Value is",$InputVal)

My problem is the message box display is always 0, did I missed something?? :ermm:

Link to comment
Share on other sites

If you run this script from SciTE do you get any error messages in the output pane?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

OK, I manage to figure it out..: o:)

Now my problem is..

this code will work

$IEName = _IECreate("www.mysite.com", 0,1,1,1) ; navigate to www.mysite.com
$oForm = _IEFormGetObjByName ($IEName, "My Site") ; get form name which is "My Site"
$name = _IEGetObjByName($oForm,"Input_Field1") ; name of input field
$InputVal = _IEFormElementGetValue($name) ; get the value of Input_Field1
MsgBox(0,"Input Field Value is",$InputVal)

But if I'll used _IENavigate it doesn't..

$Site1 = _IECreate("www.mysite.com", 0,1,1,1) ; open www.mysite.com
$Site2 = _EINavigate($Site1, "www.mysite2.com",0) ;Navigate to site2
$oForm = _IEFormGetObjByName ($IEName, "My Site") ; get form name which is "My Site"
$name = _IEGetObjByName($oForm,"Input_Field1") ; name of input field
$InputVal = _IEFormElementGetValue($name) ; get the value of Input_Field1
MsgBox(0,"Input Field Value is",$InputVal)

BTW, If I want to SAVE the value of $InputVal instead displaying it on message box..

EDIT:

Done it with FileWriteLine

Edited by Hodahel
Link to comment
Share on other sites

  • 4 months later...

Hello,

My problem here is that, I want to display all text in the text file but the code below only display the first line. Is that possible?

GUICtrlSetData($Edit1 , FileReadLine($file)) ; reads only the first line of the file

Full Code

#include <GUIConstantsEx.au3>


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("About", 324, 370, 302, 218)
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 297)
$Edit1 = GUICtrlCreateEdit("", 24, 32, 281, 257)
GUICtrlSetData(-1, "Edit1")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 124, 312, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $file = FileOpen("D:\Inventory\error.txt")
            If $file = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf
            GUICtrlSetData($Edit1 , FileReadLine($file)) ; reads only the first line of the file
            FileClose($file)
    EndSwitch
WEnd
Edited by aguynamedray
Link to comment
Share on other sites

  • Moderators

aguynamedray,

Use FileRead in place of FileReadLine. :)

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...