Jump to content

COM error with DOM...?


Recommended Posts

I don't know who DOM is but he is making me miserable.

Most of this code is thanks to Cartman380, i tried to add two new buttons and link them to a web page...but I'm dumb apparently and I don't know what i'm doing wrong...help...please....

if you scroll through this you'll see I've added the two buttons "Radar" and "Hourly Forecast". then if you scroll to the bottom where they are called out in the case structure, you'll see I've added the "_iecreate" for both. However if you just run the damn thing, and select "check weather" first then try either of the two i have created, it gives me the COM errors and won't play nice. Ultimately, these two buttons should be incorporated into the program without linking to the web. But i guess I'll have to wait until Cartman380 helps me with that. (unless one of you knows already). I really want to LEARN this, and he has gracefully helped me so far. Any suggestions?

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Wall06.ico
#AutoIt3Wrapper_outfile=MotoWeather\MotoWeather.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Fileversion=1.2.0.7
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_Language=1033
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <IE.au3>
#include <_XMLDomWrapper.au3>
#include <Array.au3>
#include <INet.au3>
#include <GUIConstants.au3>

Dim $aKeys[1], $aValues[1]
Local $City, $Region, $DayToday, $DateToday, $LowToday, $HighToday, $ConditionToday, $PercentMatch
Local $DayTomorrow, $DateTomorrow, $LowTomorrow, $HighTomorrow, $ConditionTomorrow, $Percent, $Condition, $count
Local $LowTemp, $HighTemp, $Zip, $lowTempTest, $highTempTest, $zipTest

