Valentim
(Fresh Scripter)
2019-11-28 06:57 PM
error in function ReadProfileString

I am trying to run the script below, but an error is displayed on line 4, would anyone have any suggestions?

 Code:
Break ON
$cor = @COLOR

$GrpArray = split(ReadProfileString($pFile, "", ""), chr(10))
For Each $Grupo in $GrpArray
    If $pOpc = "R"
        If ($Grupo = "Service")
            $GrpChave = split(ReadProfileString($pFile, $Grupo, ""), chr(10))
            $Server = ReadProfileString($pFile, $Grupo, "Name")
            ? COLOR +G/n $Grupo COLOR +Y/n " ->" COLOR +R/n " Service" COLOR +Y/n " = " COLOR +W/n $Server COLOR $cor
        EndIf
        If ($Grupo = "TCP")
            $GrpChave = split(ReadProfileString($pFile, $Grupo, ""), chr(10))
            $Port = ReadProfileString($pFile, $Grupo, "Port")
            ? COLOR +G/n $Grupo COLOR +Y/n " ->" COLOR +R/n " Port  " COLOR +Y/n " = " COLOR +W/n $Port   COLOR $cor
        EndIf
    EndIf
Next


 Code:
Port Tools
ERROR : invalid method/function call: too many parameters!
Script: M:\ports.kix
Line  : 4


JochenAdministrator
(KiX Supporter)
2019-11-28 07:35 PM
Re: error in function ReadProfileString

You haven't declared $pFile in your sample, but apart from that, if I don't do this here it doesn't die with too many parameters error..

If I create an ini file with some sections and point $pFile to it your line 4 perfectly creates an array with the section names. The rest of your functions look perfectly allright, except maybe that $pOpc wasn't set anywhere ;\)

I guess this is only part of a bigger script, right?


JochenAdministrator
(KiX Supporter)
2019-11-28 07:42 PM
Re: error in function ReadProfileString

Oh by the way, the following will get rid of the last empty array element when reading in sections (or keys for that matter)

 Code:
$GrpArray = split(left(ReadProfileString($pFile, "", ""),-1), chr(10))