Jump to content

Recommended Posts

Posted (edited)

I'll try to describe the problem so that I do not need to post any code, if its necessary then I will include it.

I'm trying to read a line in a file that I write each time from a website's source.

I know how to read the number of that line, print it, all that good stuff.

The problem is that the distance between the variables I need changes depending on certain user information.

I have tried to solve this problem by obtaining those inputs from the user and calculating their StringLen() in order to add them to the total calculated ReadFile() expressions.

I will post an example of the line I am trying to read to show you the part that varies depending on the user.

The variables are strings "New York", "Chicago", "Toronto", "Boston", "Los Angeles", "Mexico City".

..and the values I want to obtain from this expression are "123456","7891011","121314","151617","181920" and "212223"

<option class="avatarCities tradegood2" value="123456" selected="selected" title="[91:33]" >New York</option><option class="avatarCities tradegood1" value="7891011" title="[92:32]" >Chicago</option><option class="avatarCities tradegood2" value="121314" title="[91:33]" >Toronto</option><option class="avatarCities tradegood4" value="151617" title="[92:35]" >Boston</option><option class="avatarCities tradegood3" value="181920" title="[92:33]" >Los Angeles</option><option class="avatarCities tradegood1" value="212223" title="[89:34]" >Mexico City</option> </select>

Ok, now my question is.. is there a better way to specify what the ReadFile is looking for so that I don't have to do something like this.

GuiCtrlCreateLabel("Please input each of your city names here",10,10)
$a=GuiCtrlCreateInput($first,10,50,80,18)
...
...
$first=StringLen("New York")
$cityiduno=StringMid(FileReadLine("foop.ini",351),39+$first,6)
Edited by myxomatosii
Posted

Is foop.ini really a INI file (structure/layout)? In which case you are better off using the IniRead function.

GuiCtrlCreateLabel("Please input each of your city names here",10,10)
$a=GuiCtrlCreateInput($first,10,50,80,18)
...
...
$first=StringLen("New York")
$cityiduno=StringMid(FileReadLine("foop.ini",351),39+$first,6)
Posted (edited)

Is foop.ini really a INI file (structure/layout)? In which case you are better off using the IniRead function.

Its from a PHP website's source, I saw the ini() commands in the function library and thought about making labels and writing to the file in certain areas but that seemed like a big ordeal.

I saved it as a .ini because typically user's do not associate them with anything they would have made or would interact with and I didn't want to cause any confusion. I delete it right afterward so I guess there is really no point, but thats why I did it x,x

Edited by myxomatosii
Posted

I am not trying to avoid answering your original question, rather change the way you have thought this out.

I'm trying to read a line in a file that I write each time from a website's source.

If you are doing this (above) then I would recommend using AutoIt's INI read/write functions since they make it so easy to read to and write out to INI files.

Both can be accomplished in a single line of code, do check the help file for IniWrite(), and IniRead(). You can then revisit your original issues with locating/transforming text read from file.

Posted (edited)

I'll just go ahead and post the entire code.

By the way, it all works except for line 82 which I am currently getting help with.

Just thought there may be an easier method.

;AutoItSetOption("TrayIconHide",1)
Func ikalaunch()
    Global $continuebutton,$ikabutton,$msg
    GuiCreate("Ikariam",150,100)
    GuiSetState(@sw_show)
    GuiCtrlCreateLabel("Please login to Ikariam,",10,10)
    GuiCtrlCreateLabel("click continue once the",10,25)
    GuiCtrlCreateLabel("page is loaded.",10,40)
    $continuebutton=GuiCtrlCreateButton("Continue",10,60,65,20)
    $ikabutton=GuiCtrlCreateButton("www.ikariam.com",10,80,115,20)
    While 1
        $msg=GuiGetMsg()
        Select
            Case $msg=$continuebutton
                GuiSetState(@sw_hide)
                ExitLoop
            Case $msg=$ikabutton
                ShellExecuteWait("www.ikariam.com")
        EndSelect
    WEnd