#Region ### START Koda GUI section ### Form=
$MotoForm = GUICreate("MotoWeather", 349, 409, -1, -1)
$Progress1 = GUICtrlCreateProgress(64, 8, 150, 16)
$btnStart = GUICtrlCreateButton("Check Weather", 248, 8, 91, 25)
$Label1 = GUICtrlCreateLabel("Progress:", 8, 8, 48, 17)
$Label2 = GUICtrlCreateLabel("High Today:", 8, 72, 62, 17)
$lblHigh = GUICtrlCreateLabel("", 80, 72, 59, 17)
$Label3 = GUICtrlCreateLabel("Low Today:", 8, 104, 60, 17)
$lblLow = GUICtrlCreateLabel("", 80, 104, 59, 17)
$btnProperties = GUICtrlCreateButton("Properties", 248, 36, 91, 25)
$btnRadar = GUICtrlCreateButton("Radar", 248, 64, 91, 25)
$btnHourly = GUICtrlCreateButton("Hourly Forecast", 248, 92, 91, 25)
$Label5 = GUICtrlCreateLabel("Precipitation:", 8, 208, 76, 17)
$lblPercent = GUICtrlCreateLabel("", 96, 208, 59, 17)
$lblDateLoc = GUICtrlCreateLabel("", 8, 40, 227, 17)
$Group1 = GUICtrlCreateGroup("Conditions", 8, 136, 329, 57)
$lblCondition = GUICtrlCreateLabel("", 16, 154, 316, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Suggestion", 8, 240, 329, 73)
$lblSuggest = GUICtrlCreateLabel("", 16, 258, 316, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Tomorrow's Weather", 8, 328, 329, 73)
$lblTomorrowWeather = GUICtrlCreateLabel("", 16, 346, 316, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $btnStart
            If Not FileExists('C:\Program Files\MotoWeather\Config.ini') Then; create ini dir if it doesn't exist
                DirCreate('C:\Program Files\MotoWeather')
                _ModifyIni(); populate ini file
            EndIf
            
            $Zip = IniRead('C:\Program Files\MotoWeather\Config.ini', 'Zip', 'Code', ""); get zip from ini file
            $LowTemp = IniRead('C:\Program Files\MotoWeather\Config.ini', 'TempLimits', 'Low', ""); get low temp from ini file
            $HighTemp = IniRead('C:\Program Files\MotoWeather\Config.ini', 'TempLimits', 'High', ""); get high temp from ini file
            $temp = VariableTest()
            If ($temp <> 0) Then _ModifyIni()
            
            GUICtrlSetData($Progress1, 10)
            
            $window =_IECreate("http://www.rssweather.com/hw3.php?pands=" & $Zip, 0, 0); create IE Window set to invisble
            $text = _IEBodyReadText($window); read the text off the page            
            $split = StringSplit($text, @CR); split the text found on the website into an array
            _IEQuit($window); closes the IE object and the process associated with it

            For $i = 0 To UBound($split); loop through the array
                $temp = StringInStr($split[$i], "Updated:", 0); get to the point where it says updated
                If ($temp <> 0) Then
                    $temp = $i + 1
                    ExitLoop; exit once Updated: is found
                EndIf               
            Next
            
            GUICtrlSetData($Progress1, 25)
            
            $Storm = StringInStr($split[$temp], "storm", 0); check for storm
            $Snow = StringInStr($split[$temp], "snow", 0); check for snow
            $Rain = StringInStr($split[$temp], "rain", 0); check for rain
            $Showers = StringInStr($split[$temp], "showers", 0); check for showers          
            If($Storm > 0 Or $Snow > 0 Or $Rain > 0  Or $Showers > 0) Then
                $BadWeather = $split[$temp]; get the bad weather condition string
                $BadWeather = StringStripCR($BadWeather)
                $temp += 1; go down to the next line                
                $PercentLoc  = StringInStr($split[$temp], "Percentage:", 0); look for percentage
                If ($PercentLoc > 0) Then; if percentage is found grab the number
                    $Length = StringLen($split[$temp]); get the string length
                    $Percent = StringRight($split[$temp], ($Length - ($PercentLoc + 11))); grab the rest of the string after the Percentage: location
                    $Percent = StringStripWS($Percent, 3); remove leading and trailing spaces                   
                Else
                    $Percent = "N/A"; if percent not found just put N/A out there
                EndIf
            Else
                $Percent = "N/A"; if not bad weather just put N/A out there
            EndIf
            GUICtrlSetData($Progress1, 40)
            
     ;connect to the Yahoo RSS and retrieve the weather information
            $WeatherXML = _INetGetSource("http://weather.yahooapis.com/forecastrss?p=" & $Zip)
            _XMLLoadXML($WeatherXML, 'xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"')
            If @ERROR Then
                MsgBox(0,"",@ERROR)
                Exit
            EndIf
            
            GUICtrlSetData($Progress1, 75)
     ;Retrieve city
            $City = _XMLGetAttrib("/rss/channel/yweather:location", "city")
     ;Retrieve region
            $Region = _XMLGetAttrib("/rss/channel/yweather:location", "region")
            
     ; Loop through to grab todays and tomorrows weather
            $count = _XMLGetNodeCount("/rss/channel/item/yweather:forecast")
            For $X = 1 to $count                
                $aNodes = _XMLGetAllAttrib("/rss/channel/item/yweather:forecast["&$X&"]", $aKeys, $aValues)             
                For $Y = 0 to Ubound($aKeys)-1
                    If ($X = 1) Then
                        Switch $aKeys[$Y]
                            Case "day"
                                $DayToday = $aValues[$Y]
                            Case "date"
                                $DateToday = $aValues[$Y]
                            Case "low"
                                $LowToday = $aValues[$Y]
                            Case "high"
                                $HighToday =$aValues[$Y]
                            Case "text"
                                $ConditionToday = $aValues[$Y]
                        EndSwitch
                    EndIf
                    
                    If ($X = 2) Then
                        Switch $aKeys[$Y]
                            Case "day"
                                $DayTomorrow = $aValues[$Y]
                            Case "date"
                                $DateTomorrow = $aValues[$Y]
                            Case "low"
                                $LowTomorrow = $aValues[$Y]
                            Case "high"
                                $HighTomorrow =$aValues[$Y]
                            Case "text"
                                $ConditionTomorrow = $aValues[$Y]
                        EndSwitch
                    EndIf
                Next
            Next
            
            GUICtrlSetData($Progress1, 95)
        
            $Tornado = StringInStr( $ConditionToday, "tornado", 0)
            $Flood = StringInStr( $ConditionToday, "flood", 0)
            $Fog = StringInStr( $ConditionToday, "fog", 0)
            $Heat = StringInStr( $ConditionToday, "heat", 0)
            
            If ($Tornado > 0 Or $Flood > 0 Or $Fog >  0 Or $Heat > 0 Or $Storm > 0 Or $Snow > 0 Or $Rain > 0  Or $Showers > 0) Then
                $Condition = "Bad"
                If ($BadWeather <> "") Then $ConditionToday = $ConditionToday & " / " & $BadWeather; use both if bad weather was set to something
            Else
                $Condition = "Good"
            EndIf
            
            
            
            GUICtrlSetData($lblHigh, $HighToday)
            GUICtrlSetData($lblLow, $LowToday)
            GUICtrlSetData($lblCondition, $ConditionToday)
            GUICtrlSetData($lblDateLoc, $DayToday & " " & $DateToday & @TAB & $City & ", " & $Region)
            GUICtrlSetData($lblPercent, $Percent)
            GUICtrlSetData($lblTomorrowWeather, $DayTomorrow & " " & $DateTomorrow & @CRLF & "High: " & $HighTomorrow & "  Low: " & $LowTomorrow & @CRLF & $ConditionTomorrow)
            
            If ($LowToday > $LowTemp And $HighToday < $HighTemp And $Condition = "Good") Then
                GUICtrlSetData($lblSuggest, "Today Should Be A Great Ride!" & @CRLF & $ConditionToday & @CRLF & "High: " & $HighToday & " " & "Low: " & $LowToday)
            ElseIf ($LowToday > $LowTemp And $HighToday < $HighTemp And $Condition = "Bad") Then
                GUICtrlSetData($lblSuggest, "CAUTION! - Bad Weather Predicted" & @CRLF & $ConditionToday)
            ElseIf (($LowToday <= $LowTemp Or $HighToday >= $HighTemp) And $Condition = "Good") Then
                GUICtrlSetData($lblSuggest, 'CAUTION! - Out of Temperature Range' & @CRLF & "High: " & $HighToday & " " & "Low: " & $LowToday)
            ElseIf (($LowToday <= $LowTemp Or $HighToday >= $HighTemp) And $Condition = "Bad")  Then
                GUICtrlSetData($lblSuggest, 'EXTEME CAUTION! - Riding Not Advised!' & @CRLF & $ConditionToday & @CRLF & "High: " & $HighToday & " " & "Low: " & $LowToday)
            EndIf           
        Case $btnProperties
            If Not FileExists('C:\Program Files\MotoWeather\Config.ini') Then DirCreate('C:\Program Files\MotoWeather'); create ini file if it doesn't exist
            _ModifyIni(); populate ini file
        Case $btnHourly
            $Zip = IniRead('C:\Program Files\MotoWeather\Config.ini', 'Zip', 'Code', ""); get zip from ini file
            $oIE = _IECreate ("http://www.weather.com/weather/hourbyhour/" & $Zip)  
        Case $btnRadar
            $Zip = IniRead('C:\Program Files\MotoWeather\Config.ini', 'Zip', 'Code', ""); get zip from ini file
            $oIE = _IECreate ("http://www.weather.com/weather/map/interactive/" & $Zip)     
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch   
WEnd


Func _ModifyIni()   
    $winPos = WinGetPos("MotoWeather", "Check Weather"); gets the window position places the coordinates into an array
    $xPos = $winPos[0]; the x position is in the first spot in the array (zero means first)
    $yPos = $winPos[1]; the y position is in the second spot in the array
    #Region ### START Koda GUI section ### Form=
    $frmProperities = GUICreate("MotoWeather Properties", 237, 164, $xPos, $yPos, -1, -1, $MotoForm)
    $Label2 = GUICtrlCreateLabel("Highest Temperature:", 8, 16, 106, 17)
    $inHigh = GUICtrlCreateInput("", 128, 8, 65, 21)
    $inLow = GUICtrlCreateInput("", 128, 48, 65, 21)
    $Label3 = GUICtrlCreateLabel("Lowest Temperature:", 8, 56, 104, 17)
    $Label1 = GUICtrlCreateLabel("Zip Code:", 60, 96, 50, 17)
    $inZip = GUICtrlCreateInput("", 128, 88, 65, 21)
    $btnSubmit = GUICtrlCreateButton("Save", 72, 128, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($frmProperities); remove properties window
                ExitLoop; ExitLoop exits out of the loop and does the code after the WEnd, which is nothing
            Case $btnSubmit
                $LowTemp = GUICtrlRead($inLow); read the input from user for low temp
                $HighTemp = GUICtrlRead($inHigh); read the input from user for high temp
                $Zip = GUICtrlRead($inZip); read the input from user for zip code
                $temp = VariableTest()
                Switch $temp
                    Case 0
                        WriteIni(); write to the ini file
                        GUIDelete($frmProperities); remove properties window                    
                        ExitLoop; Exit Loop will exit the while loop, in this case goes back to the main window
                    Case 1
                        MsgBox(48, "Error", "Low Temperature is higher than High Temperature, Try Again")
                        ContinueLoop; Continue Loop ignores all logic after this point and returns to the While 1 statement in this function
                    Case 2
                        MsgBox(48, "Error", "Zip Code must be a 5 digit number, Try Again")
                        ContinueLoop; Continue Loop ignores all logic after this point and returns to the While 1 statement in this function
                    Case 3
                        MsgBox(48, "Error", "Low Temperature must be a 1 to 3 digit number, Try Again")
                        ContinueLoop; Continue Loop ignores all logic after this point and returns to the While 1 statement in this function
                    Case 4
                        MsgBox(48, "Error", "High Temperature must be a 1 to 3 digit number, Try Again")
                        ContinueLoop; Continue Loop ignores all logic after this point and returns to the While 1 statement in this function
                EndSwitch               
        EndSwitch
    WEnd    
EndFunc

Func WriteIni()
    If Not FileExists('C:\Program Files\MotoWeather\Config.ini') Then DirCreate('C:\Program Files\MotoWeather'); create ini file directory if it doesn't exist
    IniWrite('C:\Program Files\MotoWeather\Config.ini', 'TempLimits', 'Low', $LowTemp); write the low temp to ini file
    IniWrite('C:\Program Files\MotoWeather\Config.ini', 'TempLimits', 'High', $HighTemp); write the high temp to ini file
    IniWrite('C:\Program Files\MotoWeather\Config.ini', 'Zip', 'Code', $Zip); write the zip code to ini file
EndFunc

Func VariableTest()
    $zipTest = StringRegExp($Zip, "\d{5}"); check to see if it is a 5 digit number
    $lowTempTest = StringRegExp($LowTemp, "\d{1,3}"); check to see if it is a 1-3 digit number
    $highTempTest = StringRegExp($LowTemp, "\d{1,3}"); check to see if it is a 1-3 digit number
    If($zipTest = 1 And $lowTempTest = 1 And $highTempTest = 1) Then; check to see if all variables match pattern
        If($LowTemp < $HighTemp) Then; if Low Temperature is less than High Temperature         
            Return 0; return 0 (or success in this case)
        Else            
            Return 1; return 1 (or error in this case, low temp > high temp)
        EndIf
    ElseIf($zipTest <> 1) Then      
        Return 2; return 2 (or error in this case, zip code does not match pattern)
    ElseIf($lowTempTest <> 1) Then      
        Return 3; return 3 (or error in this case, low temp does not match pattern)
    ElseIf($highTempTest <> 1) Then     
        Return 4; return 4 (or error in this case, high temp does not match pattern)    
    EndIf
EndFunc
Link to comment
Share on other sites

Show the errors.

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

First, please run your script from SciTe editor (F5). The console will give you helpful info.

Second, place this line after you IE.au3 include: _IEErrorHandlerRegister(). You may also want to use SciTe Debug Mode (see my sig).

See if it helps you figure it out.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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

  • Recently Browsing   0 members

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