lewashby 56 Junior Poster
from Tkinter import *
import tkMessageBox
import pygame.mixer

# create GUI window
app = Tk()
app.title("Head Frist Mix")

sound_file = "50459_M_RED_Nephlimizer.wav"

# start the sounds system
mixer = pygame.mixer
mixer.init()

# create function
def track_toggle():
    if track_playing.get() ==  1:
        track.play(loops = -1)
    else:
        track.stop()

# create function volume
def change_volume(v):
    track.set_volume(volume.get())

track = mixer.Sound(sound_file)

track_playing = IntVar()

# create check button
track_button = Checkbutton(app, variable = track_playing,
                           command = track_toggle,
                           text = sound_file)
track_button.pack(side = LEFT)

# create scale button
volume = DoubleVar()
volume.set(track.get_volume())
volume_scale = Scale(variable = volume,
                     from_ = 0.0,
                     to = 1.0,
                     resolution = 0.1,
                     command = change_volume,
                     label = "Volume",
                     orient = HORIZONTAL)
volume_scale.pack(side = RIGHT)

def shutdown():
    track.stop()
    app.destroy()

app.protocol("WM_DELETE_WINDOW", shutdown)

# GUI loop
app.mainloop()

I the above code I have two questions. At the very top I've imported "from Tkinter import * & import tkMessageBox". Why would I need to import tkMessageBox if I've already imported everything in Tkinter via "from Tkinter import *"?

Secondly, of all GUI controls I've ever added the first parameter was always the name of my Tk object, in this case (app). So why doesn't the Scale control also need "app" as it's fist parameter? Thanks.

lewashby 56 Junior Poster
# create options menu
options = read_depots("depots.txt")
OptionMenu(app, depot, *options).pack()

In the above code I'M getting the error that __inti__ takes 4 arguments and that it's only given 3. I'M writing the code just how the book gives it to me.

lewashby 56 Junior Poster

When you say "It goes to objects creation method __init__", do you mean object of Label or object app of Tk()? I'M still finding this confusing.

lewashby 56 Junior Poster
# create GUI
app = Tk()
app.title("Head-Ex Deliveries")

# create a label
Label(app, text = "Depot:").pack() # add to Tk app window

# create a text entry
depot = Entry(app)
depot.pack()

I understand and have been told that placing the instance name(app) as a parameter of Tk methods and other Tkinter methods results in attaching those objects to the "app" Window. But what I want to know is why and how this works, this has never been explained to me.
For instance, Label as seen above, is a class, and as I've been told placing a class name within the parameter of another class makes it an inherited class. But I don't recall ever being told what happens when you place an instance of one class as the parameter of another. So I'M stuck trying to figure out why and how this works. Thanks.

lewashby 56 Junior Poster

I'M getting error below when I run the following program code. It's with the following function. fileD.write("%\n" % depot.get())

Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "/home/developer/Projects/Head First/Chapter 7/Head-Ex.py", line 7, in save_data
fileD.write("%\n" % depot.get())
ValueError: unsupported format character '
' (0xa) at index 1

from Tkinter import *

# function for save_data button
def save_data():
    fileD = open("deliveries.txt", "a")
    fileD.write("Depot:\n")
    fileD.write("%\n" % depot.get())
    fileD.write("Description:\n")
    fileD.write("%\n" % description.get())
    fileD.write("Address:\n")
    fileD.write("%\n" % address.get("1.0", END))
    depot.delete(0, END)
    description.delete(0, END)
    address.delete("1.0", END)

# create GUI
app = Tk()
app.title("Head-Ex Deliveries")

# create a label
Label(app, text = "Depot:").pack() # add to Tk app window

# create a text entry
depot = Entry(app)
depot.pack()

# create another label
Label(app, text = "Description:").pack()

# create another text entry
description = Entry(app)
description.pack()

# create final label
Label(app, text = "Address:").pack()

# create a text field
address = Text(app)
address.pack()

# create button
Button(app, text = "Save", command = save_data).pack()

# gui loop
app.mainloop()
lewashby 56 Junior Poster

I have a computer split between Windows Vista and Ubuntu 9.10. A friend of mine who has the same configuration update his Ubuntu several months back and found that his Windows partition was unable to boot up. In order to restore his sytem he had to run Windows recover through his Windows CD. After doing some research I found that a lot of people were having this problem and apparently it had something to do with "Karmic to Lucid" update.

