nmaillet 97 Posting Whiz in Training

Start with the basics of getting a window to display, and go from there.

nmaillet 97 Posting Whiz in Training

I ran your code, and it seems to be working fine (although you should probably use e.Index instead of checkedListBox1.SelectedItem). Did you register the methods with the corresponding events, either through Visual Studio's properties panel, or with the following code (in the Form's constructor)?

checkedListBox1.ItemCheck += checkedListBox1_ItemCheck;
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
nmaillet 97 Posting Whiz in Training

K... did you try the SizeMode property...?

EDIT: Nvm, your welcome.

nmaillet 97 Posting Whiz in Training

What do you mean by "upload"? Assuming you want an image to stretch/zoom to fill the PictureBox, you can use the PictureBox.SizeMode property.

nmaillet 97 Posting Whiz in Training

Unless you have a system with a MIPS architecture, you'll need to use a simulator to run it. A quick Google search turned up MARS MIPS Simulator. FYI, a program to converters assembly language into machine code is generally called an assembler.

nmaillet 97 Posting Whiz in Training

Start by declaring a boolean variable before the for-loop:

bool correct_pass = false;

Then, you set it to true inside the for-loop, when the password is correctly entered:

for (int i=0;i<3;i++)
{
    ...
    if (pass=2468)
    {
        correct_pass = true;
        break;
    }
    ...
}

Then you just check to see if the bool is true outside the for-loop (the break statement gets you out of the for-loop). You can then use another loop for the options menu.

nmaillet 97 Posting Whiz in Training

First in your textbox Properties

CharacterCasing: Upper
MaxLength: 7

In your textbox Keypress event:

So what happens if the user moves the caret to some position other than the end of the text? And why are you allowing spaces everywhere?

nmaillet 97 Posting Whiz in Training

Pls Be early To provide code in two three days.

And when did you start signing my paycheques?

I am new in programming

Well, this is a great opportunity to learn. Give it a try.

nmaillet 97 Posting Whiz in Training

For starters, could you please answer the questions from my first post?

Just so I'm clear, you are instantiating a new instance of your Form (i.e. new SomethingForm();) before each call to ShowDialog();, correct? I tried your code, and it seems to be working. Also, a stack trace is nice, but what is the actual exception you are getting (class and message)?

nmaillet 97 Posting Whiz in Training

for i = 3 to i * i < number // start at 3 since 1 and 2 are prime

Shouldn't it be i * i <= number? Otherwise some square numbers will be improperly considered prime (e.g. 9 or 25).

nmaillet 97 Posting Whiz in Training

@jinus Please don't give out answers, especially wrong ones, to people who have not shown any attempt yet.

As I can see, the XML file is well formated.

No, it isn't (note </Paris instead of </Place>), and neither is your code.

var source = XElement.Load(MyFile)

Where's the semicolon?

var Query = from User in source.Descendents("User")

Descendents() doesn't exist; Descendants() does however.

where source.Element("Name").Value > "David"

Shouldn't we be referring to the User, not the source... again.

select new {Id = (int32)User.Element("Name").Value,

int32 doesn't exist... C# is case-sensitive, eh? Also, casting does not convert between strings and integers. And since when was Name an integer.

title = (string)User.Element("Attempts").Element("Date").Value}

Casting a string to a string... seems unnecessary, but where's the semicolon?

nmaillet 97 Posting Whiz in Training

If you're using WinForms, you could use the MaskedTextBox control.

nmaillet 97 Posting Whiz in Training

Any numeric literal preceeded by 0x indicates a hexadecimal (or base-16) value. Basically each digit represents a value from 0-15 (0-9 then A-F). It is useful because two hexidecimal digits represent exactly one byte (00, 01, ... fe, ff in hexadecimal is equivalent to 0, 1, ..., 254, 255 in decimal), and makes things much easier to understand when dealing with bitwise operations (once you understand them).

nmaillet 97 Posting Whiz in Training

That's what I thought from the first post, then I saw this:

viewImagesForm.ShowDialog();

if (viewImagesForm != null && !viewImagesForm.IsDisposed)
{
    viewImagesForm.DisposeImageControls(viewImagesForm);
    viewImagesForm.Dispose();
    viewImagesForm = null;
}

where he sets viewImagesForm to null. So I wanted to know whether he was getting the reference to the form from somwhere else before viewImagesForm.ShowDialog();, or instantiating a new one.

