View Full Version : Calling all programmers!
SMASH
February 19th, 2010, 03:50 PM
So I was just thinking that it would be cool to wake up to a voice on my computer that read me the time and the weather... well the time is easy, I can code that in C++, VB, or C# but of those 3 languages which one would be easiest for retrieving weather information off of say MSN weather and how would you go about it?
jcap
February 19th, 2010, 04:06 PM
The Weather Channel has RSS feeds for weather you can read.
SMASH
February 19th, 2010, 04:13 PM
Do you know of any tutorials on how to read RSS with one of those languages I listed? C++ is the one I'm most prolific at, but C# is a close second.
I found this site and I'm going to experiment with it more but idk if there's an easier way: http://www.example-code.com/vcpp/rss_read_feed.asp
Limited
February 19th, 2010, 06:49 PM
Depends if you like coding from scratch, C++ would do it but you'd have to do most of the head work. C# would be easier, especially with the text-to-speech API incorporation.
SMASH
February 19th, 2010, 06:54 PM
Yessir. That's why I chose to go with C#, and even then it got a little confusing... BUT... here's my code... it works betches:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace RSS_Reader_C_Sharp
{
class Program
{
static void Main(string[] args)
{
XmlTextReader reader = new XmlTextReader ("http://weather.yahooapis.com/forecastrss?p=USIL0004&u=f");
while (reader.Read())
{
if (reader.LocalName == "condition")
Console.WriteLine("The current temperature is: " + reader.GetAttribute(2) + " degrees F");
}
Console.ReadLine();
}
}
}
Note: This is just a command line program used to test the rss feature. I'm going to work on learning windows form programming now for the rest of the alarm
Kornman00
February 19th, 2010, 06:59 PM
This kind of appliction is perfectly suited for a .NET implementation
I don't see any benefits in trying to do this in a natively compiled language like C++
SMASH
February 19th, 2010, 07:05 PM
Yeaaaaa. Kornman, I've taken 2 C++ classes in college, 1 was into, and the other was object oriented, and I'm teaching myself C#. Honestly, the whole .NET thing is completely new to me and I have no idea what it is or how to use it.
Kornman00
February 19th, 2010, 09:58 PM
Well, the thing about .NET is that it really is an object-oriented framework, where as C++ is just C with struct/class methods (oh and then there is that whole template part of the language, let's just ignore that for OO's sake). Everything derives from System.Object (reference object) and if you're using a struct\enum; they derive from System.ValueType (value object).
If the class actually taught OO theory in that class then .NET shouldn't be that hard to pick up on. With experience in C++, the syntax of C# isn't too difficult to pick up either. The .NET framework provides alot of implemented functionality and interfaces for you to, well implement, in your own code to talk to those same systems and others who support that system. You've already messed with the System.Xml namespace. For this program you're wanting, the System.Web namespace is probably another vector which you'll want to lock in. I know that microsoft has a Speech SDK, but I'm not sure as to what lengths they went for making a .NET wrapper.
So what you'd just want is something to easily signal speech events. Then you can just have a layer which monitors for conditions for those signals to be fire. Eg, you have something monitor until the time is AlarmTime everyday. When it hits that condition, it fires off a GoodMorningUsa event which then calls on some worker code which gathers web-based data. Then from there, GoodMorningUsa could tell the speech SDK that it wants it to read X (ie, the date and time), Y (local weather), and Z (the gps coordinates of your car ;p).
That's just a quick 5 minute design idea. Obviously if you're that serious about it you'd want to refine some of the interface ideas then really narrow it all down into objects. But if you're wanting something quick and dirty, a quick hack up of some code can easily do the job too.
CrAsHOvErRide
February 20th, 2010, 04:47 AM
Korn said it all. There is also no real advantage of using C++ since C# can incorporate it better and might even run faster in the end.
Also, not to be a bitch but CamelCase (http://en.wikipedia.org/wiki/CamelCase) and keep Constants (e.g. the URL) at another level.
Kornman00
February 20th, 2010, 05:43 AM
Yes, CamelCasing. At least for all publicly visable constructs. lowerCamelCase on publics makes me want to hurt people
I KILL YOU <:mad:>
SMASH
February 20th, 2010, 01:15 PM
Well, the thing about .NET is that it really is an object-oriented framework, where as C++ is just C with struct/class methods (oh and then there is that whole template part of the language, let's just ignore that for OO's sake). Everything derives from System.Object (reference object) and if you're using a struct\enum; they derive from System.ValueType (value object).
If the class actually taught OO theory in that class then .NET shouldn't be that hard to pick up on. With experience in C++, the syntax of C# isn't too difficult to pick up either. The .NET framework provides alot of implemented functionality and interfaces for you to, well implement, in your own code to talk to those same systems and others who support that system. You've already messed with the System.Xml namespace. For this program you're wanting, the System.Web namespace is probably another vector which you'll want to lock in. I know that microsoft has a Speech SDK, but I'm not sure as to what lengths they went for making a .NET wrapper.
So what you'd just want is something to easily signal speech events. Then you can just have a layer which monitors for conditions for those signals to be fire. Eg, you have something monitor until the time is AlarmTime everyday. When it hits that condition, it fires off a GoodMorningUsa event which then calls on some worker code which gathers web-based data. Then from there, GoodMorningUsa could tell the speech SDK that it wants it to read X (ie, the date and time), Y (local weather), and Z (the gps coordinates of your car ;p).
That's just a quick 5 minute design idea. Obviously if you're that serious about it you'd want to refine some of the interface ideas then really narrow it all down into objects. But if you're wanting something quick and dirty, a quick hack up of some code can easily do the job too.
Wow, I really appreciate your response man. I really like this idea. I'm confused though, isn't C# and .NET basically one and the same? And I was figuring I'd do my own recording of everything like each number and have a function that will splice the sections that it needs to make that number/saying, like passing "42" to it will find the forty sound bite and the two sound bite and say it.
CrAsHOvErRide
February 20th, 2010, 01:23 PM
.NET is a Framework. Basically if you code in native C++ the executable files run directly in Windows. If you code a executable file in the .NET Framework environment with the .NET languages like C# or C++, they will run on the .NET Framework which runs on top Windows. That of course has some advantages which I don't want to go into detail now :P
This was a VERY SIMPLE explanation and not entirely accurate.
SMASH
February 20th, 2010, 01:30 PM
Ah, I that clears it up a bit. To get through to me you really have to dumb it down, I can't even call myself a legit programmer yet. I'm going for DeVry's Game and Simulation programming and so far it's just been really simple stuff.
And I'm only going to DeVry cause my mom works there so up to now it's been free but now I gotta pay 10%, still not too bad.
SMASH
February 20th, 2010, 02:18 PM
Sorry for the double post but since all my education has been in the console, I royally suck at working on GUIs. Are there any good tutorials that go over the overview of windows forms programming? My main problem is I'm trying to code the time to keep updating itself but there's only a Form1_initialize, and that only runs once so it only get's the time once and won't update. I'd write a completely different class for it but I also can't figure out how to update a label on Form1 from anywhere that's not in the form1 initialize section.
Edit: I tried a Form1.lblName, but the option didn't pop up... any ideas?
CrAsHOvErRide
February 20th, 2010, 02:28 PM
What do you mean by update? If you want to write something to a label just do
lblName.Name = "Something".
If you are coding in another class and want to modify the label you have to pass on the parent class (in this case the Form1 class) as a parameter through the constructor of the child class.
Best thing would be, if you post your code & concept (class layout).
SMASH
February 20th, 2010, 02:43 PM
Honestly man I think I have no idea what the hell I'm doing... here's some code though... all I'm trying to do is get a current time to update on Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Alarm_Clock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//call this method every second
Time.setLbl();
}
}
}
Time Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Alarm_Clock
{
class Time : Form1
{
static Time()
{
System.DateTime dt = System.DateTime.Now;
Year = dt.Year;
Month = dt.Month;
Date = dt.Day;
Hour = dt.Hour;
Minute = dt.Minute;
Second = dt.Second;
}
static public void setLbl()
{
//update labels here once I can get access
}
public static int Year;
public static int Month;
public static int Date;
public static int Hour;
public static int Minute;
public static int Second;
}
}
CrAsHOvErRide
February 20th, 2010, 03:08 PM
A few things that need a change:
private void Form1_Load(object sender, EventArgs e)
That's a method that gets called from an event handler. It is possible to manually call it but you shouldn't. This even is called once when the Form1 loads and you should not change that fact.
class Time : Form1
If you tried to do what I said, that's not what I meant. Right now the Time class is inheriting Form1.
I would recommend that you try en easier project...just to get the Object-Oriented-Programming principles.
SMASH
February 21st, 2010, 09:01 AM
I understand most simple object oriented programming, its just I've never worked with windows forms before. Are there any tutorials that you might know of that might be able to put me on the right track?
CrAsHOvErRide
February 21st, 2010, 09:31 AM
Duno, there is not much to it:
I made a GUI with 2 buttons and 1 label. The label displays the Dog's age and the buttons create the dog and increase the age.
public partial class Main : Form
{
private Dog favoriteDog;
public Main()
{
InitializeComponent();
}
private void btnCreateDog_Click(object sender, EventArgs e) //Button
{
this.createDog();
}
private void btnIncDogAge_Click(object sender, EventArgs e) //Button
{
this.increaseAge();
}
private void createDog()
{
favoriteDog = new Dog(1); //Create a new class "Dog" with the age of 1
lblDogAge.Text = "Dog Age: " + favoriteDog.getAge().ToString(); //Get the age from the class and write it to a label
}
private void increaseAge()
{
favoriteDog.increaseAge(); //Call the increaseAge() method inside the favoriteDog class
lblDogAge.Text = "Dog Age: " + favoriteDog.getAge().ToString(); //Get the age from the class and write it to a label
}
}
and the Dog class:
class Dog
{
private byte dogAge;
public Dog(byte pAge) //Constuctor
{
dogAge = pAge;
}
public void increaseAge()
{ dogAge++; }
public byte getAge()
{ return dogAge; }
}
CamelCasing is wrong and also get/set methods can be written differently now in C# but that's the basic idea behind every class. You create a class, pass arguments through constructor and retrieve/set values.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.