I have not update my Ubuntu in months because of this very problem. What I want to know is, has his problem been fixed? Is it save for me to finally update?

lewashby 56 Junior Poster
app = Tk() # creat a tkinter application window called "app"

app.title("TVN Game Show")
app.geometry("300x100+200+100")

b1 = Button(app, text = "Correct!", width = 10, command = play_correct_sound)
b1.pack(side = "left", padx = 10, pady = 10)

In the above code, I understand that "app" is my TK() object. But what is the need and purpose of having it as the first parameter of Button? I feel like I'M asking to many simple questions but my book is doing a rather poor job of explaining all the code.

lewashby 56 Junior Poster
from Tkinter import *
import pygame.mixer

sounds = pygame.mixer
sounds.init()

correct_s = sounds.Sound("Correct.wav")
wrong_s = sounds.Sound("Wrong.wav")

number_correct = 0
number_wrong = 0

def play_correct_sound():
    global number_correct
    number_correct = number_correct + 1
    correct_s.play()
    
def play_wrong_sound():
    global number_wrong
    number_wrong = number_wrong + 1
    wrong_s.play()

app = Tk() # creat a tkinter application window called "app"

app.title("TVN Game Show")
app.geometry("300x100+200+100")

b1 = Button(app, text = "Correct!", width = 10, command = play_correct_sound)
b1.pack(side = "left", padx = 10, pady = 10)

b2 = Button(app, text = "Wrong!", width = 10, command = play_correct_sound)
b2.pack(side = "right", padx = 10, pady = 10)

app.mainloop()

print str(number_correct) + " were correctly answereed."
print str(number_wrong) + " were answered incorrectly."

In the above program I'M having two problems. The first is there is no sound played when I run this code and click on the buttons. The sounds can be found at http://www.headfirstlabs.com/books/hfprog/ under chapter 7.

The second problem I'M having is the last line will only and always display "0" for answered incorrectly.

Thanks for any and all replies.

lewashby 56 Junior Poster

No. It's not the exactly the same thing as pygame and I'M afraid it wont work with the book I'M trying to learn how to program with. "Head First Programming".

lewashby 56 Junior Poster

I've been trying to find pygame that will work with python 3 on my Ubuntu machine far a while with no luck. I can find a version that will work with Ubuntu but now for python 3, or I can find one that will work with python 3 but not Ubuntu. This is the closest I have cam. Can someone please look at the following site and tell me what I need to do? Thanks.

http://mentors.debian.net/cgi-bin/sponsor-pkglist?action=details;package=pygame

lewashby 56 Junior Poster

Thanks. The answer to that employer question. I think my employer would me more likely to fire me if they even suspected I was attempting to better in hopes of leaving that wonderful no AC no Heat factory.

lewashby 56 Junior Poster

I can't go back to school because I'M a single parent with a full time job. Thanks for all the replies.

lewashby 56 Junior Poster

I am trying to get into the IT field and I'M unable to go to school. Everything I learn is from books I get vie Amazon.com or Books-A-Million. I don't really know anyone in the programming or IT field to whom I can get guidance and direction. Does anyone have any suggestions as to how I can find and meat people in this field? I work in a big enough city (Chattanooga TN), so I know they're here, I just don't know where to find them. I even tried to find local facebook IT group but with no luck. Thanks for any and all replies.

lewashby 56 Junior Poster

Thanks for the help everyone.

lewashby 56 Junior Poster

Thanks. Although I'M not trying to learn all that at one. I'M asking for advice on which one would be best, form different perspectives. Which one make the most money, and which of those fields is the easiest and quickest to enter, ext ext.

lewashby 56 Junior Poster

I'M a single parent, 24, and I have a full time job in a factory. That's pretty much killed any change for me to go back to school. I love the computer field and I've been playing around with C# and Python for a little bit and I'M also a new comer to Linux via Ubuntu.
I would really love to get a job in the IT community and out of my current manufacturing environment. I would love some advice on fields and training that would be fisable to me. Thus far all I have is a GED and I just got a Certification of Completion for Introductory to C# (unaccredited) $90 from a local collage through this web site SNIP
I'M interested in Programming, A+, Network+, & Security +, Server Admin, Database Admin, Linux Admin. Not that I know a lot about any of those. I doubt that one little certification will get me far. And if it did I don't think I would be able to hold on to that job. I've found several other sites as well with online training in the fields mentioned above. Some were as lows as $200 to $3500.
There's also SNIP
I've found a lot more but I've got them on my Windows partition.

