Jump to content

Recommended Posts

Posted

Hello,

newbie programmer here... can someone please help explain the best way to return the value through the following function?

Example of desired usage:

For $x = 1 To Ubound($array)-1
    $chain = $array[$x][1]
    $retailer = _Retailer($chain)
    FileWrite($file, $chain & $retailer & @CRLF)
Next

 

Without all the necessary declarations (just posting the relevant stuff), I want to submit a variable ($chain) into the function _Retailer and get the corresponding retailer value.

 

The function would be something like but I'm not sure how to input a parameter and return a different variable:

Func _Retailer($chain)
$file = "\excel.xls"
Local $oApplM = _Excel_Open(False)
Local $oExcelM = _Excel_BookOpen($oApplM, $file)
Local $aArrayM = _Excel_RangeRead($oExcelM, Default, $oExcelM.ActiveSheet.Usedrange.Columns("A:D"), 1, True)

For $y = 1 To Ubound($aArrayM) - 1
    If $chain = $aArrayM[$y][2] Then
    $retailer = $aArrayM[$y][1]
    EndIf
Return $retailer
EndFunc

 

Posted
Func _Retailer($chn)
$file = "\excel.xls"
Local $oApplM = _Excel_Open(False)
Local $oExcelM = _Excel_BookOpen($oApplM, $file)
Local $aArrayM = _Excel_RangeRead($oExcelM, Default, $oExcelM.ActiveSheet.Usedrange.Columns("A:D"), 1, True)

For $y = 1 To Ubound($aArrayM) - 1
    If $chn = $aArrayM[$y][2] Then
    Local $ret = $aArrayM[$y][1]
    EndIf
Return $ret
EndFunc

Try this.. You have to watch Global and Local Variables and don't use the same name for different Variables.

 

8)

NEWHeader1.png

Posted
$chain = "399"

$retailer = _Retailer($chain)
ConsoleWrite($chain & "-" & $retailer & @CRLF)

Func _Retailer($chn)
$file = "C:\Program Files\AutoIt3\STAT\national.xls"
Local $oApplM = _Excel_Open(False)
Local $oExcelM = _Excel_BookOpen($oApplM, $file)
Local $aArrayM = _Excel_RangeRead($oExcelM, Default, $oExcelM.ActiveSheet.Usedrange.Columns("A:D"), 1, True)

For $y = 1 To Ubound($aArrayM) - 1
    If $chn = $aArrayM[$y][2] Then
    Local $ret = $aArrayM[$y][0]
    Return $ret
    EndIf

Next
EndFunc

Ah! That basically worked perfectly - needed the different variable names, and the return statement within the If statement.

Thank you very much!

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
×
×
  • Create New...