overwraith 83 Newbie Poster

Am still getting the IOException however, "The device is not ready."

            var exfil = from drive in DriveInfo.GetDrives()
                    where drive.DriveType == DriveType.Removable 
                    && drive.VolumeLabel == "EXFIL"
                    select drive;
overwraith 83 Newbie Poster

Am new to Linq, is kinda my first line of it. You shure it needs it? ok.

var exfil = from drive in DriveInfo.GetDrives()
where drive.DriveType == DriveType.Removable
and drive.VolumeLabel == "EXFIL"
select drive;
overwraith 83 Newbie Poster

So, I am trying to get a query working that finds a certain flash drive attached to my computer and selects it's DriveInfo object. I am having trouble because on my system when I call the VolumeLabel property of one of my DriveInfo objects it throws an exception (IOException) because the drive is not ready to write. For some reason I have a H:\ drive which is erroring out on me, does not appear in Windows explorer, or it could be due to some other software installed on my system. Regaurdless I need to skip over any drive that throws an exception like this. Here is the code:

                var exfil = from drive in DriveInfo.GetDrives()
                        where drive.DriveType == DriveType.Removable
                            where drive.VolumeLabel == "EXFIL"
                        select drive;

I also tried looking at the Expression.TryCatch method, but I don't know how to get it working. After I get the IEnumerable object I will simply select the first drive I find, which I am sure will be the right one since nobody will name their drive what I name mine.

http://msdn.microsoft.com/en-us/library/system.linq.expressions.tryexpression.aspx

overwraith 83 Newbie Poster

Do you mean the first few bytes of a file, or the hash of the file? If you mean the hash, you will need to use a hash algorithim which is probably already implemented in the java API like sha1, sha12, md5, etc. The reason I bring it up is that sometimes these algorithims are called fingerprinting algorithims, and can be used to establish that a file is unique to other files. Even changing a single char will drastically change the hash. So far I have only implemented a fingerprinting program in C#, but I googled a little, and the results are fairly easy to find once you use the correct vocabulary.

overwraith 83 Newbie Poster

So how would I go about doing this?

overwraith 83 Newbie Poster

So I am working on an old project that uses libnet, actually it is a book example, and I cannot find a version 1.1 or 1.0 of libnet. I am going to somehow have to track the depreciation of certain functions and I have never done something like this before. I think sourceforge throws away old versions after a while. I cannot post the project in question, but basically what it is, is an anti-port scanning countermeasure.

overwraith 83 Newbie Poster

You are probably right. Any other ways of doing it? Just wondering what other programmers do in this situation.

overwraith 83 Newbie Poster

So, I recently wrote a program for a class that involved writing an aggregate class to a file. This particular program had an order object, and each order could have 10 ice cream cones, so a ToString() of the class would look like this:

Order Number: 1
Customer #1: Harrington, Honor

Ice Cream Cone: Scoops: 1, Cone Cost: $1.25, Pickle  
Ice Cream Cone: Scoops: 1, Cone Cost: $1.25, Tangarine   
Ice Cream Cone: Scoops: 1, Cone Cost: $1.25, Nectarine  
Ice Cream Cone: Scoops: 1, Cone Cost: $1.25, Orange   
Ice Cream Cone: Scoops: 1, Cone Cost: $1.25, Chocolate   
Ice Cream Cone: Scoops: 1, Cone Cost: $1.25, Fudge  
Yogurt Cone: Scoops: 1, Cone Cost: $1.25, Pickle  
Yogurt Cone: Scoops: 1, Cone Cost: $1.25, Tangarine  
Yogurt Cone: Scoops: 1, Cone Cost: $1.25, Nectarine   
Yogurt Cone: Scoops: 1, Cone Cost: $1.25, Orange  

Total Price: $12.50

Is there any right way to do this? Would the aggregates be seperated into seperate files? What I ended up doing was attempting to read a certain class from the file, and if an exception occurred I would roll back the file stream and try to read the other class. The order information was there regaurdless.

overwraith 83 Newbie Poster

I have been looking at an example on MSDN, and I have some code. Lines 27 through 30 are throwing overflow exceptions. I do not know why I cannot use the current location in the file to seek from.

