mcriscolo 47 Posting Whiz in Training

It appears your data is actually an array (or list) of items; you can tell due to the square brackets:

"PSQL": [
...
]

So, your structure should probably look something like this:

Dictionary<string, List<Dictionary<string, string>>>

That is, a dictionary with a string key and a list of dictionary (string, string) items. I used the Newtonsoft JSON package.

Hope this helps!

mcriscolo 47 Posting Whiz in Training

Are you reading the database to get the current states of the seats before the code above is called? You would need to have a list of the seats that have already been taken. Then after line 4 in your code sample, you could check the user's selection against that list and determine if the seat the user selected is already taken and issue an alert.

Or, you could insert a read of the database after line 4 to determine the same thing. But if you were to gather the list up-front, it would be one call to the database instead of potentially many.

mcriscolo 47 Posting Whiz in Training

Hi,

A couple of things to look at:

1 - In your function "MStudent" - what are you doing with the return value from this? Hint - check out how you are calling it.
2 - In the function "CalcAvrg" - take a closer look at how you are accessing the items in the array. One dimension is for each student and the other is for each grade for a particular student.

-Mike

mcriscolo 47 Posting Whiz in Training

I was suspecting the same thing. Unless I'm missing something, in "getBook", you are re-using the "resultSet" variable, assigning it new results from getting the data on a single book. When you return back to the loop in "getAllBooks()", it's referencing the same "resultSet" variable, which a) contains the results from a different query, and b) is past "end-of-data" which is why your loop only executes once.

Be sure to use different instance variables if you're going to be managing multiple result sets at the same time.

mcriscolo 47 Posting Whiz in Training

Check lines 68-70 - the test condition is "true" (that is, it will always be "true") - do you really want that? Shouldn't you have a condition you can test to see if you want to keep looping?

Line 110 - what happens to the lines after the "continue" statement? Consider re-arranging the lines so you add to your counters, but perhaps "continue" when your exit condition is met.

mcriscolo 47 Posting Whiz in Training

Check out this part of your code:

...
bool radioButton1_CheckedChanged = true;
bool convertToCelsius_CheckChanged = true;