If that is the case, then Dispose() shouldn't be called on the Form, since unmanaged resources are generally allocated in the constructor. A disposed control (or pretty well any object) should be considered unusable. The same is true for the PictureBox. If you wanted to dispose of a PictureBox after the Form is closed, but reuse the Form afterwards, you would have to instantiate and add the controls outisde of the constructor (in the Load event perhaps). The controls should also be removed from the Form.Controls collection when they are disposed of.

FYI, I tested the code without disposing the Form (or setting the variable to null), and I didn't get any exception. The PictureBox just didn't display anything.

nmaillet 97 Posting Whiz in Training

Just so I'm clear, you are instantiating a new instance of your Form (i.e. new SomethingForm();) before each call to ShowDialog();, correct? I tried your code, and it seems to be working. Also, a stack trace is nice, but what is the actual exception you are getting (class and message)?

nmaillet 97 Posting Whiz in Training

You can always give LINQ to XML a try. Another options is to read the XML file with the System.Xml.Linq.XDocument.Load() or System.Xml.XmlDocument.Load() method, locate the User node, and iterate through each of the Attempts nodes (checking dates and adding the Distance, Duration and number of nodes per Place). Give it a go, and post here again if you have any specific issues.

nmaillet 97 Posting Whiz in Training

Take a look at the DateTime struct. .NET does not have a class/struct that only represents a date, so it'll use a DateTime with the time set to midnight. So you can use ToShortDateString(), ToLongDateString() or ToString(String).

nmaillet 97 Posting Whiz in Training

Ok, so you should start by modifying your GlobalVariable module to the base types, like this:

Module GlobalVariable
    Public DbCmd As DbCommand
    Public DbConn As DbConnection
    Public DbConnStr As String
    ...
End Module

Then, when you want to initialize (Form1_Load in your case), you would do it like this:

'You may want to make this global in case you want to make more Db classes later.
Dim factory As DbProviderFactory

Select Case sdatatype
    Case "SQLClient"
        DbConnStr = "..."
        factory = DbProviderFactories.GetFactory("System.Data.SqlClient")
    Case "OleDb"
        DbConnStr = "..."
        factory = DbProviderFactories.GetFactory("System.Data.OleDb")
    ...
End Select

DbConn = factory.CreateConnection()
DbConn.ConnectionString = DbConnStr

DbCmd = factory.CreateCommand()
...

Hope that's clear (syntax might be off slightly, but you should be able to get the idea). Let me know if you have more questions.

nmaillet 97 Posting Whiz in Training

Yeah, I'm not entirely sure what your getting at... it may be a disconnect between C# and VB.NET, as they do have some differences. So yeah, an example might help.

The whole idea though, just in case this is what you're refering to, is using DbDataAdapter and DbCommand as the type, not SqlDataAdapter, OleDbDataAdapter, etc. The only time where you would really need to use anything specific to the data source type, is the creation of the factory and the connection string.

nmaillet 97 Posting Whiz in Training