Those are my interest although I don't know what would be the best rout to take. I have just a little self taught programming experience via the Internet and Books-A-Million/Amazon.com. I would love …

lewashby 56 Junior Poster
def save_transaction(price, credit_card, description):
    file = open("transactions.txt", "a") # the "a" means you are always going to append to this file
    file.write("%s%07d%s\n" % (credit_card, price, description))
    file.close()


items = ["DONUT", "LATTE", "FILTER", "MUFFIN"]
prices = [1.50, 2.0, 1.80, 1.20]

running = True

while running:
    option = 1
    for choice in items:
        print(str(option) + ". " + choice)
        option = option + 1
    print(str(option) + ". Quit")
    
    choice = int(input("Choose an option: "))
    if choice == option:
        running = False
    else:
        credit_card = input("Credit card number: ")
        
        save_transaction(prices[choice - 1], credit_card, items[choice - 1])

In the program above I'M having trouble with a few lines of code. The fist is in the line choice = int(input("Choose an option: ")) Why must I use the same "choice" variable from my for loop? In the for loop choice holds the data for each element in items for each loop iteration. But now in holds a new value, a number selected by the user. I tried to change choice = int(input & if choice == option to something other than choice but it wouldn't run. And I don't understand why they must match up to the variable in the loop. The variable in the loop just temporarily hold the data for each element in items for each iteration. The second time the choice variable gets a new value, it's just compared to "option".

Last but not least, what is prices[choice -1] & items[choice - 1]?

Thanks for any all replies.

lewashby 56 Junior Poster

Thanks all.

lewashby 56 Junior Poster
import sqlite3

def find_details(id2find):
    db = sqlite3.connect("surfersDB.sdb")
    
    # grap surfer data from database
    db.row_factory = sqlite3.Row
    cursor = db.cursor()
    cursor.execute("select * from surfers")
    rows = cursor.fetchall()

In the code snippet above from "Head First Programming", the syntax for the database code is poorly explained.

Is row_factory a call, method, or just a variable based on sqlite3.Row. And what is sqlite3.Row?

And if row_factory is just a variable, why is it proceeded with a db and the two cursor lines and the rows in the line rows = cursor.getchall are not.

Non of this is explained in the book, please help.

lewashby 56 Junior Poster

csv = comma separated values file is file with separator between field (comma), typically comma,semicolon,tab,space. It has many variations: sometimes fields are quoted sometimes not et

def find_details(id2find):
    surfers_f = open("surfing_data.csv")
    
    for eash_line in surfers_f:
        s = {}
        
        (s["id"], s["name"],s["country"], s["average"], s["board"], s["age"]) = eash_line.split(";") ## name field
        
        if id2find == int(s["id"]):
            surfers_f.close()
            
            return(s)
        return({})
    
lookup_id = int(input("Enter the id of the surfer: "))

surfer = find_details(lookup_id)

if surfer:
    print("ID:         " + surfer["id"])
    print("Name:       " + surfer["name"])
    print("Country:    " + surfer["average"]) ## small a
    print("Board type: " + surfer["board"])
    print("Age:        " + surfer["age"])

csv = comma separated values file is file with separator between field (comma), typically comma,semicolon,tab,space. It has many variations: sometimes fields are quoted sometimes not etc.

csv = comma separated values file is file with separator between field (comma), typically comma,semicolon,tab,space. It has many variations: sometimes fields are quoted sometimes not etv

lewashby 56 Junior Poster

I know there was a problem with one of the recent Ubuntu Linux updates involving Karmic to Lucid that would no longer allow a Windows partition to load. I have not update my Ubuntu since that update release. Does anyone of if it's safe to update yet? Thanks.

lewashby 56 Junior Poster
def find_details(id2find):
    surfers_f = open("surfing_data.csv")
    
    for eash_line in surfers_f:
        s = {}
        
        (s["id"], s["country"], s["average"], s["board"], s["age"]) = eash_line.split(";")
        
        if id2find == int(s["id"]):
            surfers_f.close()
            
            return(s)
        return({})
    
lookup_id = int(input("Enter the id of the surfer: "))

surfer = find_details(lookup_id)