if (radioButton1_CheckedChanged == true)
{
    convToF(double.Parse(Current.Text)); 
...

Won't this always be the case...? Should the first 2 statements be moved elsewhere?

mcriscolo 47 Posting Whiz in Training

OK, I didn't see a class declaration in the post; perhaps it got left out.

A while loop loops while the condition in the parentheses is true. So, "while(1)" will loop forever. However, in the example I posted, if the user types a "q" or "Q", it will call "System.exit(0)", and end the program. You can have code like this, just as long as you be sure to break out of the loop somehow, either using the "break" statement:

while(1)
{
    if (a.equalsIgnoreCase("q"))
    {
        break;
    }
}

// execution will continue here..

or, as was done in my previous post, calling "System.exit(0)".

mcriscolo 47 Posting Whiz in Training

I don't see a class declaration at the top of the code. It should be just before your first curly brace ({) at the top. Something like:

public class Teller

When I put that in, the code ran.

You really should have one outer loop that takes in the user's input, then compares it to your menu choices. In your example, you show the choices, get the user's choice, then after the operation (in this case, a balance inquiry), you enter a loop to get the user's next choice. With one big loop running the entire program, when you are done with an operation (balance, deposit, etc.), you just go back to the top of the loop and get the next choice. Something like:

// Do this until the user presses "q" or "Q"
while (1)
{
	// Get choice
	String a =(JOptionPane.showInputDialog(null, "Automatic Teller Machine\n [B] Balance Inquiry\n [D]Deposit\n [W] Withdrawal\n [Q] Quit\n Select you Options:  ","Automatic Teller Machine",JOptionPane.PLAIN_MESSAGE));

	// Exit?
	if(a.equalsIgnoreCase("q"))
	{
                // Do exit stuff...
		System.exit(0);
	}

	// Balance
	if(a.equalsIgnoreCase("b"))
	{
		// Do balance stuff...
	}

	// Deposit
	if(a.equalsIgnoreCase("d"))
	{
		// Do deposit stuff...
	}

//end of main loop
}
mcriscolo 47 Posting Whiz in Training
mcriscolo 47 Posting Whiz in Training

Look at the last part of your long "if" statement:

else if(side1==side2 || side2==side3 || side1=side3) // code error here

Is something missing?

mcriscolo 47 Posting Whiz in Training

Ah, but they don't have the same *values* - you are constructing arrays of *objects*. Now, the objects may contain the same values, but that's it. Each object is different. You can either change over and make the arrays out of integers, or provide a comparison function that, when you go to compare the arrays, checks each element and compares the values contained in each object at each position.

Your commented-out function in the first chunk of code was almost correct - if you change that to call your "getInt()" property on each object in the arrays, you should have it.

mcriscolo 47 Posting Whiz in Training

You can't declare an instance of a variable more than once. That's what's happening. Try this:

// Secondary.h
#ifndef SECONDARY_H
#define SECONDARY_H

#include <iostream>
using namespace std;
#include <string.h>
extern string HelloWorld;

void HelloEarth();

#endif

Change Main.cpp and Secondary.cpp to include "Secondary.h", remove the function declaration of "HelloEarth" from Main.h, and remove the include for Main.h in Secondary.cpp. This allows you to declare the variable once in Main.h, and reference it from other places.

Chuckleluck commented: Got straight to the point and showed me what was wrong with my code +2
mcriscolo 47 Posting Whiz in Training

In Panel.java, as the new last line of the constructor, type this:

ingredientScroll.setPreferredSize(new Dimension(200, 100));

Of course, you may want to interrogate the parent (Frame) to get the dimensions and set the size of the JScrollPane appropriately.

mcriscolo 47 Posting Whiz in Training

First, use code tags when posting - it makes reading the code easier.

1) As you've coded it, yes - kind of. That is, you create each object in main(), then pass each off to a distinct thread. However, there's nothing stopping you from, after starting the thread, from modifying the data in, say "pMiscData1", since, of course, you've passed a pointer to the thread function, and the thread function (short as it is - I understand this is an example) doesn't copy the data from the object into a thread-local variable. If you had a long-running thread that was working on the data, statements further in main() could change the data in pMiscData1 and affect what is going on in the thread. But, as you've coded it, there's no way that operations in the first thread can affect the data being worked on in the second - that's good.

2) Nothing. The OS will handle that.

3) Yes. The universe would cease to exist if that did not happen.

4) As far as I can tell without running it, yes, it appears so.

What *is* going wrong with your program? That is, what symptoms is it exhibiting? Just as a guess, are you hanging at one of the WaitForSingleObject calls? If so, see this link about threads that run so fast they may not properly set the thread handle (see the "Remarks" section).

Hope this helps!

mcriscolo 47 Posting Whiz in Training

Generally speaking, it should be a loop in main() that is outside your current loop. That is, you enter the main loop to get the user's choice (1= reserve, 0 = exit). If the user enters a 1, you then get the input for the row and column and check the availability. If, when you get to the top of the (new) outer loop, the number of reserved seats (i.e., size of your "reservedSeats" array) equals the total number of seats, you can just exit.

mcriscolo 47 Posting Whiz in Training

When you say "registry", do you mean the actual registry, or the certificate store (accessed by running "mmc", then from the "File" menu, selecting "Add/Remove Snap-in...", then selecting the "Certificates" snap-in, etc.)? If the latter, see below...

It's been a bit, but I used this code in the past to pick a certificate out of the certificate store:

using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
...
X509Store store = new X509Store(StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509CertificateCollection certs = store.Certificates.Find(X509FindType.FindSubjectByName, "XXX", true);

"certs" will contain a list of certificates that match the find type, in this case, if the subject in the certificate is "XXX".

To extract the first certificate in the collection, you can do:

X509Certificate2 cert = ((X509Certificate2)certs[0]);

This worked on Windows Server 2003. Also, you can change where in the certificate store you're looking by changing the "StoreLocation" when creating the "store" variable.

Good luck!

mcriscolo 47 Posting Whiz in Training

Your code is "converting" the object at element position 0 (an instance of MyDataType) to a string - but since it's an object, you are getting the type name.

I'm assuming you want "nut" to appear in the text box. If so, the code that does this is:

textBox1->AppendText(arrayObject[0]->name);

If you add a "toString" method to your "MyDataType" class, you could change your code to:

textBox1->AppendText(arrayObject[0]->toString());

Assuming, of course, that your "toString()" method returns a string with the data contained in the "^name" property.

mcriscolo 47 Posting Whiz in Training

You are not giving the webBrowser component enough time to load, before you try to set the properties of the HTML document. Try using another button, like this:

private void button1_Click(object sender, EventArgs e)
{
    // lets the browser control load up
    webBrowser1.Navigate(" http://www.httpsurf.com/ ");
}

private void button2_Click(object sender, EventArgs e)
{
    // Now, all of the info should now be in the document and ready to go
    webBrowser1.Document.GetElementById("url").InnerText = textBox1.Text;
    webBrowser1.Document.GetElementById("go").InvokeMember("Click");
}
mcriscolo 47 Posting Whiz in Training

You're almost there...

byte[] fileStream = File.ReadAllBytes(Path);
string first = Encoding.UTF8.GetString(fileStream, 0, 70);
mcriscolo 47 Posting Whiz in Training

Here's some example code from MSDN:

http://msdn.microsoft.com/en-us/library/aa363634(VS.85).aspx

mcriscolo 47 Posting Whiz in Training

Sounds like you need something like a "MultiMap". Check out this link.

mcriscolo 47 Posting Whiz in Training

Assuming the text "-- Select Date --" is the first item in the box, then this will work:

comboBox1.SelectedIndex = 0;

Note that even when yo do this in code, it will cause the "SelectedIndexChanged" event to fire for the combo box.

mcriscolo 47 Posting Whiz in Training

Slight change, but you were close:

string sSQL = "SELECT * FROM Tasks WHERE Notes = '" + No + "'";
res = stmt->executeQuery(sSQL);

Of course, this assumes that "Notes" in your database is a character column. If it is a numeric column, then leave the single-ticks out of the SQL string.

mcriscolo 47 Posting Whiz in Training

On line 61, you are defining a local version of "VideoTransmit" that eclipses the one you declared on line 23. Just state:

at = new VideoTransmit(new MediaLocator(sourcevideo),
                ipvideo,
                portvideo);

and it will use the variable you declared on line 23.

mcriscolo 47 Posting Whiz in Training

How else would you? I mean, are you looking to load each "Student" into some sort of object, and then be able to say something like:

if (firstPerson.Age == secondPerson.Age)
{
    ...
}

If so, you will still have to process the XML to load the objects.

mcriscolo 47 Posting Whiz in Training

Have you seen this article? (Not sure what the goofy photos are all about). Seems to cover some of the basic aspects of working with table adapters. It's in VB.NET, but should be easily translated to C#.

mcriscolo 47 Posting Whiz in Training

Take it in small chunks. First, concentrate on question 5a. You are given the code that calls the function "inputAndValidate". The assignment calls for you to write this function.

The function needs to take in three parameters. The assignment says that these should be passed in as reference parameters. The reason for this is that if you pass them by value, when you get inside the "inputAndValidate" function and assign values to the variables, when you leave, the values you just assigned will "go away". The point of this part of the assignment is to teach you how to pass variables into a function so that you can assign values to them and get them back.

See this article on passing variables by reference: http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/

Just work on getting that part of the assignment done, then, you can tackle the next part. The sample program that was given will print out the values of the variables once you get back from the function.

mcriscolo 47 Posting Whiz in Training

You are using the VB Power Packs library. Apparently, when using the "ShapeContainer", there is a stipulation that you must override the "Dispose" method of the form to explicitly dispose of any objects loaded into a "ShapeContainer" object.

See this link:

http://social.msdn.microsoft.com/Forums/en/vbpowerpacks/thread/cb89a159-c989-470f-b74f-df3f61b9dedd

mcriscolo 47 Posting Whiz in Training

One last thing - please post the code for the Windows Forms Designer-generated code. The file should be something list "agWebBrowser.Designer.cs". The code you've posted so far doesn't shed any light on "ShapeContainer".

mcriscolo 47 Posting Whiz in Training

"~" in Windows won't work (unless you are doing this in Mono, on Linux?)

In the framework, there is an enumeration of "special folders", the items like "My Documents", "MyPictures", etc. You use it like this:

Console.WriteLine("GetFolderPath: {0}",               Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

Check out the doc - there may be something here for you to use, when you don't know the structure of the the target computer you are going to install your software onto.

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

mcriscolo 47 Posting Whiz in Training

Well, that's because you can only send one "piece" of data through when you start the drag. May be a bit of overkill, but can you do this in "button1_MouseDown":

button1.DoDragDrop(button1, DragDropEffects.Copy);

Then, in "button2_DragDrop":

Button oButton = (Button)(e.Data.GetData(typeof(Button)));

Now, you have a reference to button1, and all of the props within it.

mcriscolo 47 Posting Whiz in Training

When you specify a path in a string in code that contains the backslash character, you must "escape" it. So, if you want to save a file named "gunk.txt" to the root of the C: drive, you would have to type:

string sPath = "C:\\gunk.txt";

That will be suitable for using in a function that takes a file/path string.

mcriscolo 47 Posting Whiz in Training

Line 19: what's that for? Again, since you are using the index of "4", that's past the end of the array (an array declared "char board[4,4]" will have indexes of 0..3 and 0..3, respectively.

Also, line 7 should be:

cout<<board[i][3]<<endl;

The extra "cout" would cause problems.

mcriscolo 47 Posting Whiz in Training

OK, can you post the code snip from your main form (or wherever you call your secondary form) along with the code for the secondary form (all of it)? Just by nature of the error statement:

************** Exception Text **************
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ShapeContainer'.

You're trying to access something that's been blown away already.

mcriscolo 47 Posting Whiz in Training

Sounds like a plan. One class per command keeps it straightforward. Good luck!

mcriscolo 47 Posting Whiz in Training

From what perspective are you closing the forms? That is, are you trying to close all of the forms from the main form, or are you just trying to close a secondary form when you are done with it? As in, you open the second form, do some stuff, then press a button or object to close the form.

Since you state you are getting errors saying you can't access a disposed object, you need to check to ensure you are not trying to do something with a form or items on a form after you've destroyed it.

Most likely, I think that you may be trying to access a piece of data on the secondary form after you've called "Close" or "Dispose" on it.

mcriscolo 47 Posting Whiz in Training

Couple of things....

1) your arrays/indexes are not in sync. Your board is "char[7,12]", meaning the indexes go from 0..6 and 0..11, respectively. Look at some of your loops - you have them checking for "j<13", meaning "j" can go up to 12, which is outside the bounds of the array. I was getting error messages when I ran the code about the stack being corrupt.

2) Your "for" loop for drawing the dashes (on your odd lines) was inside the "if" statement checking for the even lines. Once I properly indented the code it jumped right out at me. Like this:

void setgameboard(char board[7][12])
{
    int i,j,k;
     for (i=0;i<7;i++)
     {//row loop
         if (i==0||i==2||i==4||i==6)
         { //if row isnt barrier
            for (j=0;j<13;j++)
             {//start row that isnt barrier
	         if(j==0||j==4||j==8||j==12)
	         {
		     board [i][j]='O';
	         } //is open space for token
                 if(j==1||j==3||j==5||j==7||j==9||j==11)
	         {
		     board[i][j]=' ';
	         }//is space
                 if(j==2||j==6||j==10)
	         {
		     board[i][j]='|';
	         }//is divider
             }  //close if row isnt barrier loop
             if (i==1||i==3|| i==5)
	     {
	         for (k=0;k<13;k++)
	         {
		     board[i][k]='-';
	         }
             }          //if row is barrier            
        } //close column loop
    }//close row loop
}

Lines 23-29 should be moved below line 30, to be out of the "if" statement on line 6.

mcriscolo 47 Posting Whiz in Training

Your deletion routine is not correct - you are leaving the pointer from the previous entry in the list dangling. Example: if you enter the values 3, 2, 1 in your list, you will have a list in order from head of 1 - 2 - 3.

When you go to remove the even numbers, you will start at 1 (head) and see that it doesn't need to be removed, so you move to 2. That should be removed. You set "step" to point to the 3, then remove the 2 - but the pointer from 1 - it's still pointing to where 2 was (it has an address in it, though it is invalid).

One way to do it is to have a "trailing" pointer (call it "prev") and set it to NULL. Each time you increment "step" WITHOUT deleting a node, you set "prev" equal to "step" BEFORE you increment "step". Then in the deletion logic, you set "prev->next" equal to "step->next", so the pointer from the previous node now points to the node after the one just deleted.

mcriscolo 47 Posting Whiz in Training

You can trap the "ClientSizeChanged" event on the RichTextBox. In both cases (when the scrollbar appears and disappears), this event will fire.

Momerath commented: My example came from your statement so you deserve credit +3
mcriscolo 47 Posting Whiz in Training

The assignment seems straightforward. Do you have some specific questions about it?

mcriscolo 47 Posting Whiz in Training

What was not satisfactory about it? I looked over the code, and it seems to accomplish what you state in your post.

The other alternative is to trap what row in the ListView the user clicked, then provide a DatePicker and/or a TextBox and a "Commit" button that you fill with the data from the clicked row. Let the user edit the data, and when they press the button, put the edited data back into the ListView.

Or, you could switch to a DataGridView. It's a bit more complex than a ListView, but it's easier to set up editing of the cells. When you set up the columns in the DataGridView, you can specify if they are ReadOnly - thereby meeting your criteria of only some of the columns being editable.

mcriscolo 47 Posting Whiz in Training

Not at all. However, when you talk about "serializing", I'm assuming that you mean a good chunk of the discussion we've had in this thread, not necessarily the .NET version of serialization. First, I'm not as familiar with that, as I've stated earlier, but I feel certain that you can do that over a socket (any stream, for that matter).

The approach I've used is a custom serialization process. I wouldn't be able to use .NET serialization, since I have UNIX processes as some of the endpoints, and didn't want to have to "invent" the serializer/deserializer on that platform, or perhaps, attempt to use Mono or something like that (OK, the real truth is the UNIX side of the software was written before .NET was even invented). It works for me, and should work in most applications where you're having to send data over sockets to various processes.

As far as size is concerned, you'll have to do some tests to see how large your objects are and determine if that's the best approach. However, how else would you do it? If you have to get the data to a process on another machine, it's going over the network somehow - either directly, via your soon-to-be-developed solution, or via FTP/SCP/Samba/E-Mail - i.e., file transfer - but one way or another, the data's got to get there.

Start small, run some tests and see what results you get. Hopefully, you can gather enough data to help make a …

mcriscolo 47 Posting Whiz in Training

All valid concerns. However, at some point, you'll have to get started with things :). I don't think there's a single system I've ever developed where I didn't want to go back and redo some aspect of it after the fact. That "hindsight is 20-20" thing is very prevalent in software development!

All that said, I would suggest going with a more simplistic approach on the messages, rather than a message that would have a whole lot of data in it - and you may only be using a portion of it. That is, I'd treat the network as a precious resource - and only send over data that you know you are going to use. Some may argue that today's networks have tons of bandwidth - and they do - but if you design your software like that you almost always run into trouble later down the road.

Yes, a lot of smaller messages may be more of a management issue, but if you pile everything into one message - and then have to make changes to it - you risk possibly breaking code that was dependent on an earlier version of that message.

Even if you have to send multiple small messages to accomplish a task - that may be better from an "atomicity" (is that a word?) standpoint than sending a larger data package that you have to pick through. Perhaps at a later time, if you find that for a certain transaction, you …

mcriscolo 47 Posting Whiz in Training

Alan,

The byte array has its own length. This works:

for (int i = 0; i < baData.Length; i++)
{
    byte bByte = baData[i];
    // Do something with "bByte"
}

but so does this:

foreach (byte bByte in baData)
{
    // do something with bByte
}

It just depends if you need the location in the array; if so, then the first approach is better.

Use the "Length" property on the byte arrays to ensure you don't try to grab an element that's not there.

but I am getting error statements that indicate that the program doesn't know where the arrays are

Are you talking about using the "baData" and "baAnswer" arrays in another part of your program? If so, you need to make sure that from a scoping standpoint, you can "see" those variables. In other words, let's say you have another class, called "Analyze", that operates on the two arrays. If you just declare the class "Analyze", like this:

public class Analyze
{
    public void doAnalysis()
    {
        for (int i = 0; i < baData.Length; i++)
        {
            byte bByte = baData[i];
            // Do something with "bByte"
        }
    }
}

That won't work - the "Analyze" class doesn't "know" about the byte array in the "Form1" class. You would have to do something like this:

public class Analyze
{
    public void doAnalysis(byte[] testArray)
    {
        for (int i = 0; i < testArray.Length; i++)
        {
            byte bByte = testArray[i];
            // Do something with "bByte" …
mcriscolo 47 Posting Whiz in Training

Here's the code. You will have to put a form up with the names for the textboxes, buttons, etc. to match the names in the code, as well as the events.

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace TestShell
{
    public partial class Form1 : Form
    {
        private byte[] baData;
        private byte[] baAnswer;

        public Form1()
        {
            InitializeComponent();
        }

        private void cmdDataBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.FileName.Length > 0)
                {
                    txtDataFile.Text = ofd.FileName;
                }
            }
        }

        private void cmdAnswerBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.FileName.Length > 0)
                {
                    txtAnswerFile.Text = ofd.FileName;
                }
            }
        }

        private void cmdTest_Click(object sender, EventArgs e)
        {
            if (txtAnswerFile.Text.Length == 0 || txtDataFile.Text.Length == 0)
                return;

            // Load up the byte arrays with the data from the files
            try
            {
                baData = File.ReadAllBytes(txtDataFile.Text);
                baAnswer = File.ReadAllBytes(txtAnswerFile.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR");
                return;
            }

            // Run the test with the 2 byte arrays
        }
    }
}

