nmaillet 97 Posting Whiz in Training

You need to go through a Java tutorial. Couple things from a glance:

Each class/interface needs to defined in its own JAVA file, with the same name. For instance, SaturnSL1 must be in a file called SaturnSL1.java.

You should be declaring the ParkingGarage class outside of the main method().

nmaillet 97 Posting Whiz in Training

So... I'm assuming you have tried to rebuild it, and it didn't work?

You could also try deleting the executable in the bin\Debug (or Release) folder. If the executable's gone, there shouldn't be any reason it would execute old code. You may also have to delete the executable in the obj\x86\Debug folder.

nmaillet 97 Posting Whiz in Training

In the Main() method, put something like this:

if (DateTime.Now >= new DateTime(2011, 8, 20)
    Environment.Exit(0);

This says that, on or after August 8, 2011 it will just terminate the program. Note that this will, of course, be easy to bypass by changing the system time.

nmaillet 97 Posting Whiz in Training

If your using Visual Studio, have you tried Rebuild Solution in the Build menu? It is possible that the IDE thinks the executable is newer than the source code. I know when building VC++ in Visual Studio, it gives you the option to run the previous successful build, if there are compile errors. I don't know if C# has the same option.

It's hard to tell without more details (i.e. IDE, source code, etc.).

nmaillet 97 Posting Whiz in Training

Seriously, take some courses (or better yet, get a degree). For and while loops are used in so many common languages. You are not ready for any kind of software development career.

nmaillet 97 Posting Whiz in Training

You need to Windows API to work with these functions, and #include "Windows.h". The reference for these functions is located here.

Be sure to check the return value of OpenClipboard(). If it returns a zero (false) it failed, otherwise, if it returns a non-zero (true) it succeeded. If it returns false, another program likely has access to it, so you should wait briefly and try again.

nmaillet 97 Posting Whiz in Training

Does the x'd out user folder have any non-alphanumeric or non-whitespace characters?

nmaillet 97 Posting Whiz in Training

Your question is a little vague on details, but you could initialize a new TimeSpan:

TimeSpan span = new TimeSpan();

Then iterate through your list of hours and add them as a new TimeSpan:

span += new TimeSpan(hours, minutes, seconds);

I don't understand what to are trying to get at with "if all months of the year have 31 days?". Could you elaborate? Or post some code?

nmaillet 97 Posting Whiz in Training

Not quite, it will actually fall-through, for instance:

int i = 0;
switch(i)
{
    case 0:
    case 1:
        Console.WriteLine("valid");
        break;
    default:
        Console.WriteLine("invalid");
        break;
}

This will output valid . It just allows you to have multiple discrete values for a single block of code.

nmaillet 97 Posting Whiz in Training

You can define whatever you like. If you access the file as a binary file, you can use 256 values with a single byte. Or you can use two bytes, this would 65536 values.

Some things you may want to consider though:
- You'll need at least two layers for drawing sprites (i.e. base tiles with no alpha value, sprites/NPC's)
- The NPC's will likely be walking around, have things to say, challenge you to battles, etc. You may need to allocate more space to reference their attributes.

nmaillet 97 Posting Whiz in Training

Note that you can use fall-through for empty case's:

switch(i)
{
    case 0:
    case 1:
        ...
        break;
    case 2:
        ...
        break;
}

This is occasionally useful.

nmaillet 97 Posting Whiz in Training

I have never actually worked with it, but to get your result:

private void MyCodeCondition(object sender, ConditionalEventArgs e)
        {
           e.result = ((KeyValuePair<string, object>)comboBox1.SelectedItem).Key == "option1";
        }

Or to make your code slightly more readable:

private void MyCodeCondition(object sender, ConditionalEventArgs e)
        {
           KeyValuePair<string, object> pair = (KeyValuePair<string, object>)comboBox1.SelectedItem;
           e.result = pair.Key == "option1";
        }

Basically, just because a ComboBox displays a string, doesn't mean that the SelectedItem is a string. The Dictionary<> class is a collection of KeyValuePair<> which is what the ComboBox uses for each item. If you look at the Dictionary class, notice it inherits ICollection<KeyValuePair<TKey, TValue>> and IEnumerable<KeyValuePair<TKey, TValue>>. I believe it uses ICollection to determine each item for the ComboBox (though it could be IEnumerable, I can't remember off the top of my head).

Hope this helps.

nmaillet 97 Posting Whiz in Training

Right-click on your project in solution explorer and click Properties. Under Configuration Properties --> Common Language Runtime Support, ensure it is set to No Common Language Runtime Support.

