none
Need help with the network object! RRS feed

  • Question

  • Hi, I have been working with small basic language for a while now, and awesome as it is, I cannot find any documentation for using the Network object, specifically GetWebPageContents. What I want to do is ask the user for a URL, then retrieve the web page and then display it in text-form. I would be extremely grateful for any help you could give me (or a link to somewhere else I could)!
    Monday, March 29, 2010 8:40 PM

Answers

  • Hi yeterbumi,

    nzsammy wrote a browser program over on this thread.  The import id is: GXJ463 

    You'll have to modify it slightly to display the contents as text in the text window, but that should be straightforward.

    I used GetWebPageContents (in my program below) to pull data out of my broadband router to track data usage and write it to a log file. It may serve as an example....

     

    ' Broadband Traffic Collator (BTC)
    ' Davey~Wavey ~ Nov'09
    
    ' pull current data from BT hub 
    page=Network.GetWebPageContents("http://localhost/xslt?PAGE=A04")
    page=Text.GetSubText(page, 8435, 50)
    page=Text.GetSubTextToEnd(page, Text.GetIndexOf(page, ">")+1 )
    page=Text.GetSubText(page, 1, Text.GetIndexOf(page, "<")-1 )
    
    ' now left with numerical Download bytes value (since last Hub reset)
    currentBytes = page
    
    ' build text line for logfile
    log = Clock.Date + "," + Clock.Time + "," + currentBytes + "," + Text.GetCharacter(12)
    
    ' centre text window
    TextWindow.Left = Desktop.Width/2-300
    TextWindow.Top  = Desktop.Height/2-200
    TextWindow.Title= "BROADBAND TRAFFIC COLLATOR"
    
    ' error check, in case the HTML page data is different and we're pulling in non-numeric data
    If Math.Floor(currentBytes) <> currentBytes Then
      TextWindow.WriteLine( log )
      TextWindow.WriteLine( "INVALID! (Data not yet written to logfile.)" )
      TextWindow.PauseWithoutMessage()
    EndIf
    
    ' write to the log file and terminate
    File.AppendContents( Clock.Year + "_" + Clock.Month + "_Log.csv", log )
    
    TextWindow.Clear()
    TextWindow.CursorLeft = 32
    TextWindow.CursorTop  = 12
    TextWindow.Write ( "BTC COMPLETED" )
    Program.Delay    (1000)
    
    Program.End()
    
    

    Monday, March 29, 2010 9:04 PM

All replies

  • Hi yeterbumi,

    nzsammy wrote a browser program over on this thread.  The import id is: GXJ463 

    You'll have to modify it slightly to display the contents as text in the text window, but that should be straightforward.

    I used GetWebPageContents (in my program below) to pull data out of my broadband router to track data usage and write it to a log file. It may serve as an example....

     

    ' Broadband Traffic Collator (BTC)
    ' Davey~Wavey ~ Nov'09
    
    ' pull current data from BT hub 
    page=Network.GetWebPageContents("http://localhost/xslt?PAGE=A04")
    page=Text.GetSubText(page, 8435, 50)
    page=Text.GetSubTextToEnd(page, Text.GetIndexOf(page, ">")+1 )
    page=Text.GetSubText(page, 1, Text.GetIndexOf(page, "<")-1 )
    
    ' now left with numerical Download bytes value (since last Hub reset)
    currentBytes = page
    
    ' build text line for logfile
    log = Clock.Date + "," + Clock.Time + "," + currentBytes + "," + Text.GetCharacter(12)
    
    ' centre text window
    TextWindow.Left = Desktop.Width/2-300
    TextWindow.Top  = Desktop.Height/2-200
    TextWindow.Title= "BROADBAND TRAFFIC COLLATOR"
    
    ' error check, in case the HTML page data is different and we're pulling in non-numeric data
    If Math.Floor(currentBytes) <> currentBytes Then
      TextWindow.WriteLine( log )
      TextWindow.WriteLine( "INVALID! (Data not yet written to logfile.)" )
      TextWindow.PauseWithoutMessage()
    EndIf
    
    ' write to the log file and terminate
    File.AppendContents( Clock.Year + "_" + Clock.Month + "_Log.csv", log )
    
    TextWindow.Clear()
    TextWindow.CursorLeft = 32
    TextWindow.CursorTop  = 12
    TextWindow.Write ( "BTC COMPLETED" )
    Program.Delay    (1000)
    
    Program.End()
    
    

    Monday, March 29, 2010 9:04 PM
  • Just saw DW's replay as I was writing this - much the same but here it is anyway.

    The documentation for SmallBasic is in its infancy - this forum is probably the best resource.

    You may want to try Fremy's extensions to display a web page (included in first link below, with an example of its use in the second link).

    Note that the Network command in the basic version (without Fremy extension) just returns the contents of the web page as text.

    Some links form this website

    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/30a05809-960f-47ac-adf1-1154e735dfa2

    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/6e1c0476-2175-410f-af6d-a9a297094054/

    Import RZV694 for nzsammy's code formatted for SmallBasic + Fremy extension to load a browser into SmallBasic.

    Try the following to get an idea of the Network command:

    SB = Network.DownloadFile("http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads/")
    TextWindow.WriteLine(SB)

    Program.Delay(1000)

    SBtext = File.ReadContents(SB)
    TextWindow.WriteLine(SBtext)

    Program.Delay(1000)

    SBtext = Network.GetWebPageContents("http://social.msdn.microsoft.com/Forums/en-US/smallbasic/threads/")
    TextWindow.WriteLine(SBtext)

    Monday, March 29, 2010 9:07 PM
    Moderator
  • When I try to run the code a dialog box pops up saying tmp7138.tmp.exe has stopped working. And with the previous code sample (GXJ463) it says that the variable "t" was used but not assigned a value. Can you provide some help with either of these problems?
    Monday, March 29, 2010 10:09 PM
  • Don't know what the first error is about, sorry. Which bit of code were you trying to run?

    The second error, from GXJ463... oops, yeah, I forgot that there was a bug in that file.  Either, just put the following anywhere near the top of the program and it will work....

    t=""

     

    OR, use the alternative import code that litdev gave: RZV694


    Tuesday, March 30, 2010 12:28 AM
  • Thanks for the help! I didn't think of just declaring T and leaving it blank *smacks forehead*.

    Turns out the first problem wasn't just an issue with the code; I think I might have accidentally deleted a file when switching to v0.8.

    • Proposed as answer by yuvjeeth Saturday, April 23, 2011 8:33 AM
    Thursday, April 1, 2010 1:41 AM