KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Weather Forecaster

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
sptomey
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 18 Mar 2003
Posts: 158

PostPosted: Thu Mar 20, 2003 12:51 am    Post subject: Weather Forecaster Reply with quote

I can't take credit for alot of this code. Just thought the idea was so good at showing the capabilities of KiXForms that it should be posted. Lonkero wrote the FTPGet UDF and Radimus found the image converter thats downloadable from http://www.stinsv.com/jpgtobmp.htm. Just download it and put it in your systemdrive. Any thought of ever supporting jpeg or gif files?

Code:

;;;;;; ------------------------------------------------------------------------------------------------
;;;;;;   Description   :   Used to get the weather forecast for any given zip code
;;;;;;   Dependencies   :   DJPEG.exe to convert .jpg files to .bmp files.  Also gets image from weather.com.
;;;;;; ------------------------------------------------------------------------------------------------

Break On

; -------------------------------------------------------------------------------
;                                         Install KiXForms
; -------------------------------------------------------------------------------
$kixformsver = GetFileVersion("%windir%\kixforms.dll")
$kixformsdir = "\\server\share"
If $kixformsver < "2.2.0.37"
   copy "$kixformsdir\kixforms.dll" "%windir%\kixforms.dll"
Endif
If Exist ("%windir%\kixforms.dll")
   $Form = CreateObject("Kixtart.Form")
   If Not $Form
      Shell 'regsvr32.exe /s "%windir%\kixforms.dll"'
      $Form = CreateObject("Kixtart.Form")
      If Not $Form
         Messagebox ("There was a problem registering kixforms.dll in %windir%.","Error",0)
         Exit
      Endif
   Endif
Else
   Messagebox ("There was a problem copying kixforms.dll to %windir%.","Error",0)
   Exit
Endif


; -------------------------------------------------------------------------------
;                                             Draw Form
; -------------------------------------------------------------------------------

$Form.Caption = "Weather"
$Form.FontName = "arial"
$Form.FontSize = 8
$Form.Size = 275,255

$Label = $Form.Label("Zip Code:", 10, 15)
$ZipBox = $Form.ComboBox
$ZipBox.Left = 60
$ZipBox.Top = 10
$ZipBox.Width = 100
$ZipBox.AddItem ("Clear List")
$ZipBox.onClick = "GetWeather() UpdateZipList()"

$WeatherButton = $Form.ToolButton
$WeatherButton.Caption = "Get Weather"
$WeatherButton.Left = 190
$WeatherButton.Top = 11
$WeatherButton.Width = 70
$WeatherButton.Height = 20
$WeatherButton.OnClick = "GetWeather() UpdateZipList()"

$PictureBox = $form.picturebox('')
$PictureBox.left = 0
$PictureBox.top = 50
$PictureBox.width = 270
$PictureBox.height = 140

$ExitButton = $Form.ToolButton
$ExitButton.Caption = "Exit"
$ExitButton.Left = 100
$ExitButton.Top = 195
$ExitButton.Width = 70
$ExitButton.Height = 20
$ExitButton.OnClick = "ClearTemp() Quit()"

UpdateZipList()

$Form.Center
$Form.Show
While $Form.Visible
 $=Execute($Form.DoEvents)
Loop
Exit 1