When creating a new project, under Visual C++, select Win32 and then select either Win32 Console Application or Win32 Project.

Just to be sure, what are your friends installing to run it? They will require the VisualC++ Redistributable Package, as it contains libraries that they use. They should not however, require the full .NET Framework.

nmaillet 97 Posting Whiz in Training

When working with Object properties, you can determine the type using something like:

System.Diagnostics.Debug.WriteLine(comboBox1.SelectedItem.GetType());

Assuming you are using an IDE. Otherwise you can just show it in a MessageBox. In this case it is returning a KeyValuePair<string, object>, so you can just cast it and check the Key property:

KeyValuePair<string, object> pair = (KeyValuePair<string, object>)comboBox1.SelectedItem;
if (pair.Key == "option1")
{
    ...
}

Out of curiosity, why are you using the Dictionary itself as a Value? Couldn't you just use a List or HashSet?

nmaillet 97 Posting Whiz in Training

Your should add an initializer for base8; if x is < 10 then base8 is never assigned and will cause problems with the result. In addition, it looks like you can't go beyond certain number (i.e. 123 does not work).

In either case, I think you're over complicating the issue. You could simply iterate through each digit multiplying it by 8 to the power of the position number:

int ret = 0;

for(int multi = 1; x > 0; multi *= 8) {
	int digit = x % 10;
	if(digit > 7)
		return -1;
	ret += digit * multi;
	x /= 10;
}

return ret;

In each iteration you can check for an invalid digit.

EDIT:
Just to clarify, the ^ operator is a bitwise XOR operator, not a power function. I believe that is not what you intended.

nmaillet 97 Posting Whiz in Training

Just a quick note. WaitForExit() should be called after reading the stream. Although it is not likely to occur, this method will enter a deadlock if the stream's buffer becomes full before the program is able to exit.

nmaillet 97 Posting Whiz in Training

Request to Send (RTS) is used to signal a devices intention to send data. Without it the connected device may refuse to receive data.

For modems, Data Terminal Ready (DTR) is used to tell a modem that it wants to dial out, and drops the signal to low to drop the call. It is also used to tell the modem that the serial port is ready to receive an incoming call. If you are not using a modem, then I'm not sure, I believe it depends on the specific device.

nmaillet 97 Posting Whiz in Training

When you compile the source code, everything gets translated to machine code, and everything ends up being referenced by a memory address. In addition, the compiler will likely optimize your code, and will not maintain any 1 to 1 relation to the source code. The idea of a line number is lost by this point. It may be possible to use a debug file (such as a PDB file from VisualC++) to achieve this, but that would not be a trivial task.

nmaillet 97 Posting Whiz in Training

Assuming you are using an array of pointers (you could easily modify if you are storing the structures themselves):

int count = 0;
for(int i = 0; i < size; i++)
    if (teams[i]->progress)
        count++;
Team **teamsSubset = new Team*[count];
for(int i = 0, i2 = 0; i < size; i++)
    if (teams[i]->progress)
        teamsSubset[i2++] = teams[i];
some_function(teamsSubset, count);

I didn't compile this, so there may be some issues, but hopefully you get the general idea. Even simpler, you could use a list, vector, etc. from the STL.

nmaillet 97 Posting Whiz in Training

Do you have Visual Studio 2010 installed? I don't believe any previous versions ever added support for 4.0. If so, just open the solution with VS2010, and use the conversion wizard.

nmaillet 97 Posting Whiz in Training

For b &= (byte) ~a; , the compiler will check this conversion since a is a constant, and it is certain what the value will be. Since bitwise operations return int's (doesn't seem right to me), it will evaluate ~a as an int, which would evaluate to -9. I don't think there is any other way, except to use unchecked statements:

unchecked
{
    b &= (byte) ~a;
}
nmaillet 97 Posting Whiz in Training

dir isn't actually an executable; it is a command that Command Prompt understands. You could replace line 4 with:

p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "/c dir";

That should work for you.

nmaillet 97 Posting Whiz in Training

To reference the current Thread, you could use Thread.CurrentThread.Suspend(); . The Suspend() method is obsolete however, what are you trying to achieve?

nmaillet 97 Posting Whiz in Training

You should definitely add a check to ensure there is 7 characters in the string, otherwise you will get an out of bounds exception:

...
if (textBox.Text.Length >= 7 && (textBox.Text[6] == M || textBox.Text[6] == G))
...
nmaillet 97 Posting Whiz in Training
txtBox.Text[6] == 'm';