I can't believe I forgot about this... there's a DbProviderFactory class you can use. You get the DbProviderFactory by using either of following (C# sorry; I don't use VB.NET very much):

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
//or
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");

You then use the factory to create object like so:

DbDataAdapter adapter = factory.CreateDataAdapter();
DbCommand command = factory.CreateCommand();
//etc.

You can list all the available DbProviderFactorys using DbProviderFactories.GetFactoryClasses(), which gives you a DataTable of possibilities. Hope that helps.

nmaillet 97 Posting Whiz in Training

I'm curious, since I've never compared the two, what functions are giving you issues? Most classes that you need to work with should derive from the common namespace, so initialization may be different, but they could be passed fairly easily.

nmaillet 97 Posting Whiz in Training

This looks like VB.NET, not C#. In either case, neither directly inherits from the other; therefore, you can't cast between the two types. The do however, share a base class: System.Data.Common.DbConnection. You could, possibly, work with a DbConnection class directly. If there are specific functions implemented by the SqlConnection or OleDbConnection classes, you'd have to handle them specially.

nmaillet 97 Posting Whiz in Training

You need a lock around Dequeue as well. Include The if statement too, since you wouldn't want the Count changing before the Dequeue.

nmaillet 97 Posting Whiz in Training

Not that I've ever seen... and a quick search of Google only seems to turn up the same thing. Could you repost your Pipe and Pipe1 classes? Is there anywhere else that the Queue is referenced (double check all your code please)? If so, post it. It may help to see your changes, and ensure locking is done correctly. Also, an Enqueue() call that is properly locked could still throw the exception if other areas in your code don't lock on the same object properly.

nmaillet 97 Posting Whiz in Training

You need to make sure you have a lock around every Enqueue() and Dequeue() call. Any instance method/field/property of the Queue class is not thread safe. This also includes checking the Count property, without releasing the lock before an Enqueue() or Dequeue() (that depends on the Count).

nmaillet 97 Posting Whiz in Training

I think you have it backwards... The string should be the key in this case (i.e. SortedDictionary<string, int>), since there is a one-to-many relationship between the key and the value. If you did it with SortedDictionary<int, string> you could never have words that equal the same amount.

nmaillet 97 Posting Whiz in Training

You end a Thread by returning from the method specified in the Thread constructor.

nmaillet 97 Posting Whiz in Training

Are you getting an exception? That would be helpful to have.

At a quick glance, try adding the row oDetailRow to the table before calling SetParentRow().

nmaillet 97 Posting Whiz in Training

Were you going to ask that question?

nmaillet 97 Posting Whiz in Training

Queue's are not thread safe, so you should be using locks. Pretty sure I gave you an example in a previous post. Was there anything about it you didn't understand?

nmaillet 97 Posting Whiz in Training

There's also the Leave event; it's fired when the TextBox loses focus. Just keep in mind, that if you have an AcceptButton set and the user presses <Enter>, the Button.Click event will fire, but the Leave event will not (since it never really loses focus).

You may want to even look at the validation logic that WinForms supports. You can individually validate each control in the Leave event, and also call ValidateChildren on the Form to validate all controls in the Button.Click event. Not sure if this applies in your situation, but just an idea.

nmaillet 97 Posting Whiz in Training

You'll have to poke around the registry for that. You can use RegistryKey.OpenRemoteBaseKey to access a remote registry. There are some conditions to using it; they are discussed in the provided link.

There could be some security risks with this however. You could also install a client application/service on the remote machine which monitors the registry and provides that information back to the host machine via a TCP socket (or whatever protocol).

nmaillet 97 Posting Whiz in Training

There's no misunderstanding; you can't do it with the standard C# specification. There's a possibility that someone out there wrote an extension or tool to do this...

nmaillet 97 Posting Whiz in Training

Did you read the link I gave you? You still need the +, as that means one or more, and nothing should come after the \z. Also, you can't have any spaces in there, since that's a literal.

nmaillet 97 Posting Whiz in Training

What do you mean by unknown errors? Are you getting an exception, or is it giving you unexpected results? Give some more detail. Also, an example of your test input.

nmaillet 97 Posting Whiz in Training

Did you try:

Something<K, V>[] s = new Something<K, V>[size];

That's assuming the other class is generic, and has K and V defined. If not, you need to explicitly declare it, like so:

Something<string, int>[] s = new Something<string, int>[size];
nmaillet 97 Posting Whiz in Training

The sender parameter gives you the reference to the particular ComboBox that fired the event. For example:

private void buildingComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox comboxBox = sender as ComboBox;
    if (comboBox != null)
    {
        ...
    }
}
nmaillet 97 Posting Whiz in Training

See here. Basically, you subscribe to an event like so:

comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;

and you can unsubscribe from an event like so:

comboBox.SelectedIndexChanged -= comboBox_SelectedIndexChanged;
nmaillet 97 Posting Whiz in Training

Oh yeah, it is...

You could either use [a-zA-Z], or [a-z] with RegexOptions.IgnoreCase.

nmaillet 97 Posting Whiz in Training

Not that I am aware of. Like I said, using only works with namespaces (also aliases of namespaces and classes, but still not what you want). Maybe do a search for extensions for your IDE that do this (or make your own).

nmaillet 97 Posting Whiz in Training

Is this where RunSQL() should go?

Yup.

How does it determine if the progress has changed?

You use the BackgroundWorker.ReportProgress() method; that is, you explicitly update progress if you wish. You can get the instance of the BackgroundWorker by using the sender parameter. It is important to note that DoWork is run on a separate thread, but ProgressChanged and RunWorkerCompleted both run on the UI thread (which allows you to update controls and such).

How does it determine if the process is completed?

The work is completed when the DoWork delegate returns (i.e. bw_DoWork returns).

nmaillet 97 Posting Whiz in Training

I don't get what you're asking...

nmaillet 97 Posting Whiz in Training

