babe of the day

Author Message
thefamousnomo

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 6/10/2009
  • Status: offline
babe of the day Wednesday, June 10, 2009 7:50 PM (permalink)
0
heres a wee quick and dirty(!) script that i wrote for a pal

 on error resume next ' just incase the file exists or no internet
 dim url, wsh
 url = "http://www.babeoftheday.org/babe.jpg" ' just happens to exist
 set xmlhttp = CreateObject("Microsoft.XMLHTTP")
 xmlhttp.open "GET", url, False
 xmlhttp.send() ' get file
 set sGet = CreateObject("ADODB.Stream")
 sGet.Type = 1
 sGet.Open()
 sGet.Write(xmlhttp.responseBody) ' write file
 sGet.SaveToFile "C:\" & Day(Date) & Month(Date) & Year(Date) & ".jpg"', 2 ' save file
 sGet.Close
 set wsh = CreateObject("WScript.Shell")
 wsh.regwrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\" & Day(Date) & Month(Date) & Year(Date) & ".jpg" ' set desktop background
 wsh.regwrite "HKCU\Control Panel\Desktop\WallpaperStyle", "0"
 set xmlhttp = nothing
 set sGet = nothing
 url = nothing
 


could include a wee bit of error checking, but it serves a purpose

could i ask a couple of questions at this point?

- how important is case sensitivity?
- should i xmlhttp.close()?

:D
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: babe of the day Thursday, June 11, 2009 1:58 AM (permalink)
    0
    VBScript commands are not case sensitive. As for closing resources, the garbage collector is pretty good but it never hurts to be explicit.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      TNO

      • Total Posts : 2094
      • Scores: 36
      • Reward points : 0
      • Joined: 12/18/2004
      • Location: Earth
      • Status: offline
      RE: babe of the day Thursday, June 11, 2009 6:39 AM (permalink)
      0
      The language is not case sensitive, but you should pretend it is anyway for readability. For example, here is your exact same code with some very minor improvements:

       On Error Resume Next ' just incase the file exists or no internet
       
       Dim url : url = "http://www.babeoftheday.org/babe.jpg" ' just happens to exist
       Dim wsh : Set wsh = CreateObject("WScript.Shell")
       Dim xmlhttp : Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
       Dim sGet : Set sGet = CreateObject("ADODB.Stream")
       
       xmlhttp.open "GET", url, False
       xmlhttp.send() ' get file
       
       With sGet
           .Type = 1
           .Open()
           .Write(xmlhttp.responseBody) ' write file
           .SaveToFile "C:\" & Day(Date) & Month(Date) & Year(Date) & ".jpg"', 2 ' save file
           .Close
       End With
       
       wsh.regwrite "HKCU\Control Panel\Desktop\Wallpaper", "C:\" & Day(Date) & Month(Date) & Year(Date) & ".jpg" ' set desktop background
       wsh.regwrite "HKCU\Control Panel\Desktop\WallpaperStyle", "0"
       
       Set xmlhttp = Nothing
       Set sGet = Nothing
       url = Nothing



      In regards to closing resources, you may wish to look at these conversations we had some time ago:
      http://www.visualbasicscript.com/m_68817/mpage_1/key_Garbage/tm.htm#68819
      http://www.visualbasicscript.com/m_41162/mpage_1/key_/tm.htm#41163
      http://www.visualbasicscript.com/m_40532/mpage_1/tm.htm
      To iterate is human, to recurse divine. -- L. Peter Deutsch
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9