using System;
using System.IO;

public class FSSeek {
    public static void Main() {
        long offset;
        int nextByte;

        // alphabet.txt contains "abcdefghijklmnopqrstuvwxyz" 
        using (FileStream fs = new FileStream("stuff.txt", FileMode.Open, FileAccess.Read)) {
            for (offset = 1; offset <= fs.Length; offset++) {
                fs.Seek(-offset, SeekOrigin.End);//seeks from end backwards
                Console.Write(Convert.ToChar(fs.ReadByte()));
            }
            Console.WriteLine();

            for (offset = 0; offset <= fs.Length - 1; offset++) {
                fs.Seek(offset, SeekOrigin.Begin);//seeks from beginning forwards
                Console.Write(Convert.ToChar(fs.ReadByte()));
            }
            Console.WriteLine();

            //fs.Seek(0, SeekOrigin.Begin);//go back to beginning
            fs.Seek(13, SeekOrigin.End);//go to middle of file


            for (offset = 0; fs.Seek(offset, SeekOrigin.Current) > 0; offset++) {
                fs.Seek(-offset, SeekOrigin.Current);//seeks from current backwards
                Console.Write(Convert.ToChar(fs.ReadByte()));
            }

                fs.Seek(20, SeekOrigin.Begin);

            while (( nextByte = fs.ReadByte() ) > 0) {
                Console.Write(Convert.ToChar(nextByte));
            }
            Console.WriteLine();
        }
    }
}
// This code example displays the following output: 
// 
// zyxwvutsrqponmlkjihgfedcba 
// uvwxyz
overwraith 83 Newbie Poster

Sorry to be resurrecting this post, but I have been buisy lately, and didn't have time to persue this any farther. Can anybody provide some code for how to roll back a readline? I am currently dealing with a FileStream and a reader stream(i foreget what it was called) and every time I try to use this seek method I end up halfway between the previous record and the one I am trying to read again. I have been trying to incorporate the length of the string into the calculation. The code I have would be convoluted and bulky, so best if we start over from scratch.

overwraith 83 Newbie Poster