if surfer:
    print("ID:         " + surfer["id"])
    print("Name:       " + surfer["name"])
    print("Country:    " + surfer["Average"])
    print("Board type: " + surfer["board"])
    print("Age:        " + surfer["age"])

The database file can be found at http://www.headfirstlabs.com/books/hfprog/

In the above program I'M getting two errors, one on line 7 and another on line 17. I can't figure out what's going on. It says to many values to unpack. Thanks for any and all help.

One more thing, what is a .csv file

lewashby 56 Junior Poster
line = "101;johnny 'wave-boy' Jones;USA;8.32;Fish;21"

s = {}

(s['id'], s['name'], s['country'], s['average'], s['board'], s['age']) = line.split(";")
# above, why is "s" and the end of the key list surrounded by parenthesis?

print("ID:         " + s['id'])
print("Name:       " + s['name'])
print("Country     " + s['country'])
print("Average     " + s['average'])
print("Board type: " + s['board'])
print("Age:        " + s['age'])

The program is also not displaying the ID.

lewashby 56 Junior Poster

In the following program I have a few questions.

results.txt
Johnny 8.65
Juan 9.12
Joseph 8.45
Stacey 7.81
Aideen 8.05
Zack 7.21
Aaron 8.31

scores = {}

result_f = open("results.txt")

for line in result_f:
    (name, score) = line.split()
    scores[score] = name

result_f.close()

print("The toop scores were:")

for each_score in sorted(scores.keys(), reverse = True):
    print("Surfer " + scores[each_score] + " scored " + each_score)

(name, score) = line.split()
scores[score] = name

Why is the value "name" being placed into the variable [score]? It looks to me like it's just swapping places with name and score.

Secondly, what is reverse = Ture? Is reverse a function, because it doesn't look like one. It looks to me like a simple statement inside of the sorted function and after the keys function.

Last but not least, when I run my program, it doesn't display the score Juan 9.12.

Thanks for any and all response.

lewashby 56 Junior Poster

If this isn't enough you could always try Eclipse (you'll still be using g++, but at least with a nice and shiny IDE)

Thanks, but I looked up Eclipse using the Synaptic Package Manager and all I found was a Java?

lewashby 56 Junior Poster
StreamWriter outFile = File.CreateText ¬
    ("output1.txt");

In the above line of what, what is File. I see that StreamWriter is a class, outFile is our instance of that class, and CreateText would be a method. But what is the "File." before the CreateText method?

Normally when I have created any type of instance it's looked like this,

ClassName instance = new ClassName

Thing have gotten just a little bit more confusing without explanation. Thanks.

lewashby 56 Junior Poster

I'M using Ubuntu and I'M running python 3. I'M trying to find a pygame download for Ubuntu and python 3. I went to pygame.org and followed the Ubuntu link. I eventually found one link for pygame 1.9, which I'M told works for pythan 3. There were two files, amd64 & i386. I downloaded them both, and they both said that is was the wrong architecture. I'M running an AMD Turion(tm) X2 Dual-Core Mobile RM-72. And I can't find pygame at all in the Ubuntu Software Center and I can only find pygame 1.8 in the Synaptic Package Manager. Thanks for any and all help.

lewashby 56 Junior Poster

I use Ubuntu Linux and I'M running python 3. How do I know what version of pygame to get for python 3? And could someone point me to it? Thanks.

lewashby 56 Junior Poster

Recently a friend of mine updated his Ubuntu Linux and then his Windows partition failed to boot there after. I read up on it and apparently a lot of people are having the problem and it has something to do with karmic to lucid, or something like that I can't remember. I also have a Windows partition. So I'M wondering, does anyone know that that problem has been fixed. I haven't updated my Ubuntu since that happened to his machine and I'M wondering if it's safe to do so yet. Thanks.

lewashby 56 Junior Poster

Could anyone point me to a good C++ compiler for Ubuntu, other than Mono. Note that I was using Visual C++ 6. thanks.

lewashby 56 Junior Poster

I know a lot of you out there are probably way to stuck up to consider iTunes, I use to be the same way. I felt that I may lose control over my music files or some other ridicules scare. But when I finally did try it, I absolutely loved it, as well as an accompanying iPod. But seeing that I am trying to move to Linux and Apple has yet to release iTunes for Linux, I would like some suggestions. I'M using Ubuntu. So what are some good media players out there for Ubuntu as well as some mp3 devices? I would love to hear some feedback on this, thanks.

