Sign in to follow this  
Followers 0
Realm

Reading an INI file

7 posts in this topic

I have a function that is supposed to read a line from a text file, than pull 2 values from an ini file. It pulls the info from the text file and splits it just fine, but is not assigning the needed values.

The text file looks like this per line

"Bog Wraith",7,0,"U","7E",03/20,"No"

the ini file in 2 sections looks like this

[Regular]

Bog Wraith (7E)=0.3,0.15

[Foil]

Bog Wraith (7E)=63,31.5

$CsvFile= FileOpen(@DesktopDir & "Testcoll.csv", 0)

While 1
    $Cardline = FileReadLine($CsvFile)
    If @error = -1 Then ExitLoop
    $CardData = StringSplit($Cardline, ",")

Global $CardName = $CardData[1], $CardSet = $CardData[5], $CardQty = $CardData[2], $CardPremium = $CardData[7]
Global $Buy, $Sell
Local $path = @DesktopDir & "Price_log.ini"

    Select
        Case $CardPremium = "No"
            $Read = IniRead ($path , "Regular", $CardName & " (" & $CardSet & ")", "Card Not Found")
            $CardPrice = StringSplit ($Read, ",")
            If $CardPrice[0] > 0 Then $CardPrice = $CardPrice[1]
            $Sell = $CardPrice
            $Read = IniRead ($path , "Regular", $CardName & " (" & $CardSet & ")", "Card Not Found")
            $CardPrice = StringSplit ($Read, ",")
            If $CardPrice[0] > 0 Then $CardPrice = $CardPrice[2];
            $Buy = $CardPrice
        Case $CardPremium = "Yes"
            $Read = IniRead ($path , "Foil", $CardName & " (" & $CardSet & ")", "Card Not Found")
            $CardPrice = StringSplit ($Read, ",")
            If $CardPrice[0] > 0 Then $CardPrice = $CardPrice[1]
            $Sell = $CardPrice
            $Read = IniRead ($path , "Foil", $CardName & " (" & $CardSet & ")", "Card Not Found")
            $CardPrice = StringSplit ($Read, ",")
            If $CardPrice[0] > 0 Then $CardPrice = $CardPrice[2]
            $Buy = $CardPrice
    EndSelect

    MsgBox(0,"hope this works", $CardName & " (" & $CardSet & ")= " & $CardQty & "  Foil= " & $CardPremium & @CRLF & "Buy Each $" & $Buy & "To Sell at $" & @CRLF & "Buy all " & $CardQty & " for $" & $CardQty * $Buy)
WEnd

FileClose($CsvFile)

This is what I have, can someone help me find those values. Any help is highly appreciated.


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites



Usually I don't help botters. :idea:

@DesktopDir & "\Price_log.ini"

"GO ... and sin no more."


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Usually I don't help botters. :idea:

@DesktopDir & "\Price_log.ini"

"GO ... and sin no more."

I'm not botting... The Game client allows you to download a csv file of your collection. so I'm building a script that will download prices from a website, and than evaluate the buy and sell value of my collection

even with the proper path it does not pull prices...I tried direct path C:\ and @DesktopDir....both will not read the ini. I cut the actual path out for my own reasons, and forgot to cut the forward slash also...

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Bog Wraith (7E) /= "Bog Wraith" ("7E")

edit:

No /= "No"

Yes /= "Yes"

etc.

Edited by Tvern

Share this post


Link to post
Share on other sites

With some Help, this snippet was fixed, but I ran across another problem, and need some input on what should be the best solution?

It now reads both the csv and the ini just fine. but I had to add a third section to the ini. But the ini is not the problem, the csv text file is.

had to add [Other] section to ini, which is the same as above. Problem is that in the csv file, some lines contain 7 elements, while a few contain only 6. I tried doing 'Case Else' as you can see below, before that I tried ' Case $CardData[7] = " "

How do i get around this. included is the new snippet.

7 element line:

"Bog Wraith",7,0,"U","7E",03/20,"No"

6 element line

"Zendikar Booster",0,0,"ZEN", ,"No"

Local $CardData, $CardPrice, $Section 
Local $inipath = @DesktopDir & "\MTGO Collection Analyzer\Price_log.ini"
Local $CsvFile = FileOpen(@DesktopDir & "\MTGO Collection Analyzer\MTGO CSV Files\Test_Collection.csv", 0)

While 1
    $CardData = FileReadLine($CsvFile)
    If @error = -1 Then ExitLoop
    $CardData = StringReplace($CardData,'"','')
    $CardData = StringSplit($CardData, ",")
    If $CardData[0] <> 
    If @error Then ExitLoop
    Select
        Case $CardData[7] = "No"
            $Section = "Regular" 
        Case $CardData[7] = "Yes"
            $Section = "Foil"
        Case Else
            $Section = "Other"
    EndSelect
    $CardPrice = IniRead($inipath , $Section, $CardData[1] & " (" & $CardData[5] & ")", "Card Not Found") 
    If @error Then ExitLoop
    $CardPrice = StringSplit ($CardPrice, ",")
    If @error Then ExitLoop
 
    $msg = $CardData[1] & " (" & $CardData[5] & ")" & @CRLF _ ;name and set
    & "Qty=" & $CardData[2] & "  Foil=" & $CardData[7] & @CRLF _ ;qty and foil
    & "Buy Each $" & StringFormat("%.2f",$CardPrice[2]) & " To Sell at $" & StringFormat("%.2f",$CardPrice[1]) & @CRLF _ ;buy and sellprice
    & "Buy all " & $CardData[2] & " for $" & StringFormat("%.2f",$CardData[2] * $CardPrice[2]) ;buy all price
    MsgBox(0,"This works", $msg)
WEnd
FileClose($CsvFile)

Any and all help is highly appreciated.


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

I'm not sure exactly what you need the result to be, but this should point you in the right direction:

#include<array.au3> ;add to top of script

Select ;replace the old select with this one
    Case $CardData[0] = 6
        $Section = "Other" ;set inisection to read
        _ArrayInsert($CardData,4,"") ;add an element to the array to make it compatible with the rest of the script (not sure this is the correct element to insert though)
    Case $CardData[7] = "No"
        $Section = "Regular"
    Case $CardData[7] = "Yes"
        $Section = "Foil"
EndSelect

Share this post


Link to post
Share on other sites

A Solution has been found.

Thank you Tvern for all your help!


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

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