I wrote this bit of code while I was in the class. If I ever did it over, there are a few things that I would change, but there is a lot of potential in the code. Basically this "batch" master record/transaction record processor uses this passing of pointers to heap allocated structs to preform it's work. Combines two files, the transaction file, and the old master file into the new master file. It really reads the file almost like the file it's slef is the list. One of the things that should probably be fixed is that it does not write to a binary file, it writes to a text file (that just happens to have a .dat extension, I know I was younger when I wrote it, I didn't know). The loop in main may also need some work.

/*
Author: Cameron Block
Assignment: 11.7, 11.8
File: FileMatching.c
Purpose: Develop a program that does various operations on a file. 
*/
#include <stdio.h>//standard input/output
#include <assert.h>
#include <stdlib.h>//malloc cmd for allocating structs
#include <string.h>//memset cmd for clearing memory

char *removeNewLine(char input[]);

typedef struct{//struct for old master file
int accountNum;
float currentBalance;
char name[32];
}MasterRecord;

typedef struct{//struct for transfer file
int accountNum;
float dollarAmmt;
}TransRecord;

MasterRecord *readMasterFileRecord();//pointers are really awesome
TransRecord *readTransactionRecord();
void writeNewMasterRecord(MasterRecord *record);
MasterRecord *createMasterRecord(TransRecord *input, char *name);//creates a new initialized master file record
char *strStrip(char input[]);

void main()
{
    //both transactions file, and master file must be in order
    MasterRecord *currentMaster=readMasterFileRecord();
    TransRecord *currentTransaction=readTransactionRecord();
    while(currentMaster!=NULL)
    {
        while(currentTransaction!=NULL) …
overwraith 83 Newbie Poster

Yeah, sure it doesn't. I'm just imagining int, double, char, and all the structs I can think of :)

The cirriculum at my school says so, it might be mistaken, or I could have even interpreted it wrong. Dunno.

overwraith 83 Newbie Poster

C doesn't have objects silly! But basically yes, if you choose to allocate your struct without the malloc method, on the stack (I'm not saying that's what I did in my code), and then return the address of that stack allocated struct, would you still be able to access it, would it move it's slef to the heap, or what.

From what you are saying, it would be popped off the stack and unavailable to the coder.

From what I learned here, allocating to the heap is a really good idea, and can be very benificial to efficiency.

Thanks everybody for bearing with me.

overwraith 83 Newbie Poster

But what if you don't use malloc? Does the variable then get copied to the heap?

What if you deliberately place the struct on the stack?

It has been a while since I have coded C, so I hope this makes sense?

overwraith 83 Newbie Poster

Wait now, how did it get on the heap?

overwraith 83 Newbie Poster

I am actually looking back at one of my old C programs that I wrote in a C/C++ data structures class. Apparently it was very efficient according to the teacher, but am looking back to determine why it was efficient.

So if you do not allocate on the heap and you do pass a pointer back to main, then the program will have to move the struct elsewhere?

overwraith 83 Newbie Poster

Ok, I think I see, so when the code leaves the method it actually has to copy the struct from where it has been allocated to the method that called it right? So if you return a pointer it might be a little more efficient than copying the whole thing, but wouldn't it still have to copy the struct because the area on the stack is gone?

overwraith 83 Newbie Poster

Is there any difference between returning a pointer to a struct, and returning a struct? Aside from the derefrenceing that is done would they both be working with the same struct? Is there any copying that gets done if it is just a regular return?

overwraith 83 Newbie Poster

I am relatively new to C#, does anybody have a simple example of how calling C++ from C# would be done? I heard that C# can call other languages.

overwraith 83 Newbie Poster

How does one roll back a readline from a text file?

overwraith 83 Newbie Poster

That was very helpful, thanks.

overwraith 83 Newbie Poster

So, I wrote some code for appending to an array, and I thought to myself, would be cool to make the method more generic using an interface. I keep getting this error though that basically says that the compiler's best overloaded method that can match this is _____, and it does not like how I am passing it. So I am getting the distinct impression that interfaces cannot be passed by reference. Here is the code:

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

namespace Test2 {
    class Program {
        static void Main(string[] args) {
            MyClass[] mine = new MyClass[5];

            for (int i = 0; i < mine.Length; i++)
                mine[i] = new MyClass(i);

            foreach (MyClass temp in mine)
                Console.WriteLine(temp.ToString());

            appendIComparable(ref mine, ref new MyClass(8) );

            foreach(MyClass temp in mine)
                Console.WriteLine(temp.ToString());

            pause();

        }

        public static void pause() {
            Console.Write("Press any key to continue... ");
            Console.ReadLine();
        }

        public class MyClass : IComparable {
            public int i;

            public MyClass(int i) { this.i = i; }

            public int CompareTo(object obj) {
                if (obj == null) return 1;

                MyClass otherClass = obj as MyClass;
                if (otherClass != null)
                    return this.i.CompareTo(otherClass.i);
                else
                    throw new ArgumentException("Object is not my class... ");
            }

            public override string ToString() {
                return i.ToString();
            }

        }

        public static void appendIComparable(ref IComparable[] original, ref IComparable append) {

            //move original from one array to the other
            int j = 0;
            IComparable[] newArray = new IComparable[original.Length + 1];
            for (; j < original.Length; j++) {
                if (original[j].CompareTo(append) > 0) {//if the append customer is …
overwraith 83 Newbie Poster

I wrote my own program to test this out, and you were right, if one want's to save processing cycles, this is not the place to do it with primitive types. Arrays, classes, and structs are the only place where this makes sense. When using my program I noticed that passing by reference and passing by value would frequently change places in terms of being the fastest. It would be interesting to be able to put the information gathered from a program like this into a function curve in a graphing program. Here is the code I wrote, tell me if there are any flaws. Also I noticed that the values are very close together, which tells me that the difference between the two is negligable.

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

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int numTries = 1000;

            passingComparisonInt(numTries);

            pause();
        }

        private static void passingComparisonInt(int numTries)
        {
            double[] times1 = testByRefInt(numTries);

            double avg = average(times1, numTries);

            Console.WriteLine("The average time for a pass by reference is: {0}", avg);


            double[] times2 = testByValInt(numTries);

            avg = average(times2, numTries);

            Console.WriteLine("The average time for a pass by value is: {0}", avg);
        }

        private static double[] testByRefInt(int numTries)
        {
            int x = 0;
            Stopwatch sw = new Stopwatch();

            double[] times = new double[numTries];

            for (int i = 0; i < numTries; i++)
            {
                sw.Start();
                myMethod1(ref x);
                sw.Stop();

                times[i] = sw.Elapsed.TotalMilliseconds;
            }
            return times;
        }

        private static double[] testByValInt(int numTries)
        {
            int x …
overwraith 83 Newbie Poster

So I have read what you both posted, and they had some very good points. I also asked my C# teacher more about pass by reference, and I had some of the topic confused. So pass by reference basically boxes, or stores a pointer to the data type provided in the heap. This address in the heap is passed to the method. These pointers used to be about a ubyte in size, and probably still are according to my teacher. So given what my teacher told me, it stands to reason that it is more efficient to pass by reference for any value larger than a ubyte. Given this, it would be more efficient in all situations to pass by reference rather than copy the whole value in a pass by value operation. The article that I gave you all to look at really did me a disservice though, because it suggested that there is overhead in passing by reference. There is some overhead yes, but no more than is necessary and compared to pass by value it is much better, so it should not be portrayed as such. I suppose what I am trying to say is that coding it's self generates overhead, pass by reference is much better in terms of overhead than pass by value.

Thank you all, the universe has righted it's self again!

overwraith 83 Newbie Poster

I am wondering, when does it become more efficient to pass by value in C#? I was reading this article:
http://msdn.microsoft.com/en-us/library/4d43ts61%28v=vs.90%29.aspx
The article suggests that passing by reference actually generates overhead when it transferrs the value type to the heap. My C/C++ classes swore by passing by reference as a good coding practice, and I have passed even primitive values by reference for a while now. I am in C# now, so I guess it is possible that it does not funciton the same, but I always thought that passing a pointer to a value was more efficient than copying the value of a variable to a new local variable in memory. Is there a certain number of bytes a data type has to be to become more efficient to pass by reference?

overwraith 83 Newbie Poster

Figured something out today, if the list is blank the script will fail, if I assign a space to it, it will preform as I want it to. Does anybody know why?

set mylist= & for /f "tokens=3 delims= " %A in ('echo list volume ^| diskpart ^| findstr /V "###" ^| findstr /V "System" ^| findstr "Volume"') do (set mylist=!mylist! %A)
overwraith 83 Newbie Poster

Hello, am having some trouble with Windows batch variable expansion. Am trying to make a script that will make a list of all currently plugged in drives. I want to omit the system drive, since that one shows up as a blank letter. The following script can be copy+paisted directly into windows command line, you just have to turn on delayed variable expansion first, so I will paste both commands here:

    SETLOCAL ENABLEDELAYEDEXPANSION

    set mylist=& for /f "tokens=3 delims= " %A in ('echo list volume ^| diskpart ^| findstr /V "###" ^| findstr /V "System" ^| findstr "Volume"') do (set mylist=!mylist! %A:)

The script does not work right though, because when I tell the variable to echo, I get the variable name at the beginning of the output, aswell as the output printed twice.

C:\Users\UserName>echo %mylist%
!mylist! E: F: C: D: G: H: J: E: F: C: D: G: H: J:

Would be cool if somebody knows what's going on.

overwraith 83 Newbie Poster

I think I will just use a queue. It looks like there is no way to do what I am trying to do, especially when arrays are passed by refrence in C, and what I need is not a refrence, but a pointer that can be changed.

overwraith 83 Newbie Poster

How do I create a function that accepts by refrence an array of character pointers?

I need to be able to overwrite the contents of an array of character pointers, hence I need a pointer to that array.

Here is some of my code, but it is throwing errors, so will be overwriting it:

//function prototype. 
void getFileNames(char **contents[]);

//in main
char *contents[] = {"Hello", "World!!!"};
getFileNames(&contents);

//function definition
void getFileNames(char **contents[]){}

Maybe there is a better way of doing this.

overwraith 83 Newbie Poster

Yes, but is there any kind of online refrence I can use to read about the functions?

overwraith 83 Newbie Poster

Hello, I got some code from:

http://stackoverflow.com/questions/1859201/add-seconds-to-a-date

this is the code:

#include <time.h>
#include <stdio.h>

int main()
{
    time_t now = time( NULL);

    struct tm now_tm = *localtime( &now);


    struct tm then_tm = now_tm;
    then_tm.tm_sec += 50;   // add 50 seconds to the time

    mktime( &then_tm);      // normalize it

    printf( "%s\n", asctime( &now_tm));
    printf( "%s\n", asctime( &then_tm));

    return 0;
}

Unfortuantely I do not know much about the code, and need to write a program that records a time, and compares two times. I do not know much about the datatypes time_t, struct tm, and the functions localtime, mktime, asctime, etc. Any information on this would be helpful. I am hoping to write some firmware which will activate after a certain amount of time, once I know how to use c time I will be able to finish the firmware.

overwraith 83 Newbie Poster

Sorry everybody, I think I know what is causing it, didn't reset the variables.

#include <windows.h>
#include <stdio.h>
#include <stddef.h>//null defined here
#include <array>//for ARRAYSIZE() method
#include <string.h>
using namespace std;

int main(){

    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStringsA(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
        char* szSingleDrive = szLogicalDrives;
        //Returned string "C:\\ \0 D:\\ \0 E:\\ \0 \0"
        //Hits an extra \0 at the final string, which stops the loop. 
            while(*szSingleDrive)
            {
                //GetVolumeInformationA() variables
                char volumeName[255];
                memset(volumeName, '\0', 255);
                char fileSystemName[255];
                memset(fileSystemName, '\0', 255);
                DWORD serialNumber=0;
                DWORD maxComponentLen = 0;
                DWORD fileSystemFlags=0;

                GetVolumeInformationA(szSingleDrive,volumeName,ARRAYSIZE(volumeName),
                    &serialNumber,
                    &maxComponentLen,
                    &fileSystemFlags,
                    fileSystemName,
                    ARRAYSIZE(fileSystemName));
                //put the code here for getting the drive name. 
                printf("Drive: %s Volume Name: %s\n", szSingleDrive, volumeName);
                //printf only prints up to the first \0 character. 

                //get the next drive
                szSingleDrive += strlen(szSingleDrive) + 1;
                //strlen() only reads up to the first \0 character
                //so szSingleDrive always points to the beginning of a string. 
            }
    }
    system("pause");
}
overwraith 83 Newbie Poster

I just glued together two codes I found online, and found an interesting result. Some of my flash drives have been appearing twice on the system.
Here is what the output looks like:

Drive: C:\ Volume Name:
Drive: D:\ Volume Name:
Drive: E:\ Volume Name:
Drive: F:\ Volume Name:
Drive: G:\ Volume Name: USB20FD
Drive: H:\ Volume Name: USB20FD
Drive: I:\ Volume Name: CRUZER
Drive: J:\ Volume Name: CRUZER
Press any key to continue . . .

And here is the code that I ran:

#include <windows.h>
#include <stdio.h>
#include <stddef.h>//null defined here
#include <array>//for ARRAYSIZE() method
using namespace std;

int main(){

    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStringsA(dwSize,szLogicalDrives);

    //GetVolumeInformationA() variables
    char volumeName[255];
    char fileSystemName[255];
    DWORD serialNumber=0;
    DWORD maxComponentLen = 0;
    DWORD fileSystemFlags=0;

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
        char* szSingleDrive = szLogicalDrives;
        //Returned string "C:\\ \0 D:\\ \0 E:\\ \0 \0"
        //Hits an extra \0 at the final string, which stops the loop. 
            while(*szSingleDrive)
            {
                GetVolumeInformationA(szSingleDrive,volumeName,ARRAYSIZE(volumeName),
                    &serialNumber,
                    &maxComponentLen,
                    &fileSystemFlags,
                    fileSystemName,
                    ARRAYSIZE(fileSystemName));
                //put the code here for getting the drive name. 
                printf("Drive: %s Volume Name: %s\n", szSingleDrive, volumeName);
                //printf only prints up to the first \0 character. 

                //get the next drive
                szSingleDrive += strlen(szSingleDrive) + 1;
                //strlen() only reads up to the first \0 character
                //so szSingleDrive always points to the beginning of a string. 
            }
    }
    system("pause");
}

Another thing to note is that none of my flashdrives have that U3 launchpad software that makes the …

overwraith 83 Newbie Poster

Thank you, what you said more accurately reflects what I tried to express what I thought was happening (If that makes any sense).

overwraith 83 Newbie Poster

Hello, I was doing some research on enumerating the different drives on a system, and I found some code on MSDN.
Here is the page:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364975%28v=vs.85%29.aspx

The source code looks like this:

DWORD dwSize = MAX_PATH;
char szLogicalDrives[MAX_PATH] = {0};
DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);

if (dwResult > 0 && dwResult <= MAX_PATH)
{
    char* szSingleDrive = szLogicalDrives;
        while(*szSingleDrive)
        {
        printf("Drive: %s\n", szSingleDrive);

              // get the next drive
                szSingleDrive += strlen(szSingleDrive) + 1;
        }
} 

I modified the code to look like this, because I prefer to use ANSI operations:

#include <windows.h>
#include <stdio.h>
using namespace std;

int main(){

    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStringsA(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
        char* szSingleDrive = szLogicalDrives;
            while(*szSingleDrive)
            {
                printf("Drive: %s\n", szSingleDrive);
                //printf only prints up to the first \0 character. 

                //get the next drive
                szSingleDrive += strlen(szSingleDrive) + 1;
                //strlen() only reads up to the first \0 character
                //so szSingleDrive always points to the beginning of a string. 
            }
    }
    system("pause");
}

I was wondering, how does this work:

while(*szSingleDrive)

I am not sure what the while operation is doing, I am guessing however that the pointer in the while loop is always pointing to string data, until it iterates on the final drive, and hits another \0 character, which causes the while test to be false. I am not sure, however so I thought I would ask somebody online.

overwraith 83 Newbie Poster

It works now! I had another, more complex program I was simultneously working on, and I updated the code with the tweaks I learned about here, and added a few more threads, and I got the alternating action I was looking for. Looks like the less threads you have, the less likely you are to get the altrenating action. Thank you.

Now, how do I mark this solved?

overwraith 83 Newbie Poster

Ok, so that explains some things, updated code looks like this:

public class RaceHorseAppII {

    public static void main(String[] args) {


        Thread t = new Thread(new RaceHorse("Sawyer"));
        Thread t2 = new Thread(new RaceHorse("Tom"));

        t.start();
        t2.start();

    }

    public static class RaceHorse implements Runnable{

        private String name = "";

        public RaceHorse(String name){
            this.name = name; 
        }

        public void run() {
            for(int i = 0 ; i < 50 ; i++){
                System.out.println(name);

            }
        }

    }//end inner class

}//end class

I still dont know why the output doesn't look something like the following:

Tom
Sawyer
Sawyer
Tom
Sawyer
Tom
Tom
...

overwraith 83 Newbie Poster

Output looks like the following:

Stan...
Tom...
Harry...
Finn...
Sawyer...

overwraith 83 Newbie Poster

Hello, I am working on a program, and I noticed that all my threads are starting and stopping in exactly the same order I put them in, and they are not trading places in the output, or mixing output like concurrent objects should. Here is my code:

public class RaceHorseAppII {

    public static void main(String[] args) {
        new RaceHorse("Stan").run();
        new RaceHorse("Tom").run();
        new RaceHorse("Harry").run();
        new RaceHorse("Finn").run();
        new RaceHorse("Sawyer").run();

    }

    public static class RaceHorse implements Runnable {

        private String name = "";

        public RaceHorse(String name){
            this.name = name; 
        }

        public void run() {
            for(int i = 0 ; i < 50 ; i++){
                System.out.println(name);

            }
        }

    }//end inner class

}//end class

Does anyone know why it is doing this?

overwraith 83 Newbie Poster

I see the error of my ways. Good catch bguild. I still cant believe that the local variable declaration even made it into my code in the first place. Arg!!!

overwraith 83 Newbie Poster

I have been having some trouble with this action listener scenareo, and I am doing it exactly like what my java book says to do, and something is still not working. In the action listener the if statement is not working correctly. Here is an example of my code. The label in the center of the frame should be changing, but doesnt.

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class Test extends JFrame implements ActionListener{

    private JButton team1;
    private JLabel label;

    public static void main(String[] args) {
        new Test();
    }//end main

    public Test(){
        super("Favorite Teams");
        this.setVisible(true);
        this.setSize(300, 300);
        this.setLocationRelativeTo(null);//center the frame 
        this.setLayout(new BorderLayout());
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Initialize the JButtons
        JButton team1 = new JButton("Zerg");//video game starcraft

        //initialize the JLabel
        label = new JLabel("Please select a team. ");
        label.setHorizontalAlignment(JLabel.CENTER);

        //add the JButtons to the frame
        this.add(team1, BorderLayout.LINE_START);

        //add JLabel to the frame
        this.add(label, BorderLayout.CENTER);

        //add ActionListeners to the buttons
        team1.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if(source == team1)//Zerg
            label.setText("Ok, if you like critters. ");
    }//end method

}//end class
overwraith 83 Newbie Poster

I just created my own class based on this idea, and found that a class based on a linked list is much less efficient in runtime than the built in String Builder, and String Buffer classes. Thanks for the post on ropes and gap buffers, I will look at them.

overwraith 83 Newbie Poster

If there is a String Buffer, and a String Builder based on array technology, why then is there no equivalent mutable data type based on a Linked List? Or is there?

overwraith 83 Newbie Poster

I see what you mean now, a class shouldnt be extended unless there is a reason for extending it. I fixed the code as follows.

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Component;
import java.awt.GridLayout;

public class JOptionPaneArrayInputExample{

    public static void main(String[] args) {
           String messages[] = {"str1", "str2", "str3", "str4", "str5"};

           showInputDialog(null, messages);
    }//end main

   public static String[] showInputDialog(Component parentComponent, String messages[]){
       JTextField textFields[] = new JTextField[messages.length];
       JPanel panel = new JPanel();
       String input[] = new String[messages.length];

       panel.setLayout(new GridLayout(messages.length, 2, 0, 0));

       for(int i = 0 ; i < messages.length ; i++){
           panel.add(new JLabel(messages[i]));
           textFields[i] = new JTextField();
           panel.add(textFields[i]);
       }

       JOptionPane.showConfirmDialog(parentComponent, panel, 
               "Input", JOptionPane.OK_CANCEL_OPTION);

       for(int i = 0 ; i < messages.length ; i++)
           input[i] = textFields[i].getText();

       return input;
   }//end method

}//end class
overwraith 83 Newbie Poster

I thought this was going to be harder than what it turned out to be. After looking around online some, and some coding here is what I came up with.

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Component;
import java.awt.GridLayout;

public class EXTJOptionPane extends JOptionPane {

    public static void main(String[] args) {
           String messages[] = {"str1", "str2", "str3", "str4", "str5"};

           showInputDialog(null, messages);
    }//end main

   public static String[] showInputDialog(Component parentComponent, String messages[]){
       JTextField textFields[] = new JTextField[messages.length];
       JPanel panel = new JPanel();
       String input[] = new String[messages.length];

       panel.setLayout(new GridLayout(messages.length, 2, 0, 0));

       for(int i = 0 ; i < messages.length ; i++){
           panel.add(new JLabel(messages[i]));
           textFields[i] = new JTextField();
           panel.add(textFields[i]);
       }

       JOptionPane.showConfirmDialog(parentComponent, panel, 
               "Input", JOptionPane.OK_CANCEL_OPTION);

       for(int i = 0 ; i < messages.length ; i++)
           input[i] = textFields[i].getText();

       return input;
   }//end method

}//end class
overwraith 83 Newbie Poster

Would making a completely seperate class with the proposed functionality be better/make more sense?

overwraith 83 Newbie Poster

I thought it would be really cool if JOptionPane could be extended to accept an array of strings that represent messages, and have the method return an array of strings that represent user answers to the messages which are entered into the dialog box. This would make getting GUI input a little easier. Unfortunately I have no idea how the JOptionPane class works under the hood so I have no Idea where to start. Here is an example of the method I would start work on.

    import javax.swing.JOptionPane;
    import java.awt.Component;

    public class EXTJOptionPane extends JOptionPane {

        public static Object[] showInputDialog(Component parentComponent, 
                Object message[]){
            return new Object[3];
        }//end method
    }//end class
overwraith 83 Newbie Poster

I hope this is the right location to make this post.

I downloaded the source code for a rich text editor from;

http://code.google.com/p/android-richtexteditor/

and the code will not compile correctly. The errors I get are;

"Unable to resolve target 'android-4'",

"AndroidManifest.xml file missing!", and in the Html.java file there are 2 errors involving;

"The import org.ccil cannot be resolved"

When you download the file, you will need to download the version 4 of the source code because the newest versions source code has been removed. I am using eclipse version 4.2.0, and Android SDK Manager Revision 20. I have installed API versions 4.0, 4.1 and many of the extras. I am pretty sure I downloaded the "classic" version of eclipse. I suspect there are 2 causes to these errors, and would appreciate input. Other threads from stack overflow concerning both this project and the generic errors have been unhelpful, as at least one of the threads highest ranked answers was in fact incorrect. Also, the instructions put forth were not for my version of
eclipse, or were incomplete.

overwraith 83 Newbie Poster

I have figured out a couple things concerning my previous post. The first, and possably most important is that the preceding loop needs to have Delayed Environment Variable Expansion enabled. Apparently MSDOS has problems if there are refrences to the same variable more than once on the same line, and Delayed Environment Variable Expansion is the key to fixing these problems. I have also found out that if there is no text assigned to the accumulator variable, then the first time through the loop the variable assigns %targetDR% to the variable. To avoid this assign some text to the variable first, then delete the first character like shown in some of the code I provide below. Also, to take advantage of Delayed Environment Variable Expansion you need to use exclamation(!) marks instead of percent symbols(%). The following code executes directly in the command shell, and needs modified if you want to execute it in a batch file.

REM SET THE FLAG FOR ENABLE DELAYED ENVIRONMENT VARIABLE EXPANSION
REM FROM WHAT I UNDERSTAND THERE ARE INDIRECTION PROBLEMS WHEN NOT 
REM SET AND THE VARIABLE IS CALLED MULTIPLE TIMES ON THE SAME LINE
cmd.exe /V:ON
REM IF SOME TEXT IS NOT ASSIGNED TO THIS VARIABLE THE LOOP WILL FAIL AND
REM CAUSE THE VARIABLE NAME TO BE ASSIGNED TO THE BEGINNING OF THE LIST
Set targetDr=*
REM THE FOR LOOP THAT SEEKS OUT SUITABLE DRIVES, HAS SOME NIFTY INDIRECTION
REM OPERATORS "!" WHICH ARE USED WHEN THE VARIABLE IS CALLED MULTIPLE …
overwraith 83 Newbie Poster

I am working on a "for loop that finds all the drives on a system that match a given criteria and am trying to accumulate the drive letters into a list(string) which I can then pipe to a command which will do something to those drives. I do not use the command prompt every day, so please keep explanations simple. here is the code I have so far;

for %a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (IF NOT EXIST %a:\evac.txt If EXIST %a:\ SET "targetDR=%targetDR %a:" )

The "SET "targetDR=%targetDR %a:" )" is not working as it should. I want the code to accumulate like so;
"C:\ D:\ E:\ F:\" provided the drives match the if statements I have preceding the code. "echo %targetDR%" yields "%targetDR H:" which is incorrect. I will NOT be running this code in a batch file, I will be running it directly from the command prompt. Also, I am not very familiar with variable operations in the command prompt, because in some code I see differing variable declarations like the following; %var%, %var, !var! ect...