lewashby 56 Junior Poster

I just updated Ubuntu and now my Windows partition will not start from within the grub loader. When I select Windows, the screen is black with a white blinking cursor at the top left of the screen. Any help would be greatly appreciated. Thanks.

lewashby 56 Junior Poster

I'M trying to learn to program and I'M also new to the Linux OS. I've just started with Ubuntu. Anyway, I was reading a long list of post from Linux users posting on Mono. I'M trying to figure out where all the negative feedback concerning Mono is coming from. Why are so many Linux people against it?

Is it just because C# was created by Microsoft? I mean hey, if it works it works and lets use it. I noticed a lot of the complaints where that Microsoft has a patent on it or something like that. So what exactly does that mean anyway, what relevance does that have and how will it affect us? It works and it's free so I just want to know, what's the big deal? Is this the typical Linux and Mac attitude to act superior to everything Windows? Or is there some real substance behind these allegations? Thanks

lewashby 56 Junior Poster

The book I'M reading "Head First C#" is trying to teach my about the use of properties, private vs public. But when viewing the following code, I still don't understand why the program is behaving the way it is.

The code shows 5 bags of feed no matter how many cows I have set in the numericUpDown1 value. But it looks like to me the line

BagsOfFeed = numberOfCows * FeedMultiplier; in the set property should set it back the way it should be anyway. There are the files.

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 Cow_Calculator
{
    public partial class Form1 : Form
    {
        Farmer farmer;
        public Form1()
        {
            InitializeComponent();
            farmer = new Farmer() { NumberOfCows = 15 };
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("I need {0} bags of feed for {1} cows", farmer.BagsOfFeed, farmer.NumberOfCows);
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            farmer.NumberOfCows = (int)numericUpDown1.Value;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            farmer.BagsOfFeed = 5;
        }
    }
}

Farmer class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cow_Calculator
{
    public class Farmer
    {
        public int BagsOfFeed;
        public const int FeedMultiplier = 30;

        private int numberOfCows;
        public int NumberOfCows
        {
            get
            {
                return numberOfCows;
            }

            set
            {
                numberOfCows = value;
                BagsOfFeed = numberOfCows * FeedMultiplier;
            }
        }
    }
}

One last question. How in the world would I know that the creation of Farmer should be broken into two …

lewashby 56 Junior Poster

I'M rather new to Linux and I've just started with Ubuntu. I'M trying to understand the file system. I see that rather than a traditional drive letter like C: , Linux uses a single /. But I guess my real question is, where are programs stored? In Windows they're stored in X:Program Files\. One other thing, what is the file extension for a program launcher, the linux equivelent of a windows .exe? I was trying to find the launcher to a program but found myself unable to be specific enough to find what I needed with an extension.

lewashby 56 Junior Poster

I prefer gnome to KDE but I don't know what this is but I thought I might give it a try. If anyone knows what this is and where to get it, please let me know, thanks.


http://www.tomshardware.com/gallery/ubuntu-linux,0201--6247----jpg-.html

lewashby 56 Junior Poster

I recently uninstalled python 2.6 from my Ubuntu, unbeknown to me at the time, the gnome desktop is reliant on python 2.6. Ubuntu then crashed and now will only load up in Kubuntu KDE. Kubuntu will not let me switch back to Ubuntu gnome, it's not an option. So from Kubuntu I am as I am writting this downloading from the Synaptic package Manager "Ubuntu-Desktop". It's only tacking about 5 minutes an consist of around 80 files. Am I downloading the right package(s), it just seemed a little small to me?

One more thing, assuming that this works, what happened to all the other files and packages that went to gnome, are they still sitting in my computer taking up space not being used? Thanks for any and all replies.

lewashby 56 Junior Poster

I recently decided to update my version of python from 2.6 to 3.1. At the time I didn't realize that the gnome desktop relied upon python 2.6. In the middle of py 2.6 un-installation, Ubuntu crashed, when it reloaded I could only use Kubuntu KDE. I would just try to download Ubuntu-desktop from Kubuntu but I can't get the internet to load up in Kubuntu. I also considered starting it up in safe mood and just using a command to get a new copy of gnome, but again, how would I connect to the internet? Any suggestions on how to get this done. One more thing, my Kubuntu how has a very strange looking folder view. Every file and folder is represented by a colored triangle, it's very strange and hard to use.