EndFunc
Func ikasource()
    While 1
        If WinActive("Ikariam - World Alpha ")Then
            BlockInput(1)
            Send("^u")
            WinActivate("Source of: http://")
            Send("^a")
            Sleep(300)
            Send("^c")
            Sleep(300)
            FileWrite("foop.ini",ClipGet())
            WinClose("")
            BlockInput(0)
            ExitLoop
        EndIf
    WEnd
EndFunc
Func readwrite()
;add gui here to get city names
    $first=StringLen("---------");9
    $second=StringLen("--------");8
    $third=StringLen("------");6
    $fourth=StringLen("----------");10
    $fifth=StringLen("-----------");11
    $sixth=StringLen("--------");8
    $cityiduno=StringMid(FileReadLine("foop.ini",351),39+$first,6)
    $cityiddos=StringMid(FileReadLine("foop.ini",351),141+$first+$second,6)
    $cityidtres=StringMid(FileReadLine("foop.ini",351),224+$first+$second+$third,6)
    $cityidcuatro=StringMid(FileReadLine("foop.ini",351),301+$first+$second+$third+$fourth,6)
    $cityidcinco=StringMid(FileReadLine("foop.ini",351),381+$first+$second+$third+$fourth+$fifth,6)
    $cityidseis=StringMid(FileReadLine("foop.ini",351),465+$first+$second+$third+$fourth+$fifth+$sixth,6)
;$cityidsiete=StringMid(FileReadLine("foop.ini",351),48,6)
;$cityidocho=StringMid(FileReadLine("foop.ini",351),48,6)
;$cityidnueve=StringMid(FileReadLine("foop.ini",351),48,6)
;$cityiddiez=StringMid(FileReadLine("foop.ini",351),48,6)
    MsgBox(0,"Test",$cityiduno&" "&$cityiddos&" "&$cityidtres&" "&$cityidcuatro&" "&$cityidcinco&" "&$cityidseis&".",1)
;FileDelete("foop.ini")
;FileRecycleEmpty("")
EndFunc
Func getNames()
    local $first,$second,$third,$fourth,$fifth,$sixth,$seventh,$eighth
    global $a,$b,$c,$d,$e,$f,$g,$h
    GuiCreate("City Names",250,250)
    GuiSetState(@sw_show)
    GuiCtrlCreateLabel("Please input each of your city names here",10,10)
    GuiCtrlCreateLabel("Please leave any extra boxes blank",10,30)
    GuiCtrlCreateLabel("First City",100,50)
    GuiCtrlCreateLabel("Second City",100,70)
    GuiCtrlCreateLabel("Third City",100,90)
    GuiCtrlCreateLabel("Fourth City",100,110)
    GuiCtrlCreateLabel("Fifth City",100,130)
    GuiCtrlCreateLabel("Sixth City",100,150)
    GuiCtrlCreateLabel("Seventh City",100,170)
    GuiCtrlCreateLabel("Eighth City",100,190)
    $a=GuiCtrlCreateInput($first,10,50,80,18)
    $b=GuiCtrlCreateInput($second,10,70,80,18)
    $c=GuiCtrlCreateInput($third,10,90,80,18)
    $d=GuiCtrlCreateInput($fourth,10,110,80,18)
    $e=GuiCtrlCreateInput($fifth,10,130,80,18)
    $f=GuiCtrlCreateInput($sixth,10,150,80,18)
    $g=GuiCtrlCreateInput($seventh,10,170,80,18)
    $h=GuiCtrlCreateInput($eighth,10,190,80,18)
    $lena=StringLen(GuiCtrlRead($a))
    While 1
        MsgBox(0,"test",$lena,0)
    WEnd
EndFunc

ikalaunch()
ikasource()
readwrite()
getNames()
Edited by myxomatosii
Posted

I am not trying to avoid answering your original question, rather change the way you have thought this out.

If you are doing this (above) then I would recommend using AutoIt's INI read/write functions since they make it so easy to read to and write out to INI files.

Both can be accomplished in a single line of code, do check the help file for IniWrite(), and IniRead(). You can then revisit your original issues with locating/transforming text read from file.

Alrite, I'll go re-check it out, I probably missed something my first visit, thanks for the feedback =)

I'll update this with my path in a bit..

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
  • Recently Browsing   0 members

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