Jump to content

Variables not being passed to array?


Recommended Posts

Hi. I've managed to piece this script together from tutorials and examples I've found, but I've hit a dead-end and could use a little help. I'm trying to create a script that will transfer text from a specific page onto an Excel worksheet. According to what I've read, it should enter 'pizza' into cel A3 of an Excel worksheet, and 'developer' into cel A4.

#include <Array.au3>
#include <Excel.au3>
#Include <FF.au3>
#include <String.au3>

    ; Go to page and copy the source to clipboard.
If _FFStart("http://ff-au3-example.thorsten-willert.de/") Then
    $sHTML = _FFReadHTML()
    If Not @error Then ClipPut($sHTML)
EndIf


Example()

Func Example()
    ; Declare variables and set to the words surrounding "pizza" and "developer".
    Local $sWordOne = _StringBetween($sHTML, "hlen Sie eine ", ":</legend>")
    Local $sWordTwo = _StringBetween($sHTML, "Mozilla ", " center")


    ; Create application object and create a new workbook
    Local $oAppl = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookNew($oAppl)
        If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oAppl)
        Exit
        EndIf

; *****************************************************************************
; Write a 1D array to the active sheet in the active workbook
; *****************************************************************************
Global $aArray1D = [$sWordOne, $sWordTwo]
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray1D, "A3")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "1D array successfully written.")
EndFunc ;==>Example

But for some reason, the values of variables $sWordOne and $sWordTwo seem to get deleted before it reaches the Excel page, so the cels just wind up blank. I've double (and triple) checked that the _StringBetween variables are correct when used on their own. I've also found that if I change the variables to integers, it copies them to Excel as it should. I've spent a few hours looking at this and getting nowhere. Am I doing something obviously wrong?

Edited by CharlesStamp
Link to comment
Share on other sites

They do, but that doesn't seem to be the issue. If I use a string, integer or combination of them for the variables it passes them to Excel. It also seems to work fine with just one variable, too. But if there's more than one they just go blank. As far as I can tell it should work, but I don't have much experience with this. I had a similar problem displaying them in arrays, too.

Edited by CharlesStamp
Link to comment
Share on other sites

I haven't heard about maps before now, but I tried making the change you suggested and the problem now is that it copies $sWordOne to both cels. Again, I get a similar problem when I just display the array, so the issue doesn't seem to be related to Excel or its UDF. It seems to be a problem with how _StringBetween variables are managed.

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

×
×
  • Create New...