lewashby 56 Junior Poster

I've had KDE for a while but I didn't like it as much to I stuck with gnome. Today I updated my gnome and a while later I decided to un-install python 2.6 and replace it with 3.0. I noticed that un-install was going really slow. Then my computer suddenly rebooted and now it will only start up in KDE. Can someone help me please? Thanks.

lewashby 56 Junior Poster

In the code below I can't understand the line

List<Surface> sfcStars = new List<Surface>();
What's going on here, and what are "<>" those doing in the code, I've never seen the before.
I got this code from http://www.tuxradar.com/beginnerscode

using System;
using SdlDotNet.Graphics;
using System.Collections.Generic;
using System.Drawing;

namespace TroutWars
{
	
	
	class Starfield
	{
		List<Surface> sfcStars = new List<Surface>();
		
		public Starfield()
		{
			sfcStars.Add(new Surface("content/stardark.bmp"));
			sfcStars.Add(new Surface("content/starmedium.bmp"));
			sfcStars.Add(new Surface("content/starbright.bmp"));
		}

}
}

lewashby 56 Junior Poster

I'M reading the book "Beginning C# Game Programming by Ron Penton". The book is instucting me to create a small framework for a game, the problem is, the book was written for VS 2002 and I'M using VCs 2008 express. I'M instructed to add references to the project, two of which I can't find. Microsoft.DirectX & Microsoft.DirectX.3D.

Here's the code and the errors I'M getting

Error 1 The type or namespace name 'DirectX' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) C:\Users\Owner\Documents\Visual Studio 2008\Projects\02-VCSFrame1\02-VCSFrame1\MainClass.cs 12 17 02-VCSFrame1

Error 2 The type or namespace name 'DirectX' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) C:\Users\Owner\Documents\Visual Studio 2008\Projects\02-VCSFrame1\02-VCSFrame1\MainClass.cs 13 17 02-VCSFrame1

Error 3 The type or namespace name 'Device' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Owner\Documents\Visual Studio 2008\Projects\02-VCSFrame1\02-VCSFrame1\MainClass.cs 25 3 02-VCSFrame1

