<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hello,<br>
<br>
Thank you very much for the help. I finally have it working
correctly.<br>
<br>
Thanks,<br>
Puzzledplane<br>
<br>
<div class="moz-cite-prefix">On 10/27/2014 10:05 PM, Matthias
Felleisen wrote:<br>
</div>
<blockquote
cite="mid:E750D2CA-BAB5-4B0C-82C2-1EC5ADB33DB7@ccs.neu.edu"
type="cite"><base href="x-msg://159/"><br>
<div>
<div>On Oct 27, 2014, at 7:46 PM, Derek C. wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite"><span class="Apple-style-span"
style="border-collapse: separate; font-family: 'Lucida
Grande'; font-style: normal; font-variant: normal;
font-weight: normal; letter-spacing: normal; line-height:
normal; orphans: 2; text-align: -webkit-auto; text-indent:
0px; text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width:
0px; font-size: medium; ">
<div dir="ltr">
<div data-externalstyle="false" dir="ltr"
style="font-family: Calibri, 'Segoe UI', Meiryo,
'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun
Gothic', sans-serif; font-size: 12pt; ">
<div>Hello,</div>
<div><br>
</div>
<div>Thank you for the reply. It was very helpful.</div>
<div><br>
</div>
<div dir="ltr" style="margin-right: 0px; ">The only
thing that I am confused in doing now is that I have
to store the value of the zip code in order to use it
within the API’s url. That is the first thing I was
trying to do because I need to take the zip code that
is entered and be able to add it within the url before
the .xml extension.</div>
<div dir="ltr" style="margin-right: 0px; "><br>
</div>
<div dir="ltr" style="margin-right: 0px; ">For Example:<span
class="Apple-converted-space"> </span><a
moz-do-not-send="true"
href="http://api.wunderground.com/api/*snip*/conditions/q/ZIPCODE.xml"
target="_parent"><u><font color="#0066cc">http://api.wunderground.com/api/*snip*/conditions/q/ZIPCODE.xml</font></u></a></div>
<div dir="ltr" style="margin-right: 0px; ">where ZIPCODE
is the zip code that was entered.</div>
</div>
</div>
</span></blockquote>
<div><br>
</div>
<div>See my sketch of the 'retrieve' function (not the fake one,
the real one). Change the format string to something so that </div>
<div><br>
</div>
<div> (format underground-format zip-code)</div>
<div><br>
</div>
<div>makes the correct string. See </div>
<div><br>
</div>
<div> (format "hello/there/~a" "02115")</div>
<div><br>
</div>
<br>
<blockquote type="cite"><span class="Apple-style-span"
style="font-family: Calibri, 'Segoe UI', Meiryo, 'Microsoft
YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic',
sans-serif; font-size: 16px; ">At first, I was attempting to
get this value from the zipcodelabel message% object, using
(define x (send zipcodelabel get-label)) but that would only
give me the initial value of the message% which is "No Zip
Code Entered".</span></blockquote>
<div><br>
</div>
<div><br>
</div>
<div>No it isn't. Add a '(displayln zip-code)' to the fake
retrieve function and you'll see that it retrieves the entered
code. </div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<br>
<blockquote type="cite"><span class="Apple-style-span"
style="border-collapse: separate; font-family: 'Lucida
Grande'; font-style: normal; font-variant: normal;
font-weight: normal; letter-spacing: normal; line-height:
normal; orphans: 2; text-align: -webkit-auto; text-indent:
0px; text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
-webkit-text-decorations-in-effect: none;
-webkit-text-size-adjust: auto; -webkit-text-stroke-width:
0px; font-size: medium; ">
<div dir="ltr">
<div data-externalstyle="false" dir="ltr"
style="font-family: Calibri, 'Segoe UI', Meiryo,
'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun
Gothic', sans-serif; font-size: 12pt; ">
<div dir="ltr" style="margin-right: 0px; "><br>
</div>
<div dir="ltr" style="margin-right: 0px; ">Thanks again,</div>
<div dir="ltr" style="margin-top: 0px; margin-right:
0px; margin-bottom: 0px; ">Puzzledplane<br>
</div>
<div data-signatureblock="true"><br>
</div>
<div style="padding-top: 5px; border-top-color: rgb(229,
229, 229); border-top-width: 1px; border-top-style:
solid; ">
<div><font style="line-height: 15pt; letter-spacing:
0.02em; font-family: Calibri, 'Segoe UI', Meiryo,
'Microsoft YaHei UI', 'Microsoft JhengHei UI',
'Malgun Gothic', sans-serif; font-size: 12pt; "
face=" 'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft
YaHei UI', 'Microsoft JhengHei UI', 'Malgun
Gothic', 'sans-serif'"><b>From:</b> <a
moz-do-not-send="true"
href="mailto:matthias@ccs.neu.edu"
target="_parent">Matthias Felleisen</a><br>
<b>Sent:</b> Monday, October 27, 2014
1:56 PM<br>
<b>To:</b> <a moz-do-not-send="true"
href="mailto:puzzledplane@yahoo.com"
target="_parent">Derek C.</a><br>
<b>Cc:</b> <a moz-do-not-send="true"
href="mailto:users@racket-lang.org"
target="_parent">users@racket-lang.org</a></font></div>
</div>
<div><br>
</div>
<div dir=""><br>
<div>
<div>On Oct 26, 2014, at 5:51 PM, Derek C. wrote:</div>
<br class="Apple-interchange-newline">
<blockquote style="margin-top: 0px; margin-bottom:
0px; "><span class="Apple-style-span"
style="text-transform: none; text-indent: 0px;
letter-spacing: normal; word-spacing: 0px;
white-space: normal; border-collapse: separate;
orphans: 2; widows: 2; "><span
class="Apple-style-span" style="font-family:
Calibri, 'Segoe UI', Meiryo, 'Microsoft YaHei
UI', 'Microsoft JhengHei UI', 'Malgun Gothic',
sans-serif; font-size: 16px; ">
<div data-signatureblock="true">I am trying to
get the value of a label after a button is
clicked. I know that I can use (send x
get-label) to get the value of the label,
but it only gets the initial value of the
label in my case "No Zip Code Entered".</div>
</span></span></blockquote>
<div><br>
</div>
<div>I don't know what you are asking. When I enter
a zip code and click Submit, the zip code shows up
in your text field. </div>
<div><br>
</div>
<br>
<blockquote style="margin-top: 0px; margin-bottom:
0px; "><span class="Apple-style-span"
style="text-transform: none; text-indent: 0px;
letter-spacing: normal; word-spacing: 0px;
white-space: normal; border-collapse: separate;
orphans: 2; widows: 2; "><span
class="Apple-style-span" style="font-family:
Calibri, 'Segoe UI', Meiryo, 'Microsoft YaHei
UI', 'Microsoft JhengHei UI', 'Malgun Gothic',
sans-serif; font-size: 16px; ">
<div>Also, after that button is pressed I
would like to run code that queries an API
and parses xml information using the zip
code from the label. Below is my code:</div>
</span></span></blockquote>
<br>
</div>
<div>See below. I have marked some small changes and
sketched a way to get this going. I also fixed some
basic style issues. </div>
<div><br>
</div>
<div>Note: if this is homework, please forward the
assignment so we can help more directly. If not, I
recommend developing with testing in mind (see
rackunit and submodules). </div>
<div><br>
</div>
<div>-- Matthias</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<br>
<div><br>
</div>
<div>
<div>#lang racket</div>
<div><br>
</div>
<div>(require racket/gui/base)</div>
<div><br>
</div>
<div>;; -> Void </div>
<div>(define (main) ;; don't run directly, wrap in
main function from the beginning; work with
(module+ main ...) if you want to always run </div>
<div> </div>
<div> ;; Creates a Frame called mainframe</div>
<div> (define mainframe </div>
<div> (new frame%</div>
<div> [label "Forecaster - Powered by
Wunderground API"]</div>
<div> [width 500]</div>
<div> [height 500]</div>
<div> [stretchable-width 500]</div>
<div> [stretchable-height 500]))</div>
<div> </div>
<div> ;; Creates a Current Conditions
group-box-panel</div>
<div> (define maingroup</div>
<div> (new group-box-panel%</div>
<div> [label "Current Conditions:"]</div>
<div> [parent mainframe]</div>
<div> [min-height 450]</div>
<div> [stretchable-height 450]))</div>
<div> </div>
<div> (define cclabel-text (new text%)) ; you want
a editor here, not a message </div>
<div> [send cclabel-text insert "Insert Conditions
Here from API"] ;; add your initial string, though
I am not sure what for </div>
<div> (define cclabel ;; now put the editor into a
canvas</div>
<div> (new editor-canvas%</div>
<div> [parent maingroup]</div>
<div> [label "current conditions"]</div>
<div> [editor cclabel-text]))</div>
<div> </div>
<div> ;; Creates a Zip Code group-box-panel</div>
<div> (define zipcodegroup </div>
<div> (new group-box-panel%</div>
<div> [label "Zip Code:"]</div>
<div> [parent mainframe]</div>
<div> [min-height 100]</div>
<div> [stretchable-height 100]))</div>
<div> </div>
<div> ;; Zip Code Message Label -- Defaults to No
Zip Code Entered</div>
<div> (define zipcodelabel</div>
<div> (new message%</div>
<div> [parent zipcodegroup]</div>
<div> [label "No Zip Code Entered"] ))</div>
<div> </div>
<div> ;; Zip Code Text-Field</div>
<div> (define zipInput </div>
<div> (new text-field% </div>
<div> [parent zipcodegroup]</div>
<div> [label ""]</div>
<div> [init-value ""]</div>
<div> [min-width 5]</div>
<div> [stretchable-width 5]</div>
<div> [callback</div>
<div> (lambda(f ev)</div>
<div> (define v (send f get-value))</div>
<div> (unless (string->number v)</div>
<div> (send f set-value
(regexp-replace* #rx"[^0-9]+" v ""))))]))</div>
<div> </div>
<div> ;; Submit Button</div>
<div> (define submit-button </div>
<div> (new button% </div>
<div> [parent zipcodegroup]</div>
<div> [label "Submit"]</div>
<div> [callback </div>
<div> (lambda (button event)</div>
<div> ;; use internal define over let
only because it's easier</div>
<div> (define zip-code (send zipInput
get-value))</div>
<div> (define weather (retrieve
zip-code))</div>
<div> (send zipcodelabel set-label
zip-code)</div>
<div> ;; now insert weather into the
editor, but clear it first </div>
<div> (send cclabel-text select-all)</div>
<div> (send cclabel-text clear)</div>
<div> (send cclabel-text insert
(prepare-as-text weather)))]))</div>
<div> ;; -- IN -- </div>
<div> (send mainframe show #t)) </div>
<div><br>
</div>
<div>;; helper but this may actually have to work on
the editor directly to make it look good </div>
<div>(define (prepare-as-text list-of-pairs)</div>
<div> (string-join </div>
<div> (map (lambda (x) (format "~a ~a" (first x)
(second x))) list-of-pairs)</div>
<div> "\n"))</div>
<div><br>
</div>
<div>;XML Parsing:</div>
<div>;</div>
<div>;#lang racket</div>
<div><br>
</div>
<div>;; this module should presumably provide a
retrieve function that does the hard work: </div>
<div>;; (provide </div>
<div>;; ; ZipCode -> [Listof [List Symbol
String]]</div>
<div>;; ; retrieve the information for the given
zip code and deliver the result as an association
list </div>
<div>;; ; -- examples here -- </div>
<div>;; retrieve)</div>
<div>(require net/url xml xml/path)</div>
<div><br>
</div>
<div>(define underground-url-format</div>
<div> "<a moz-do-not-send="true"
href="http://api.wunderground.com/api/%2asnip%2a/conditions/q/autoip.xml"
target="_parent">http://api.wunderground.com/api/*snip*/conditions/q/autoip.xml</a>")</div>
<div><br>
</div>
<div>;; I am taking a short-cut here: </div>
<div>(define (retrieve zip-code)</div>
<div> (list (list 'Location: "Boston, MA") (list
'Conditions: "typical fall day") </div>
<div> (list 'Temperature: "57o F") (list
'Feels-Like: "damp, humid, earthy")</div>
<div> (list 'Humidity: "67%") (list
'Wind: "5mph, south-by-south-west")))</div>
<div><br>
</div>
<div>(define (retrieve-to-be-done zip-code) </div>
<div> (define curent-cond-url (string->url
(format underground-url-format zip-code)))</div>
<div> (define current-cond-port (get-pure-port
curent-cond-url))</div>
<div> (define response (port->string
current-cond-port))</div>
<div> (close-input-port current-cond-port)</div>
<div> </div>
<div> (define data (xml->xexpr</div>
<div> ((eliminate-whitespace
'(response))</div>
<div> (read-xml/element
(open-input-string response)))))</div>
<div> </div>
<div> (define curr-location (se-path*/list
'(display_location full) data))</div>
<div> (define curr-weather (se-path*/list
'(current_observation weather) data))</div>
<div> (define curr-temp (se-path*/list
'(current_observation temp_f) data))</div>
<div> (define curr-humidity (se-path*/list
'(current_observation relative_humidity) data))</div>
<div> (define curr-wind (se-path*/list
'(current_observation wind_string) data))</div>
<div> (define curr-feels-like (se-path*/list
'(current_observation feelslike_f) data))</div>
<div> </div>
<div> (list (list 'Location: curr-location) (list
'Conditions: curr-weather) </div>
<div> (list 'Temperature: curr-temp) (list
'Feels-Like: curr-feels-like)</div>
<div> (list 'Humidity: curr-humidity) (list
'Wind: curr-wind)))</div>
</div>
</div>
</div>
</div>
</span></blockquote>
</div>
<br>
</blockquote>
<br>
</body>
</html>