; -------------------------------------------------------------------------------
;                                                UDFs
; -------------------------------------------------------------------------------
FUNCTION UpdateZipList()
   $zipcode = $ZipBox.Text
   If $zipcode = "Clear List"
      $Form.PrintXY(95,35,"Clearing List")
      sleep 2
      $PictureBox.Clear
      $count = 0
      While @Error = 0
         $ValueName = ENUMVALUE ("HKEY_Current_User\Software\KiXtart\WeatherZips", $count)
         If $ValueName > 1
            del "%temp%\$ValueName.bmp"
         Endif
         $count = $count + 1
      Loop
      $null = DelKey ("HKEY_Current_User\Software\KiXtart\WeatherZips")
      $Form.Clear
      $zipcode = ""
   Endif
   $ZipBox.Clear
   If $zipcode
      $count = 0
      While @Error = 0
         $ValueName = ENUMVALUE ("HKEY_Current_User\Software\KiXtart\WeatherZips", $count)
         If Instr ($ValueName, $zipcode)
            $count = 0
            While @Error = 0
               $ValueName = ENUMVALUE ("HKEY_Current_User\Software\KiXtart\WeatherZips", $count)
               If $ValueName > 1
                  $ZipBox.AddItem($ValueName)
               Endif
               $count = $count + 1
            Loop
            $ZipBox.AddItem ("Clear List")
            exit
         Endif
         $count = $count + 1
      Loop
      $null = WriteValue ("HKEY_Current_User\Software\KiXtart\WeatherZips", $zipcode, "", "REG_SZ")
   Endif
   $count = 0
   While @Error = 0
      $ValueName = ENUMVALUE ("HKEY_Current_User\Software\KiXtart\WeatherZips", $count)
      If $ValueName > 1
         $ZipBox.AddItem($ValueName)
      Endif
      $count = $count + 1
   Loop
   $ZipBox.AddItem ("Clear List")
ENDFUNCTION

FUNCTION GetWeather()
   $zip = $ZipBox.Text
   If $zip = "Clear List"
      exit
   Endif
   $Form.PrintXY(95,35,"Getting Weather")
   If Exist ("%temp%\$zip.bmp")
      $PictureBox.Picture="%temp%\$zip.bmp"
      $PictureBox.Refresh
      $Form.Clear
   Else
      FTPget("http://oap.weather.com/fcgi-bin/oap/generate_magnet?loc_id=$zip","%temp%\$zip.jpg")
      If @Error
         $null = Messagebox ("Error : "+@Error+" - "+@SError,"Error",0)
         Exit
      Endif
      Del "%temp%\$zip.bmp"
      Shell '%systemdrive%\djpeg.exe -bmp "%temp%\$zip.jpg"'
      Del "%temp%\$zip.jpg"
      $PictureBox.Picture="%temp%\$zip.bmp"
      $PictureBox.Refresh
      $Form.Clear
   Endif
ENDFUNCTION

FUNCTION FTPget($sURL, $sTargetFile, optional $sUser, optional $sPass)
   Dim $oFTP, $oStream
   $sUser=""+$sUser
   $oFTP = CreateObject("Microsoft.XMLHTTP")
   if @error
      $ftpget=1
      exit 1
   endif
   $oStream = CreateObject("ADODB.Stream")
   if @error
      $ftpget=2
      exit 2
   endif
   if $sUser
      $oFTP.Open("GET", $sURL, not 1, $sUser, $sPass)
   else
      $oFTP.Open("GET", $sURL, not 1)
   endif
   if @error
      $ftpget=3
      exit 3
   endif
   $oFTP.Send
   $oStream.Type = 1
   $oStream.Mode = 3
   $oStream.open
   $oStream.Write($oFTP.responseBody)
   if @error
      $ftpget=4
      exit 4
   endif
   $oStream.SaveToFile($sTargetFile, 2)
   if @error
      $ftpget=5
      exit 5
   endif
   $oStream.Close
ENDFUNCTION

FUNCTION ClearTemp()
   $count = 0
   While @Error = 0
      $ValueName = ENUMVALUE ("HKEY_Current_User\Software\KiXtart\WeatherZips", $count)
      If $ValueName > 1
         del "%temp%\$ValueName.bmp"
      Endif
      $count = $count + 1
   Loop
ENDFUNCTION
[/url]
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Mar 20, 2003 1:46 am    Post subject: Reply with quote

That is so cool and creative ... Cool Cool Cool Cool Cool Cool Cool Cool Cool Cool

It even returns the weather for Toronto, Canada. The code is:

CAXX0504

and my home town, Brampton, Ontario:

CAXX0043
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Thu Mar 20, 2003 3:41 am    Post subject: Reply with quote