// Beginning C# Game Programming
// (C)2004 Ron Penton
// Chapter 6
// Demo 2 - Visual C# Framework

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace MyDirect3DProject
{
	/// <summary>
	/// This is the main class of my Direct3D application
	/// </summary>
	public class MainClass : Form
	{
		/// <summary>
		/// The rendering device
		/// </summary>
		Device device = null;
		
		public MainClass()
		{
			this.ClientSize = new System.Drawing.Size(640, 480);
			this.Text = "Direct3D Project";
		}
		
		public bool InitializeGraphics()
		{
			try {
				// Now let's setup the …
lewashby 56 Junior Poster

Dog[] dogs = new Dog[7];
dogs[5] = new Dog();
dogs[0] = new Dog();

According to the book I'M reading the second two lines here create instances but the first only creates an array.
I'M still learning how to program but it looks to me like the fist line is also creating an instance. And it also seem
like that would be better anyway. If you have to explicitly tell each element in the array that it's an object, then that's just as much
typing as if you never used an array in the first place. Again remember, I'M learning.

lewashby 56 Junior Poster

First off, I did google this before hand but most of the answers I got were about assigning attributes, but that's the the trouble I'M having. I'M trying to understand the "this" keyword beging used as a parameter/argument.

Here some sample code

There is a class by the name Elephant.

Elephant lloyd = new Elephant() { Name = "Lloyd", EarSize = 40 };
Elephant lucinda = new Elephant() { name = "Lucinda", EarSize = 33 };

public void TellMe(string message, Elephant whoSaidIt)
{
MessageBox.Show(whoSaidIt.Name = "says: " + message);
}

public void SpeakTo(Elephant talkTo, string message)
{
talkTo.TellMe(message, this);
}

lucinda.SpeakTo(lloyd, "Hello");

According to the book I'M reading, Lucinda's talkTo parameter of the SpeakTo method has a reference to Lloyd's TellMe method. I don't see it. When where and how dos talkTo point to Lloyds TellMe?

lewashby 56 Junior Poster

In the code below, I'M having trouble with one line of code

MenuMaker menu = new MenuMaker() { Randomizer = new Random() };

The program is a simple windows Form with two main files, Form1.cs & MenuMaker.cs, the second one is a class.

What I'M trying to understand is why is the line of code above in the Form1.cs file instead of the MenuMaker.cs class where the rest of my fields are at, including the creation of my Random instance. The two files are below.

Form1.cs

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 DiscountSandwiches
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            MenuMaker menu = new MenuMaker() { Randomizer = new Random() };
                
            label1.Text = menu.GetMenuItem();
            label2.Text = menu.GetMenuItem();
            label3.Text = menu.GetMenuItem();
            label4.Text = menu.GetMenuItem();
            label5.Text = menu.GetMenuItem();
            label6.Text = menu.GetMenuItem();
        }
    }
}

MenuMaker.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiscountSandwiches
{
    public class MenuMaker
    {
        // fields
        public Random Randomizer;


        string[] Meats = { "Roast beef", "Salami", "Turkey", "Ham", "Pastrami" };
        string[] Condiments = { "yellow mustard", "brown mustard", "honey mustard",
                                  "mayo", "relish", "french dressing" };
        string[] Breads = { "rye", "white", "wheat", "pumpernickel", "itelian bread", "a roll" };

        // methods
        public string GetMenuItem()
        {
            string randomMeat = Meats[Randomizer.Next(Meats.Length)];
            string randomCondiment = Condiments[Randomizer.Next(Condiments.Length)];
            string randomBread = Breads[Randomizer.Next(Breads.Length)];

            return randomMeat + " with " …
lewashby 56 Junior Poster

The error means that on line 16 of your first code, the class EventArgs does not contain a method Run
I looked at the link you gave: change line 16 to Events.Run().

Thanks, that took away one error message, but now I'M getting this one.

[Task:File=/home/developer/Projects/TroutWars/TroutWars/Main.cs, Line=15, Column=72, Type=Error, Priority=Normal, Description=

An object reference is required to access non-static member `TroutWars.MainClass.Quit(object, SdlDotNet.Core.QuitEventArgs)'(CS0120)]

lewashby 56 Junior Poster

I'M reading this tutorial at http://www.tuxradar.com/beginnerscode at all I have done thus far is enough for an empty game window built with two small .cs files.

Here are the error messages.

Line=15, Column=72, Type=Error, Priority=Normal, Description=An object reference is required to access non-static member TroutWars.MainClass.Quit(object, SdlDotNet.Core.QuitEventArgs)'(CS0120)]

&

Description=`System.EventArgs' does not contain a definition for `Run'(CS0117)]

Here are the files

Main.cs

using System;
using SdlDotNet;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using System.Drawing;

namespace TroutWars
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			TroutWars game = new TroutWars();
			Video.SetVideoMode(1024, 768);
			Events.Quit += new EventHandler<QuitEventArgs>(Quit);
			EventArgs.Run();
		}
		
		void Quit(object sender, QuitEventArgs e)
		{
			Events.QuitApplication();
		}
	}
}

TroutWars.cs

using System;
using SdlDotNet;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using System.Drawing;

namespace TroutWars
{
	
	
	public class TroutWars
	{
		
		public TroutWars()
		{
			Console.WriteLine("Hello World!");
		}
	}
}

Any help would be greatly appreciated, thanks.

lewashby 56 Junior Poster

Yea I seen that, I put it at the top of the page!

lewashby 56 Junior Poster

Running Mono on Ubuntu 9.10

Main.cs

using System;
using SdlDotNet;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using System.Drawing;

namespace TroutWars
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			Video.SetVideoMode(1024, 768);
			Events.Quit += new EventHandler < QuitEventArgs > (Quit);
			EventArgs.Run();
		}
		
		void Quit(object sender, QuitEventArgs e)
		{
			Events.QuitApplication();
		}
	}
}

TroutWars.cs

using System;
using SdlDotNet;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using System.Drawing

namespace TroutWars
{
	
	
	public class TroutWars
	{
		
		public TroutWars()
		{
			Console.WriteLine("Hello World!");
		}
	}
}

Thanks for any and all help.

lewashby 56 Junior Poster

I'M trying to build a simple Console.WriteLine program in mono. It build with no errors but there is not output for what I have coded it to say. All I'M getting is

---------------Done----------------
Build Successful.

Thanks.

lewashby 56 Junior Poster

Since I first moved to Ubuntu, one of my biggest complaints is Totem not having any audio, does anyone have any suggestions? Thanks.