The Interstate Commerce Clause of the U.S. Constitution basically says that any commerce occurring between states falls under the umbrella of the federal government. This is an important point for a nation which takes states' rights so seriously. Keep in mind, too, the time period in which the Constitution was drafted and the level of interstate commerce at that point.
What can the feds do with the ICC?
Fast forward to the present day. The ICC is how the federal government can prohibit guns within so many feet of a school. Why? Because no gun is made entirely within one state and sold entirely within one state. Hence, the feds can control legislation relating to guns. The ICC is also how many cases are removed from state court to federal court when it is more favorable to the defendant who was sued in state court. What company uses paper made entirely in one state and sold entirely in the same state? Or software? Or office equipment? You get the picture.
The age of the Internet.
I'm a stay-at-home mom to 2 small kids. I can't afford to pay for daycare on top of tuition. So I can only pursue my techie dreams if I can take classes online. Wake Tech is ultra cheap, CodeAcademy introduced me to HTML/CSS/JS and MOOC gave me Python. The point is that we have access to more knowledge (and I don't mean the kind Perez Hilton brings us) than ever before. Access to knowledge = power. Constricting access = power for someone else.
Replace "We the People" with "Comcast/Time Warner Cable"...
...if these giant corporations can control internet speed based on who pays the ransom, then we are not a democracy. And I hope you don't think for one second their lobbyists aren't well paid to attempt to take control of Congress. So if the corporations tell us what we can read and what we can watch and what we can listen to because they have the money to bend Congress' ear...then "adijo" democracy.
It looks like we've won part of the battle, but they'll be back for more.
Keep the faith, Republic Wireless.
So when a company like RW starts to make a dent in a market and make technology affordable for everyone, it's a big deal. Everyone says the desktop is dying. (Personally, I need a bigger screen for regular reading.) If that's true, outrageous phone bills for smart phones means a lot of people are priced out of accessing information.
This is not a thorough legal analysis, but it is something I believe in strongly. I'm all for making a profit and people who work hard and do a good job should be aptly rewarded. But individuals should not be controlled by corporations. They don't own the internet. They don't own information.
How we practice democracy will change with technology. Companies like RW can push us in that direction while simultaneously pushing back against the corporate giants that want to diminish democracy.
Sharing my journey as I go from knowing almost nothing to, hopefully, a whole lot more.
Thursday, July 31, 2014
Wednesday, July 23, 2014
Making columns in a listbox in C#
Amended: There is a MultiColumn property I forgot to mention. It didn't work for me with the particular problem I had. Maybe that was my lack of skill. Maybe it was the problem. In any case, try MultiColumn and try my workaround. One of them should do the trick.
This post probably has a very limited audience made up of other students who, like me, are being forced to use Windows Forms and have not yet used WPF. Having not used WPF yet, I don't know if this helpful hint will help outside Windows Forms.
Here was my problem: I had a lab assignment in which I was required to make a GUI in Windows Forms. Random integers were to be created with a button click and the values displayed in a listbox with two columns. I suddenly realized I didn't know how to make columns in a listbox. Very old versions of Visual Studio had a columns property but since I was using VS 2013, that didn't help. I also read somewhere that listview could be used but it was described as "quirky." I didn't have time for quirky.
So here's how to do it:
Step 1: listBox1.Items.Add("Index Values");
Step 2: Make a for loop
Step 3: Inside the for loop, add the output underneath the column headings
from Step 1.
listBox1.Items.Add(string.Format("{0} {1}", i, intArray[i]));
That's it. Pretend you're in a Console app but use listbox instead and you've got columns.
This post probably has a very limited audience made up of other students who, like me, are being forced to use Windows Forms and have not yet used WPF. Having not used WPF yet, I don't know if this helpful hint will help outside Windows Forms.
Here was my problem: I had a lab assignment in which I was required to make a GUI in Windows Forms. Random integers were to be created with a button click and the values displayed in a listbox with two columns. I suddenly realized I didn't know how to make columns in a listbox. Very old versions of Visual Studio had a columns property but since I was using VS 2013, that didn't help. I also read somewhere that listview could be used but it was described as "quirky." I didn't have time for quirky.
So here's how to do it:
Step 1: listBox1.Items.Add("Index Values");
Step 2: Make a for loop
Step 3: Inside the for loop, add the output underneath the column headings
from Step 1.
listBox1.Items.Add(string.Format("{0} {1}", i, intArray[i]));
That's it. Pretend you're in a Console app but use listbox instead and you've got columns.
Monday, July 14, 2014
Convert string to a char array in C#
It's not complicated. You just have to know how to do it.
public class ArrayChange
{
static char[] charArray;//declare before Main method
public static void Main(string[] args)
{
Console.WriteLine("Enter your name: ");
string input = Console.ReadLine();
charArray = input.ToCharArray();
}//end Main method
}//end class
This first line, of course, prompts the user to enter a string. The second line stores that input in a string variable called "input". The third line converts input to a char array and stores it in the array called "charArray".
If you try to store the user input directly into a char array, you'll get a red squiggly line telling you that you cannot implicitly convert a string, which is the user input, into a char array. In other words, you can't just say that apples = oranges.
So your next thought is probably to do this:
Convert.ToCharArray(Console.ReadLine());
Good idea. Makes sense to me, but Convert class does not contain a ToCharArray method, just ToChar. So when you want apples = oranges, you need a middleman. In our case, that middleman is string input, which stores the user input as a string. Since strings are made of characters, we can just dump those characters into a char array as we did in the third line.
public class ArrayChange
{
static char[] charArray;//declare before Main method
public static void Main(string[] args)
{
Console.WriteLine("Enter your name: ");
string input = Console.ReadLine();
charArray = input.ToCharArray();
}//end Main method
}//end class
This first line, of course, prompts the user to enter a string. The second line stores that input in a string variable called "input". The third line converts input to a char array and stores it in the array called "charArray".
If you try to store the user input directly into a char array, you'll get a red squiggly line telling you that you cannot implicitly convert a string, which is the user input, into a char array. In other words, you can't just say that apples = oranges.
So your next thought is probably to do this:
Convert.ToCharArray(Console.ReadLine());
Good idea. Makes sense to me, but Convert class does not contain a ToCharArray method, just ToChar. So when you want apples = oranges, you need a middleman. In our case, that middleman is string input, which stores the user input as a string. Since strings are made of characters, we can just dump those characters into a char array as we did in the third line.
Saturday, June 28, 2014
Structs vs. Classes in C#
This MVA video does an excellent job of explaining the difference. This post is a short summary of the video.
The most important thing to understand is passing by reference versus passing by value. The example I use for explaining the difference between pass by reference and pass by value is this: You go to an art gallery and buy an original work of art. When you take it home, your 2-year-old scribbles all over it with crayon. The original work of art is forever changed. That's passing by reference. But if you were to buy a print of the original work of art which your 2-year-old then scribbles on, the original work of art is not affected. Although it may suck for you that you paid good money for a print which is now messed up, the original work of art remains intact and more prints can be made from it. That's passing by value.
If you've looked at structs before, you know that a struct looks and acts a lot like a class. But as is pointed out in the video, there are some major differences. So here is the promised summary of the video.
1. Structs are values types and classes are reference types. Thinking of my example above, this means that when changes are made, only a copy is changed and not the original values in a struct. But with a class, whatever values you change are changed within the class itself. The MVA video does a great job of demonstrating this by code. I copied the code and put it on GitHub so I could see the whole thing at once. I just got tired of rewinding and fastforwarding when I wanted to see something. Just remember, this is not my code but the code from the MVA video.
2. Structs are passed on the stack and classes are passed on the heap. When a copy of a struct is passed onto the stack, the whole data structure is passed. (This is also means structs should be smaller data structures than classes.) When a class is passed on the heap, a copy of the memory address is passed. While this makes the process more efficient than passing the entire data structure, it also means that the method receives a copy of the instance of the class and, thus, has access to change the class itself.
3. What is the stack and what is the heap? Here is a great article. I won't try to reinvent the wheel. Just read this.
4. What is with the hashtags? It just means you can specify a block of code, a region, like the struct, that can be collapsed while you look at other code. I added in the regions to the code on GitHub, so you can try it out there.
The most important thing to understand is passing by reference versus passing by value. The example I use for explaining the difference between pass by reference and pass by value is this: You go to an art gallery and buy an original work of art. When you take it home, your 2-year-old scribbles all over it with crayon. The original work of art is forever changed. That's passing by reference. But if you were to buy a print of the original work of art which your 2-year-old then scribbles on, the original work of art is not affected. Although it may suck for you that you paid good money for a print which is now messed up, the original work of art remains intact and more prints can be made from it. That's passing by value.
If you've looked at structs before, you know that a struct looks and acts a lot like a class. But as is pointed out in the video, there are some major differences. So here is the promised summary of the video.
1. Structs are values types and classes are reference types. Thinking of my example above, this means that when changes are made, only a copy is changed and not the original values in a struct. But with a class, whatever values you change are changed within the class itself. The MVA video does a great job of demonstrating this by code. I copied the code and put it on GitHub so I could see the whole thing at once. I just got tired of rewinding and fastforwarding when I wanted to see something. Just remember, this is not my code but the code from the MVA video.
2. Structs are passed on the stack and classes are passed on the heap. When a copy of a struct is passed onto the stack, the whole data structure is passed. (This is also means structs should be smaller data structures than classes.) When a class is passed on the heap, a copy of the memory address is passed. While this makes the process more efficient than passing the entire data structure, it also means that the method receives a copy of the instance of the class and, thus, has access to change the class itself.
3. What is the stack and what is the heap? Here is a great article. I won't try to reinvent the wheel. Just read this.
4. What is with the hashtags? It just means you can specify a block of code, a region, like the struct, that can be collapsed while you look at other code. I added in the regions to the code on GitHub, so you can try it out there.
Monday, June 23, 2014
StringBuilder in C# - Tricky truncating with Length and Append
StringBuilder, unlike String, is a class that allows you to change the length of a string. If the length property is already set and a new string is created that is longer than the length, the length increases. If the new string is shorter than the property value already set, it decreases. The MSDN source code provides a more technical way of putting it. (See lines 464-467.)
Here's a simple example to demonstrate:
StringBuilder example = new StringBuilder("Hello");
//length changes from default value of 0 to 5 on creation of the object
Console.WriteLine(example.Length);
//output is 5
Using the append method, I add the string "Hello" onto an empty string.
StringBuilder example = new StringBuilder("");
//this is an empty string; length is still 0
example.Append("Hello");
Console.WriteLine(example.Length);
//output is still 5
Using the append method, I add the string "Hello" onto a string containing only a space character.
StringBuilder example = new StringBuilder(" ");
//this is NOT an empty string
//there is a space character in this string; current length is now 1
Console.WriteLine(example.Length);
//output is 1
example.Append("Hello");
Console.WriteLine(example.Length);
//output is now 6, because there is a space character at the beginning of the string
Console.WriteLine(example);//output is " Hello" - there will be a space before "H"
Just remember that an empty string ("") is not the same as (" "). The latter contains a space character. This makes a big difference if you're appending your string and then getting the length. Not that I expect this is done on a regular basis, but the moral of the story is to make sure you know what prior strings contained before appending or you might get a surprise. (Not that this ever happened to me.)
So what if I wanted to get rid of the space character? Truncate.
StringBuilder x = new StringBuilder(" ");
Console.WriteLine(x.Length);//output is 1 because of the space character
x.Length = 0;
x.Append("Hello");
Console.WriteLine(x);//output is "Hello"; notice there is no space before "Hello" now
Console.WriteLine(x.Length);//output is 5;
Here is a screenshot to show the code and output.
Monday, June 9, 2014
C# DateTimePicker and Current Time a.k.a Learning to Load
This is a "helpful hint" post. I was working on a Windows Form and needed the form to update to the current time each time the app was run. I started with the TimeDatePicker in the form, choosing Time for the property Format because I only wanted to display the time, not the date. I didn't have to set Value because that property was automatically set to the current date and time. The code I used was:
The first lesson here is to not assume that Click is an event for every controller. It's not an event for DateTimePicker. It seemed logical to me, though, so I used that in my code without checking to see if it was an actual event. You click to change the date and/or time, right? Yes, you do. But that was the wrong logic.
The correct logic is to ask: A) What should the controller do? The controller should show the current time. B) When should the controller perform this task? The controller should perform this task when the form loads, which means the data needs to be picked up before the form displays.
Here is one way to write the code correctly:
Since my textbook didn't go into a lot (i.e., any) detail about loading, I had to do a little research. Although I ran across references to Load when I was searching high and low for a way to make the time update, I couldn't find it as an event for DateTimePicker. That's because Load is an event of class Form, which is a class in the Forms namespace. (When you create a form, you will see that the class automatically generated for you is a derived class of class Form.) In the order of events, Load occurs before the form is displayed, which is logical.
The moral of the story is that if you want the current date, i.e. data that must be captured anew each time the app is run, you need the Load event. Just remember that Load is an event of class Form, not the controller DateTimePicker,
I strongly recommend reading these two posts by DotNetPerls: One on Load and one on DateTimePicker to help you understand this better.
private void DateTimePicker_Click(object send, EventArgs e)
{ DateTime.dateTimePicker1 = DateTime.Now;}Unfortunately, this combo did not work. Each time I ran the app, it showed the time the app was created and not the current time.
The first lesson here is to not assume that Click is an event for every controller. It's not an event for DateTimePicker. It seemed logical to me, though, so I used that in my code without checking to see if it was an actual event. You click to change the date and/or time, right? Yes, you do. But that was the wrong logic.
The correct logic is to ask: A) What should the controller do? The controller should show the current time. B) When should the controller perform this task? The controller should perform this task when the form loads, which means the data needs to be picked up before the form displays.
Here is one way to write the code correctly:
private void Form1_Load(object sender, EventArgs e){ //Form1 is the name of the class used to create this formdateTimePicker1.Value = DateTime.Now;}//also see DotNetPerls for another snippet
Since my textbook didn't go into a lot (i.e., any) detail about loading, I had to do a little research. Although I ran across references to Load when I was searching high and low for a way to make the time update, I couldn't find it as an event for DateTimePicker. That's because Load is an event of class Form, which is a class in the Forms namespace. (When you create a form, you will see that the class automatically generated for you is a derived class of class Form.) In the order of events, Load occurs before the form is displayed, which is logical.
The moral of the story is that if you want the current date, i.e. data that must be captured anew each time the app is run, you need the Load event. Just remember that Load is an event of class Form, not the controller DateTimePicker,
I strongly recommend reading these two posts by DotNetPerls: One on Load and one on DateTimePicker to help you understand this better.
Tuesday, June 3, 2014
Getting dates and calculating a time interval in C# - Part II
TimeSpan
You can get the source code on GitHub. (I've updated the code a bit.)
TimeSpan is struct with a method subtract that will calculate the number of days between two dates. This means, though, that we are now dealing with a different type from DateTime. DateTime just gives you dates and, as you know from the previous post, I needed to calculate an interval between dates. So how could I use the TimeSpan type with the DateTime objects I had created?
My first thought was to convert my TimeSpan object to a DateTime object because I knew how to format DateTime to display only the date. But as someone pointed out on Stack Overflow, it doesn't make sense to do it that way. TimeSpan represents, guess what, a span of time. DateTime represents, yes, you guessed it, a date and a time. The date July 12, 2013 is different from the time span 2 days, 12 hours, 30 minutes and 40 seconds.
So here's how it's done:
Now, just display the result:
It took some work for me to figure this out on my own, putting all the pieces of the puzzle together, and it was a lot of fun. I hope you find it helpful.
You can get the source code on GitHub. (I've updated the code a bit.)
TimeSpan is struct with a method subtract that will calculate the number of days between two dates. This means, though, that we are now dealing with a different type from DateTime. DateTime just gives you dates and, as you know from the previous post, I needed to calculate an interval between dates. So how could I use the TimeSpan type with the DateTime objects I had created?
My first thought was to convert my TimeSpan object to a DateTime object because I knew how to format DateTime to display only the date. But as someone pointed out on Stack Overflow, it doesn't make sense to do it that way. TimeSpan represents, guess what, a span of time. DateTime represents, yes, you guessed it, a date and a time. The date July 12, 2013 is different from the time span 2 days, 12 hours, 30 minutes and 40 seconds.
So here's how it's done:
TimeSpan daysGoneBy = todayDateOnly.Subtract(boughtDateOnly);Start with a TimeSpan variable, daysGoneBy. On the other side of the equation is largerDate.methodSubtract(argumentIsSmallerDate).
Now, just display the result:
string output;As you may recall, "d" is a format specifier. Here, "%d" means only the whole number of days will be displayed. (Remember that % is the symbol for modulo.)
output = "The number of days elapsed since the vehicle was bought: " + daysGoneBy.ToString("%d");
It took some work for me to figure this out on my own, putting all the pieces of the puzzle together, and it was a lot of fun. I hope you find it helpful.
Subscribe to:
Posts (Atom)