That should work for you. If you are checking for numbers as well, you can iterate through the characters in the string (returned by the TextBox.Text property) and use char.IsNumber().

nmaillet 97 Posting Whiz in Training

The DataSet class does offer direct serialization to/from XML files, however I'm assuming your DataSet doesn't necessarily correlate to your XML schema. So, take a look at the XmlDocument class. Basically you can create XML elements and attributes using the XmlDocument's Create...() methods, than use AppendChild() on the appropriate object to build its structure. Finally use XmlDocument.Save() to generate the file.

kvprajapati commented: Good suggestion. +15
nmaillet 97 Posting Whiz in Training

It is because of the while(y<=num) statement. When your iteration, where x = 21 and y = 34, is complete: it checks if y is <= num (which it is), so it continues executing. If you changed it to while(y<num) it would stop at 34.

nmaillet 97 Posting Whiz in Training

You shouldn't be converting the float variable to a string. This will not allow the proper formatting:

double A = 0.532492829839;
string.Format("{0:0.00}%", A * 100.0);
nmaillet 97 Posting Whiz in Training

You can download the express editions. It looks like Microsoft no longer directly links to any of the downloads on their site anymore, but you can still link to them directly. Note that I have not tested any of these links:
http://apdubey.blogspot.com/2009/04/microsoft-visual-studio-2005-express.html

nmaillet 97 Posting Whiz in Training

I would recommend you use the Random class in these exercises. Specifically, look at the nextInt(int n) method when you require integers. Calling the default Random() constructor should generate a suitable seed value for your purposes.

For your first question, Math.random() returns values in the range [0,1). This means that the value can be anywhere in the range 0-0.999... but will never equal 1. Given this, choice will only ever be in the range [0,3), which is equivalent to [0,2] when casted to an int.

Your second question has a similar problem to question 1. In addition, the question asks for five sets of six integers. You will require two for-loops to achieve this. Also, the question asks for different (or unique) integers in each set. You could use an array to achieve this.

There is no randomness to your third answer. You need to randomize the values, not simply print a sequential list of them. You'll have to initialize a Random object:

Random random = new Random();

then you can get symbol by calling:

random.nextInt(26) + 65;

Note that the range of nextInt() is 0 (inclusive) to n (exclusive).

Good luck.

nmaillet 97 Posting Whiz in Training

Could you post your code? I'm having trouble understanding what your question is.

nmaillet 97 Posting Whiz in Training

Is the background image being covered by the highlighted border? If so, you'll probably have to override a Renderer class, and wrap the default ToolStripRenderer to achieve this. See this thread. It's been a while since I've done much with WinForms, but I believe this is quite an involved process. WPF allows for quite a bit more visual customization, if you are able to switch.

Also, you shouldn't be calling Image.FromFile() in each of the events. I could be wrong, but I don't believe this method caches the images for subsequent calls. You should call it once in the constructor of the Form and store it as a local variable.

nmaillet 97 Posting Whiz in Training

Arrays are initialized when they have a length of 0. They may not contain any values, however they do store the length and allow you to reference it. If you attempt to reference the length of a null reference, you will get an exception. It can be useful when you are certain that an array is not null; for instance, if you store a final reference to an array, and do your check in the constructor of a class. Then you can avoid additional checks in the class (or at the beginning of a method):

for(int i = 0; i < array.length; i++) {
    ...
}

Instead of performing additional checks:

if(array != null)
    for(int i = 0; i < array.length; i++) {
        ...
    }

The actual usefulness is somewhat negligible, but that depends on your circumstances.

nmaillet 97 Posting Whiz in Training

Form has a public Dispose() method. Why are you trying to cast between the two types? Assuming that both classes derive from Form, HD.MainMenu and HD.NewBookEntry are both ancestors of Form, and have common variables/methods from Form. However, they define their own variables/methods, therefore they lack a commonality between them.

nmaillet 97 Posting Whiz in Training

You are adding the input value to num; then checking num. Therefore if you entered 5, 6, 7, 0. num would equal 18 when you checked it against 0. Try something like this:

...
int n = int.Parse(Console.ReadLine());
if(n == 0)
    break;
num += n;
...

Also, note that I used a int when comparing it to 0. Although an int value stored to a double should exactly equal an integer, it may not. It could be equal to something like 0.000000000000001. Floating point numbers can never be guaranteed to be exact. You should try and avoid exact comparisons of floating point numbers.

nmaillet 97 Posting Whiz in Training

