Tyster 17 Light Poster

Hi Folks,

I have a simple app (coded in VB 2008 Express Edition) that uses an SQL Server database (in .mdf format) that works fine on my own machine. I created the database in SQL Server on this machine. I added the DB as a data source and it works fine. But when packaged this app (ClickOnce) and installed this app on a different machine the installer tries to download MS SQL Server Express. Obviously this is because SQL Server is a prerequisite and is not installed on the other machine. But just as obvious is the fact that the download will take a long time to complete before my code even starts installing.

My question is this: Is there an SQL Server reference (using Add Reference...) that I can add to avoid this? I suspect the application just needs one or two DLL files from SQL Server. Downloading the whole product seems like overkill. Is there a way I can included the needed files in my app to avoid this long download process?

If there is a way to do this does anyone know what files or references I need to add? I've been doing a lot of searches on Google, etc... looking for a way to avoid this download and haven't found anything (so far!)

Many Thanks for any suggestions!

Tyster

Unhnd_Exception commented: Nice job responding back. -2
Tyster 17 Light Poster

Thanks, dxider.... I wrote a new function that allowed me to pass the data I needed to MainForm and it works fine. I appreciate your input very much!

Many Thanks!!!

Tyster

Tyster 17 Light Poster

Hello Everyone,

I have what I hope will be a simple VB question:

I am building an app with multiple forms. It has a MainForm, which is the main interface, and several sub-forms that are started using buttons on the MainForm.

The MainForm Load method has some code that runs each time the form starts. This code populates various fields in the MainForm and it works fine. When I click a button a sub-form loads. I update some data there and then close or hide this form.

My problem is this: When I close or hide the sub-form and show the MainForm again, is it possible to have the MainForm Load method 're-run', or execute again? I presume I might be able to add something to the sub-form "Back" button event that runs when I hide or close the sub-form. I've tried a few variations of "frmMainForm.this" and "frmMainForm.that" with no luck.

I want to do this because the MainForm Load code will pick up the changes I made in the sub-form and display the updated data in the text fields of the MainForm.

Any advice is greatly appreciated. Many Thanks!

Tyster

Tyster 17 Light Poster

Observe:

const int setSize(15);

int someInt;

someInt = setSize;

In this little snippet, Line 5 is an assignment statement. For an assignment statement to function properly, the assignment operator (" operator = ") must be defined for the dataType. This snippet works because the built-in dataType int has the assignment operator already defined for it.

In your particular case, you are trying to assign the updated value of Rational c to Rational x. However, the system doesn't know how to perform this assignment because you haven't told it how to do it.

Read this.

Thx, Fbody. I see what you're saying and I'll research this more to see if I can figure out how to do that. Many Thanks!

Tyster

Tyster 17 Light Poster

There are several issues with this, but the biggest is that your class doesn't have an assignment operator defined. As a result, the compiler doesn't know how to assign the new value of c (after adding d to it) to x.

Also, you may want to find an arithmetic textbook and review how to add fractions properly. This algorithm isn't even close.

Thanks Fbody,

Yeah, I know about the calculation problem (I need to find the LCD first). Haven't gotten around to fixing that yet. But you mention that "but the biggest (problem) is that your class doesn't have an assignment operator defined". I',m not sure I understand what that means or how it would be implemented. Can you please offer clarification?

Many Thanks!

Tyster

Tyster 17 Light Poster

Hi folks,

I'm quite new to C++ and I'm getting an exception I don't understand.

I have a class named 'Rational' that performs calculations on fractions. It has a default constructor as follows...

//In Rational.h

public:

   Rational(int num = 1, int denom = 2); //Default constructor
   void addition(Rational);
   void subtraction(Rational);
   void multiplication(Rational);
   void division(Rational);
   //other functions


private:

    int numerator;
    int denominator;



//In Rational.cpp, constructor

Rational::Rational(int x, int y)
{
	numerator = x;
	denominator = y;

}

The problem I am having is when I call the addition function in main(). First I create 3 Rational objects and then I call the addition function, as follows...