Teh original thread out of which thsi form developed is at KORG under http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=14;t=000519
_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
ntdoc
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 77
Location: Mouse Country

PostPosted: Thu Mar 20, 2003 7:48 am    Post subject: Reply with quote

Nice little program idea there guys.

A couple comments.

1.
.DLL files should not go in %windir% they should go in %windir%\system32 on NT/2000/XP and %windir%\system for Windows 9x

2.
The code does not check if the zip code is blank when the Get Weather button is clicked.

3.
May be nice to have another small button to clear the image without clearing the zip list.
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Chris S.
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 241

PostPosted: Thu Mar 20, 2003 1:24 pm    Post subject: Reply with quote

I would also change how you test for KiXforms installation. My prefered method is to first create the form, test for form, then check build. After that, you can go through the trouble of copying it over and registering.
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Mar 20, 2003 1:50 pm    Post subject: Reply with quote

Agreed - I had to modify your script to get it to work on my machine. Not everyone has kixforms installed in system32. Try creating the form first then if it fails, dig deeper.
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Thu Mar 20, 2003 6:14 pm    Post subject: Reply with quote

I don't agree!
first, check for proper registeration.

it's easier to check the registry directly than code some 100 lines of check code.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Thu Mar 20, 2003 6:17 pm    Post subject: Reply with quote

btw, really much of ftpget() is coded by kdyer (kent dyer?)...

and, the thing I disagree with is not the proper check but the order it's done.

as far as I know, kixforms has been registered in the same main key and thus, the proper way is to check the registeration directly.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Fri Mar 21, 2003 7:28 am    Post subject: Reply with quote

You're right, except maybe if you go way back in 2000(1?) when there was a change between 2 builds ... But I think this can be forgotten Wink
_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
ntdoc
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 77
Location: Mouse Country

PostPosted: Fri Mar 21, 2003 10:23 pm    Post subject: Reply with quote

Lonkero, or Jochen

Please post the code that you think is appropriate so that others may view and critique if needed.

Thanks.
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Mar 22, 2003 2:16 am    Post subject: Reply with quote

j, if I remember correctly, the main-key changed but the current kixtart.form was there already at that time.