(a - (a * b)) , where a = 19.99 and b = 0.2, equals 15.992. It you multiply it by 12, you get 191.904, which rounds to 191.90 on line 27. You would have to round the calculation (a - (a * b)) before multiplying it by c to achieve your results.

nmaillet 97 Posting Whiz in Training

No I did not...this should work:

private void maskedTextBox2_GotFocus(object sender, EventArgs args)
{
    BeginInvoke((MethodInvoker)delegate()
    {
        maskedTextBox2.SelectionStart = 0;
        maskedTextBox2.SelectionLength = 0;
    });
}
nmaillet 97 Posting Whiz in Training

It was not working with tab stops since the SelectionStart/SelectionLength can only be set when the Control has focus. Therefore it should actually be in the GotFocus event. However, the mouse click and caret positioning is done after this. If you use BeginInvoke() method, the message should be processed after the mouse click is handled, for instance:

private void maskedTextBox2_GotFocus(object sender, EventArgs args)
{
    BeginInvoke((MethodInvoker)delegate()
    {
        maskedTextBox2.SelectionStart = 0;
        maskedTextBox2.SelectionLength = 0;
    }
}
nmaillet 97 Posting Whiz in Training

I believe decimal numbers just provide more significant digits than double or float.

nmaillet 97 Posting Whiz in Training

You don't need to simulate a key press. You could just set maskedTextBox.SelectionStart = 0; and maskedTextBox.SelectionLength = 0; .

nmaillet 97 Posting Whiz in Training

You can never be certain of rounding errors. For instance try running the following code:

Console.WriteLine("{0:G17}", 0.72 + 0.11 + 0.06 + 0.11);

On my system, this returns 0.99999999999999989. Note that this may be different for your system, which leads to your second question. Consistency cannot be guaranteed across different architectures. It should produce consistent results on the same machine, but I cannot say that with certainty.

nmaillet 97 Posting Whiz in Training

Does it need to be efficient? If O(n2) is acceptable, you could just initialize an int array of the same size, then store the number of following characters that are equal. Then use the index of the largest int value to locate your maximum occurring character.

nmaillet 97 Posting Whiz in Training

Events can only be raised from the class that declared them (even derived class' cannot invoke them). Luckily WPF/Forms controls implement protected methods to allow derived classes to do this. Just derive from the Button class, and call OnClick(), for example:

public MyButton : Button
{
    public void SimulateClick()
    {
        OnClick();
    }
}
nmaillet 97 Posting Whiz in Training

I believe when you create the new Chart, it becomes the new ActiveSheet. Therefore you are trying to retrieve a Range from the Chart. Try creating the Chart after getting the Range.

nmaillet 97 Posting Whiz in Training

For your first pattern, you would require something like: \{(\-?[0-9]+\.[0-9]+,)*(\-?[0-9]+\.[0-9]+)\} Note that I made quite a few big assumptions for this:
- Cannot be empty ("{}")
- Cannot exclude the decimal or numbers before/after (".9", "9." or "9" would be invalid").
- Cannot start with a + sign.
Take a look at http://msdn.microsoft.com/en-us/library/ms256481.aspx for more information on Regular Expressions.

Your second and third patterns could simply use the decimal and integer types respectively, for example:

<xs:element name="price" type="xs:decimal"/>

Your fourth one could use the pattern: [NY] Or you could use <xs:enumeration value="N"/>... instead.

You should also check out W3 Schools as well. They usually have some good examples/tutorials.

nmaillet 97 Posting Whiz in Training

You should be able to do something like this:

char **b_array;
b_array = new char*[MAXPATHLEN];
for(int i = 0; i < MAXPATHLEN; i++)
	b_array[i] = new char[numFtrs];

char ***b_array_ptr;
b_array_ptr = &b_array;

I am certain there is some shortcut for this, but I don't have time to look around right now.

nmaillet 97 Posting Whiz in Training

Take a look at the System.Data.SqlClient namespace, and search for some tutorials on using SQL with C#. There are plenty around.

nmaillet 97 Posting Whiz in Training

You can also use the AcceptButton property of the Form. This will however, capture the Enter key from any control on the Form. But, this generates the button's Click event, a mouse click or enter key can be handled in the same method.

nmaillet 97 Posting Whiz in Training

You'll want to take a look at the System.Xml namespace. As a starting point, you can call XmlDocument.Load(...) , and work from the XmlDocument object created.

nmaillet 97 Posting Whiz in Training

Look at the Console class. You can use a combination of the Write(), WriteLine(), Read(), ReadKey() and ReadLine() methods.