int main()
{
   Rational c( 2, 6 ), d( 7, 8 ), x; // creates three rational objects 

   x = c.addition( d ); // adds object c and d; sets the value to x


...


The addition function in Rational.cpp is:

//Add 2 Rational numbers
void Rational::addition(Rational f)
{
   //Add numerators and denominators
   numerator += f.GetNumerator();  //accessor defined elsewhere in this class
   denominator += f.GetDenominator();  //GetNumerator defined elsewhere in this class
}

When the addition function is called I get the following error message from gcc...

"16 E:\CSC_134_Cpp\Lab5\Rational_Number\Rational_Number\Rational_Driver.cpp no match for 'operator=' in 'x = (&c)->Rational::addition(Rational(((const Rational&)((const Rational*)(&d)))))' "


It looks like it thinks the object I pass in the addition function ('d') should be a const or a reference but I tried that and it didn't work (but maybe I did it wrong). I admit the …

Tyster 17 Light Poster

Hello everyone,


I am looking for open source message queue implementation in Java. Does anyone know where can I find a 100% pure Java implementation of message queue with basic features? It is better an implementation which does not rely on other components and can be used as a utility class.


Thanks in advance,
George

Hi George,

I work in messaging software (MQ and SIB) and I have a VERY simple messaging simulation I wrote for education purposes that you might find helpful. Its a simple set os classes that uses an ArrayList as a 'queue' and main() starts 2 threads, a Producer and a Consumer, that put and get 'messages' from the 'queue'. Each 'message' is actually just a random string, but it works. Each thread uses re-entrant locks for 'queue' access. I can send it to you if you like. Keep in mind this stuff is REALLY simple, but it does demonstrate the concept.

Tyster

Tyster 17 Light Poster

stephen84... Thanks for the suggestion. It turns out the code I have was correct... I used the exist() method as you suggested and it returned true. Turns out that the real source of the exception I was getting was my incorrect use of XPath syntax (right after the code I pasted above). I've corrected that and all is well.

Thanks again and have a great Christmas!

...Tyster

Tyster 17 Light Poster

I try this part of your program with my xml-file

//and my .... continuation
        Element element = doc.getDocumentElement();
        System.out.println(element.getTagName());
// is OK

further code related to

XPathFactory xpfactory = XPathFactory.newInstance();
        XPath path = xpfactory.newXPath();
//....

you not posted, also i don't know what is inside "Bank.xml"
I can't answer, insufficient info.

Thanks for your help. I think my document and xpath code is OK. I think the problem is that my XML file is not (cannot) be found by the parser. I suspect the real problem is in this part of my code...

//Find the XML file and start parsing 
 String fName = "C:\\Bank.xml";      // Windows path
 File f = new File(fName);
 Document doc = builder.parse(f);   // Parsing

I'm sure I'm making a silly mistake. The file is located in C:\Bank.xml Is my syntax wrong? I'm not sure I understand why the file would not be found (see the exception in my forst post).

Any advice is greatly appreciated!

...Tyster

Tyster 17 Light Poster

NOTE: The classes I posted above are NOT complete, but I think they have what you are looking for.

Cheers!

Tyster

Tyster 17 Light Poster

I have something that might help... When you have an array list of objects, each object has instance variable values. The idea is to extract and print the values of each variable in each object. The way you are doing it now prints the OBJECT (and its memory address, I think), rather than the variable values.

To solve this have a look at the program below. It's a program that sets and gets student grades, names, and student Id's and each student object is stored in an Array List. I wrote it to do exactly what you want (I think!). You need 2 classes... the main() method class to provide values for the variables, and a second class that has Getter methods, where each get() method gets the value you want. You print the values using the get() methods.

Here's the main() class...

public class GradeTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		ArrayList<Grader> GraderList = new ArrayList<Grader>();
		
		Scanner in = new Scanner(System.in);
		
		System.out.println("Enter the number of students: ");
		String numStudents = in.next(); // Store the number of students
		int numStu = Integer.valueOf(numStudents); //Convert String to int
		
		System.out.println("Enter the Assignment name: ");
		String assignName = in.next(); // Store the assignment name
		
		for(int i = 0; i < numStu; i++){
					
			System.out.println("Enter the student name: ");
			String studentName = in.next(); // Store the student name
					
			System.out.println("Enter the student ID: ");
			String studentID = in.next(); // Store the student ID
						
			System.out.println("Enter the student score: "); …
Tyster 17 Light Poster

That's a fairly advanced project for someone new to Java. But I do have a suggestion to help get you going...

It sounds like this app requires a GUI. I would suggest you build the GUI first... forget about the logic for the dice, etc for now. First build the GUI with the buttons you need. That alone will probably get you half credit.

Once you have the GUI you will, for the most part, have much of your logic (including dice logic) in your Action Listener code. When someone clicks a button the Action Listener code will be called. You can find out more about Action Listeners here...

http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html

I also suggest using the Math.random method for your dice rolls.

Hope this helps!

Tyster

Tyster 17 Light Poster

Neil... You have a fantatsic website. Well done!

Tyster 17 Light Poster

Hi Folks,

I am encountering what I think is a simple problem but I haven't been able to solve it. I am trying to parse a simple XML file and I keep getting the following exception...

Exception in thread "main" javax.xml.transform.TransformerException: A location step was expected following the '/' or '//' token.
at com.sun.org.apache.xpath.internal.compiler.XPathParser.error(Unknown Source)

... more lines ...

Caused by: javax.xml.transform.TransformerException: A location step was expected following the '/' or '//' token.
at com.sun.org.apache.xpath.internal.compiler.XPathParser.error(Unknown Source)
at com.sun.org.apache.xpath.internal.compiler.XPathParser.RelativeLocationPath(Unknown Source)
at com.sun.org.apache.xpath.internal.compiler.XPathParser.LocationPath(Unknown Source)

I am convinced the problem is that the file isn't being found so the parser returns the exception above. I have built my documentBuilder and XPath objects correctly. Here is the code that I am using...

//Create builder and xpath objects
		DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder builder = dbfactory.newDocumentBuilder();
	    XPathFactory xpfactory = XPathFactory.newInstance();
	    XPath path = xpfactory.newXPath();

 //Find the XML file and start parsing 
 String fName = "C:\\Bank.xml";      // Windows path
 File f = new File(fName);
 Document doc = builder.parse(f);   // Parsing

I've tried various adjustments to get the parser to find the file, including simply specifyng the filename by itself (no specific path). I am using Eclipse and included the file in the project so I thought it would be found there without a problem but I guess not. In any case, nothing I've tried has worked. Can anyone kindly offer any suggestions?

Any help is greatly appreciated!

Thanks and have a great weekend!

Tyster 17 Light Poster

I think I'll try using Callable instead of Runnable.

Many Thanks!

Tyster 17 Light Poster

Maybe this will help...

My main method is required to read filenames as command line arguments, such as

java MyApp textfile1. txt textfile2.txt textfile3.txt

The app is supposed to use a separate thread to count the number of words in each text file. So, since a new thread is required for reading each text file, I have a separate class that implements the Runnable interface and does the actual counting of words. So I have...

public class CountWords implements Runnable {

...  instance variables and constructor ...  then the run() method...

     public void run() {

	> Word counting logic <

	}
	return numWords;

And this is where the trouble starts... I can't return the number of words counted because the run() method is a void method.

I was thinking that perhaps I could do the word counting in main() instead, but then its not clear to me how I would use a new thread for counting the words in each file. I mean, what would be the purpose of my Runnable class at that point?

Andy advice is greatly appreciated!

Tyster

Tyster 17 Light Poster

Hi Folks,

I have a general question about multithreading...

I have a small app that is multithreaded. I have a main() class and a separate Runnable class that implements the Runnable interface. The problem I have is that the Runnable class needs to return an integer to main(). But this isn't possible because the run() method in my Runnable class is of type void, so no value can be returned.

I suppose I could move the code that returns a value to a new class that is not Runnable but is called inside the run() method, but I think that still leaves me with the same basic problem.

Is there a general approach or widely accepted practice to this problem? Just looking for a little guidance on how one should tackle this sort of problem.

Many Thanks!

Tyster

Tyster 17 Light Poster

Hey Brian and Alex...

Many Thanks, guys. I had a couple of mistakes, but using == instead of .equals was the big one. I'm getting the expected return now.

Many Thanks to both of you!!

...Ty

Tyster 17 Light Poster

Hi there folks. I have an app that has several classes but for some reason one of these classes isn't giving me a return value. What I want to check is whether or not this code will return the expected string...

String seatLayout;

public String showAllSeats(String flightNumber){
		
		fn = flightNumber;
		
	// Make a set of arrays for each flight. This is only one flight. If the flightNumber is "1294"  ... 

		if(fn == "1294"){

			ArrayList<String> r1 = new ArrayList<String>(); 
			r1.add("Row 1");
			r1.add("_");
			r1.add("_");
			r1.add("_");
			String row1 = r1.toString();
			
			ArrayList<String> r2 = new ArrayList<String>();
			r2.add("Row 2");
			r2.add("_");
			r2.add("_");
			r2.add("_");
			String row2 = r2.toString();
			
			ArrayList<String> r3 = new ArrayList<String>();
			r3.add("Row 3");
			r3.add("_");
			r3.add("_");
			r3.add("_");
			String row3 = r3.toString();
			
			seatLayout = row1 + row2 + row3;
			
					
		}
		return seatLayout;

Is > String row1 = r1.toString(); < OK? I'm trying to convert the String array to a simple string. I think it's OK (Eclipse doesn't complain.)

If thats OK then > seatLayout = row1 + row2 + row3; < should be OK.

For some reason seatLayout isn't getting returned to main(). The code in main() that calls the method above is...

Seats s = new Seats();                    //Create Seats instance
int flightNum = fl1.getFlightNum();    //Get the flight number (from Flight class)

String flightN = Integer.toString(flightNum);  //Must convert flight number int to String first

System.out.print(s.showAllSeats(flightN));  // Pass flight number and Print the return

seatLayout should get returned to main() in the last line above (the print statement) but it isn't. I've tried fooling …

Tyster 17 Light Poster

Many Thanks, javaAddict! Thats exactly the guidance I was looking for.

Thanks again and have a great week!

... Tyster

Tyster 17 Light Poster

I have a problem that I've been poking at for 2 weeks and I'm stumped.

The basic problem is this: If you have an array of objects (an ArrayList in this case), and each of these objects has more than one instance variable (3 variables in this case), how the heck can you use a for loop to update the instance variables, one object after another? For example...

I have an array of bank accounts. Each account has a name, an account ID number and a balance. I'm trying to loop through the accounts, first updating the name, then updating the ID number, then the balance. Then I move on to the next object in the array.

I've tried doing this several ways, first by updating the names of each account, then the other variables, but that doesn't seem to be working. I think the easiest approach would be to update all 3 variables for each account, then move on to the next object in the array. Here's what I'm having trouble with...

I have a BankAccount class and a BankAccountTester class. The BankAccount class has the following constructor...


//Instance variables.

private int accountId;
private double balance;
private String name;


/**
* @param accountId
* @param balance
* @param name
*/

public BankAccount2(int accountId, double balance, String name) {
super();
this.accountId = accountId;
this.balance = balance;
this.name

Tyster 17 Light Poster

Many Thanks! I'll give that a try.

Tyster


Maintain the balance in a private variable inside deposit class.

you are trying to assign a double a value of void here
double newBalance = accounts.get(j).deposit(deposit);

when you withdraw or deposit, have that update a private variable of balance

private double balance = 0.0;

public double getBalance(){
   return balance;
}
public void withdraw(double d){
  //do your processing

//now set balance
balance = balance - d;
}


//in your other ui code call
double newBalance = accounts.get(j).getBalance();
Tyster 17 Light Poster

Hi Folks,

I'm a Java newbie so please forgive me if you've heard this one before...

Got a question for ya about an small app I am working on.

I have a banking app that creates accounts, then makes deposits and withdrawls to/from these accounts. Its very simple. I have a BankAccount class and in that class I have the following deposit method...

//Deposit method.
public void deposit(double dAmount) {


if(dAmount > 0) {   // Check that deposit amount is more than zero dollars..
balance = balance + dAmount;}  // Update balance with new balance.


else {JOptionPane.showMessageDialog( null, "Error: You must deposit more than 0 dollars.");}


The problem I am having is getting (retrieving) the new balance value in my tester class (with main()).  I created the accounts using an ArrayList named 'accounts'. So to get the new balance I do...


//Deposits


for(int j = 0; j < totalAccounts; j++) {


String dep = JOptionPane.showInputDialog("How much would you like to deposit in this account?: ");
double deposit = Double.parseDouble(dep);                  //Convert string to double
double newBalance = accounts.get(j).deposit(deposit);   //Call deposit method

The problem I am seeing is in the last line above. The line says go to index 'j' in the array and get the value after the deposit is made. In Eclipse the error I get is

"Type mismatch: Cannot convert from void to double."

Can anyone offer any suggestions? Should I return the balance in the deposit method instead of merely updating the balance?

I am having …

Tyster 17 Light Poster

Thanks a million Ezzaral! That helps alot!

Cheers!

...Tyster

Tyster 17 Light Poster

Each container can only have one layout manager, however you can easily create any layout you wish by nesting containers with the layout that you want for each one. This could include using a few JPanels inside a JFrame with each JPanel containing a few components. Breaking up the layout like that gives you a lot of control over the grouping and resizing behavior of complex layouts.

Thanks, Ezzaral!

Does anyone know where there might be a code sample for this sort of thing, just so I can get some guidance?

Many Thanks!

...Tyster

Tyster 17 Light Poster

Hi there everyone,

Is it possible to use more than one Layout Manager in a single GUI interface? I have classes (with event handlers) for various buttons, jtext menus, etc... but so far I've only built simple programs that use a single layout manager. When I call the setLayout() method on my container object I can only specify 1 layout manager. What I'm wondering is if its possible to combine layout managers in a single GUI. The setLayout method only takes one layout manager as a parameter.

Many Thanks!

...Tyster

Tyster 17 Light Poster

Thanks! I'll give that a try!

...Tyster

Tyster 17 Light Poster

Oddly, if I run...

C:\Sun\SDK\jdk\bin\javac E:\Chap1\source.java

It works. I get 'source.class' in E:\Chap1. But when I try to tun the program with...

C:\Sun\SDK\jdk\bin\java E:\Chap1\source

I get this error...

Exception in thread "main" java.lang.NoClassDefFoundError: E:\Chap1
\source

I tried fooling with the -d parameter but no luck.

Anyone have any ideas?

Many Thanks!

...Tyster

Tyster 17 Light Poster

Hi there folks,

Very new to java and I have what I hope will be a simple question...

I have JDK 1.5 installed on my C: drive and my source on my E: drive (flash drive). I'm trying to run the source and I always get NoClassDefFound errors when I try to run the program. Compile seems to work (no errors). Here is what I have tried...

C:\Sun\SDK\jdk\bin\java E:\Chap1\source.java

C:\Sun\SDK\jdk\bin\java "E:\Chap1\source.java"

I've fooled around with this quite a bit but no joy. I checked out the parameter options for java and javac but didn't see anything that would clearly address this. I want to compile such that the class file is created in the same directory as the source file.

Its worth noting that when I copy the source file to the directory where the compiler and java are located (C:\Sun\SDK\jdk\bin\) and try it there everything works fine.

Anyone have any suggestions?

Many Thanks!

Tyster

Tyster 17 Light Poster

Nevermind everyone! I got this one firgured out!

Thanks for looking!

Tyster

Tyster 17 Light Poster

Hi Folks,

Total C++ newbie here so please excuse my errors! I have been tasked with writing a small program and I can't get it to work. Here is the task description...

"A restaurant has 4 lunch combos for customers to choose:

Combo A : Fried chicken with slaw [price: 4.25]
Combo B : roast beef with mashed potato [price: 5.75]
Combo C : Fish and chips [price:5.25]
Combo D : soup and salad [price: 3.75]

Write a program to calculate how much a party of customers should pay. Suppose the party orders 2 B’s, 1 A and 3 D’s. The casher will enter B, B, A, D, D, D and T into the program. The T means “calculating total of the order”. It is a signal telling the computer that the whole order has been entered and it is time to calculate the total amount the party should pay. Assume there is no sales tax. "

I am supposed to try using while loops and switch for this task. I've been tinkering with this and some of this works but some doesn't. For example, when I enter T to calculate the Total I get nothing returned and the program ends. Same thing happens when I enter option C. I suspect that at least part of the problem is my break statements but any advice is GREATLY appreciated. When the program gets to 'break;' does it go back to 'switch' or somewhere …

Ancient Dragon commented: thanks for using code tags right +19