what comes to that code.
well, here is the part of me checker installer (the olde one) that handles the kf-part:
Code:
$id=readvalue("HKEY_CLASSES_ROOT\Kixtart.Form\CLSID","")
$location=readvalue("HKEY_CLASSES_ROOT\CLSID\"+$id+"\InprocServer32","")
$ver=""+getfileversion($location,"FileVersion")
if 2>len($ver)
 $location="%systemroot%\system32\kixforms.dll"
 copy "kixforms.dll" $location
 shell 'regsvr32 "%systemroot%\system32\kixforms.dll" /S'
else
 if "2.2.0.37"<>$ver
  if 6=messagebox("Current version of KixForms on your system is $ver and bbChecker has 2.2.0.37@crlfDo you want to Replace the current with bbChecker's one?","bbChecker II Installation",36)
   del $location
   copy "kixforms.dll" "%systemroot%\system32\kixforms.dll"
   shell 'regsvr32 "%systemroot%\system32\kixforms.dll" /S'
  endif
 endif
endif
del "kixforms.dll"

it's not the best or even good one.
but basically, that is the way to check directly the registered version.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
sptomey
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 18 Mar 2003
Posts: 158

PostPosted: Sun Mar 23, 2003 4:52 pm    Post subject: Reply with quote

Just a though...After hearing some of the first replies about how to check the KixForms.dll. Maybe make a common UDF to use for checking? Have tried to write one to check every possible scenario I can think of. But my limited KIX experience has probably left holes Im sure.

About putting the DLL in %windir% versus %windir%\system...I prefer just %windir% because on the Win9x machines I have checked the %windir%\system folder is not included in the path environment whereas the %windir% directory is.

Code:

If KixFormsVerCheck("\\server\share","2.2.0.37")
   ? "Problem getting KixForms to work."
Else
   ? "KixForms checks out fine."
Endif

get $


FUNCTION KixFormsVerCheck($KixFormsSrc,$KixFormsVerRequired)
$KixFormsSID = ReadValue ("HKEY_CLASSES_ROOT\Kixtart.Form\CLSID", "")
If $KixFormsSID
   $KixFormsLocation = ReadValue ("HKEY_CLASSES_ROOT\CLSID\$KixFormsSID\InprocServer32", "")
   If $KixFormsLocation
      If Exist ("$KixFormsLocation")
         $KixFormsVer = GetFileVersion("$KixFormsLocation")
         If $KixFormsVer >= $KixFormsVerRequired
            $NullForm = CreateObject("Kixtart.Form")
            If $NullForm
               Exit 0
            Else
               ; "Form not created from dll version $KixFormsVer located at $KixFormsLocation.  DLL must be corrupt.  Try re-copying and re-registering."
               shell 'regsvr32.exe /s "$KixFormsLocation"'
               $NullForm = CreateObject("Kixtart.Form")
               If $NullForm
                  Exit 0
               Else
                  del "$KixFormsLocation"
                  copy "$KixFormsSrc" "$KixFormsLocation"
                  shell 'regsvr32.exe /s "$KixFormsLocation"'
                  $NullForm = CreateObject("Kixtart.Form")
                  If $NullForm
                     Exit 0
                  Else
                     ; "You are totally hosed.  Have tried re-copying and re-registering the KixForms.dll."
                     Exit 1
                  Endif
               Endif
            Endif
         Else
            ; "KixForms DLL that is registered and located at $KixFormsLocation is outdated.  Will re-copy."
            del "$KixFormsLocation"
            copy "$KixFormsSrc" "$KixFormsLocation"
            shell 'regsvr32.exe /s "$KixFormsLocation"'
            $NullForm = CreateObject("Kixtart.Form")
            If $NullForm
               Exit 0
            Else
               ; "You are totally hosed.  Have tried re-copying and re-registering the KixForms.dll."
               Exit 1
            Endif
         Endif
      Else
         ; "KixForms registered to DLL located at $KixFormsLocation but DLL not found.  Will copy DLL to this lcoation."
         copy "$KixFormsSrc" "$KixFormsLocation"
         shell 'regsvr32.exe /s "$KixFormsLocation"'
         $NullForm = CreateObject("Kixtart.Form")
         If $NullForm
            Exit 0
         Else
            ; "You are totally hosed.  Have tried re-copying and re-registering the KixForms.dll."
            Exit 1
         Endif
      Endif
   Else
      ; "KixForms registration not complete.  Location not found.  Will try re-copying and re-registering."
      copy "$KixFormsSrc" "%windir%"
      shell 'regsvr32.exe /s "%windir%"'
      $NullForm = CreateObject("Kixtart.Form")
      If $NullForm
         Exit 0
      Else
         ; "You are totally hosed.  Have tried re-copying and re-registering the KixForms.dll."
         Exit 1
      Endif
   Endif
Else
   ; "KixForms Not Registered.  Will copy and register."
   copy "$KixFormsSrc" "$KixFormsLocation"
   shell 'regsvr32.exe /s "$KixFormsLocation"'
   $NullForm = CreateObject("Kixtart.Form")
   If $NullForm
      Exit 0
   Else
      ; "You are totally hosed.  Have tried re-copying and re-registering the KixForms.dll."
      Exit 1
   Endif
Endif
ENDFUNCTION

_________________
-Shane
Back to top
View user's profile Send private message MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sun Mar 23, 2003 4:59 pm    Post subject: Reply with quote

oh...
I see that you didn't check the code in:
http://www.kixforms.org/forum/viewtopic.php?p=455#455
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
sptomey
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 18 Mar 2003
Posts: 158

PostPosted: Sun Mar 23, 2003 5:02 pm    Post subject: Reply with quote

Nope...Miseed it totally...lol. Very Happy Thanks for the pointer. Have not been online as of late.
_________________
-Shane
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group