C# doesn't work this way. using is only intended to have the compiler imply the namespace of a class. IMO, this would make your code difficult to read, as another programmer would have to search for the particular class the method is defined in.

nmaillet 97 Posting Whiz in Training

When you use regular expressions, you must specify where it occurs in the string. To specify the whole string, you use \A at the beginning and \z at the end of the expression (case-sensitive). I had no idea [:lower:] would work in C#, however you can also use \w+ which matches any word character; then you wouln't have to use ToLower(). Note that regex character escapes are different than C# character escapes. For instance, you would either use:

"\\A\\w+\\z"

or

@"\A\w+\z"

since @ tells the compiler to ignore character escape sequences. See Regular Expression Language - Quick Reference for more info.

nmaillet 97 Posting Whiz in Training

You're comparing to variables empName and Quit. I don't see a variable called Quit declared anywhere. If you wanted to compare it to the string "Quit", then it would look like this:

if (empName != "Quit")
{
    ...
}

Note that it is case-sensitive. If you want to ignore case, you can use the String.Equals() method that explicitly specifics a StringComparison.

nmaillet 97 Posting Whiz in Training

Give it a try.

Hint: Use a for-loop.

nmaillet 97 Posting Whiz in Training

Haven't we already gone through this. Why are you using nested types? And why are you using structs? Structs are fine for a small number of variables, but as it grows, it starts taking up alot of valuable space on the stack. The heap is there for a reason, to hold large amounts of data. And in either case, string is still a class which allocates its character arrays on the heap. One common recommendation I keep hearing is that a struct should be 16 bytes or under. On most 32-bit architectures, and string is going to be a 4 byte pointer, that's 4 strings in a struct (2 on most 64-bit architectures).

nmaillet 97 Posting Whiz in Training

You can add an ' to the char array by using '\'', if that's what you're asking (see here).

As for your program, you only created one additional thread, then never really did anything with the main thread. Here's a quick example of how a threaded application could look:

static void Main(string[] args)
{
    //Initialize threads.
    Thread thread1 = new Thread(SomeMethod1);
    Thread thread2 = new Thread(SomeMethod2);
    Thread thread3 = new Thread(SomeMethod3);

    //Start threads.
    thread1.Start();
    thread2.Start();
    thread3.Start();

    //Wait for threads to finish.
    thread1.Join();
    thread2.Join();
    thread3.Join();
}

So, I'm assuming you want Filter2 to run concurrently with Filter1. You simply called the Run() method in Filter2, which doesn't cause a new thread to be created. Generally, with threads you also wouldn't want to do this. It would be very inefficient to create a new thread to process each iteration of your current thread, and could also lead to concurrency issues, since they would be working with the same data source.

Here's a quick example of what you could do in your situation:

class Program
{
    static Queue<string> q1;
    static Queue<string> q2;

    static Thread thread1;
    static Thread thread2;

    static void Main(string[] args)
    {
        q1 = new Queue<string>();
        q2 = new Queue<string>();

        thread1 = new Thread(Filter1);
        thread2 = new Thread(Filter2);

        thread1.Start();
        thread2.Start();

        thread1.Join();
        thread2.Join();

        Console.WriteLine("Done!");
        Console.ReadKey(true);
    }

    static void Filter1()
    {
        for (int i = 0; i < 20; i++)
        {
            string str = i.ToString();
            //Queues are not thread safe, so take a lock.
            lock (q1)
            {
                q1.Enqueue(str);
            } …
nmaillet 97 Posting Whiz in Training

Those aren't really errors (except for the last line), they just say that a PDB file couldn't be found for the DLLs, which is just a file that contains debug information for the particular libraries.

Could you post the text in the input file you are using?

Also, PlayGuess() and GetLetter() are supposed to return int and char respectively, but neither do.

nmaillet 97 Posting Whiz in Training

Ok, a few things:

  1. When calling a function, you do not need to define the type of the parameters. For insatnce, on line 42, you would use PlayGuess(solution);.
  2. On line 65, you try to declare a variable called MAXGUESSES. This is alreay defined on line 3. The compiler uses #define to find and replace all instances of the identifier (in this case MAXGUESSES) with the value (although you can define "functions" as well). So the compiler would change line 65 to int 6 = 6;, which doesn't make sense. Since MAXGUESSES is already defined as 6, remove line 65.
  3. On line 69, guess isn't defined in the scope of the function.
  4. On line 94/95, you trying to redeclare the function parameters.