You'll need:

3 Buttons (named "cmdDataBrowse", "cmdAnswerBrowse" and "cmdTest")
2 Text Boxes (named "txtDataFile" and "txtAnswerFile")

mcriscolo 47 Posting Whiz in Training
mcriscolo 47 Posting Whiz in Training

Well, we have a strict policy that new messages go at the end of the list. I don't know how many folks you'll have modding your code, but I'd try to go with something like that.

Strings - you really have to specify a length for each one in your classes. Think of a pure C/C++ struct - you *could* use "char *", but really, the structs will have a field and a defined length, like "char myString[24]".

In C#, you just need to set sizes for each string. I use constants at the top of each class, and in the encode/decode methods, use those constants to set the size of the strings as you put them on and take them off the wire.

mcriscolo 47 Posting Whiz in Training

That's exactly how I do it. I actually have a class that just has the enums in it. We have just over a hundred different commands, so yeah, just trying to remember the IDs would be a hassle.

mcriscolo 47 Posting Whiz in Training

Try this one. I used 7-Zip to zip it, but normally you shouldn't have trouble with it.

mcriscolo 47 Posting Whiz in Training

Is the data in your file actual binary data, or is it hex strings?

I've attached a small shell program that will let you browse for 2 files and convert the contents of the files to a byte array. It assumes the data in the file is binary format (actually, it just reads in the bytes of the supplied file). However, if your data files are text files of hex strings, then the load of the data will not occur properly.

If using hex strings, you will have to read in the data 2 characters at a time and convert each 2-char sequence to a byte value, like this:

string sData = "F2";
byte bData = null;
if (!byte.TryParse(sData, System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out bData))
{
    // Error converting byte data
}

Hope this helps!