sirlink99 56 Practically a Master Poster

Hello,

I am working on a simple timer toolbar app in swift for macOS and I am experiencing a visual bug.

Basically, I should be able to add any number of timers to the main screen and they should stack on top of each other. Once the space is filled up in the window, a scroll bar appears allowing you to scroll through all the timers. My issue is that when I add the timers, they do not show all the time. I have a hunch it is either some refresh issue or some spacing issue.

The blank screen looks like this:
Screen_Shot_2017-07-18_at_10_45_21.png

The bug is visible here. Out of the 3 timers added only 2 show up with the empty space between the 2 timers being the location where the third timer should be: Screen_Shot_2017-07-18_at_10_49_06.png

The main scene is arranged like this: Screen_Shot_2017-07-18_at_10_52_12.png

Where the mainScreenView and the dynamicScrollView and the View are all set to 250px wide. The timer view itself is a separate view, but that is also 250 px wide.

The code that adds the timers to the window is as follows:

func updateList(){
        let documentView = NSView(frame: CGRect(x:0,y:0,width:250,height:max(360, AppDelegate.timekeeperArray.count*60)))
        documentView.autoresizesSubviews = true
        documentView.canDrawConcurrently = true

        var counter = 0
        for var i in AppDelegate.timekeeperArray{
            //let offset = CGFloat(counter * 50)
            //let button = NSButton(frame: CGRect(x:0, y:offset, width:150, height:50 ))
            dsvScrollView.contentView.addSubview(i.getPreview(index: counter))
            counter += 1;
        }
        dsvScrollView.documentView = documentView
        for var i in (dsvScrollView.documentView?.subviews)!{
            i.needsDisplay = true
            i.superview?.needsDisplay = true
            for var j ...
rproffitt commented: Interesting issue but I have no way to duplicate. +12
sirlink99 56 Practically a Master Poster

Hello everyone,

I am trying to write an object loader in c++. Currently, I have a file that is made up of many sub objects and I am having a little difficulty figuring out how to process the data.

First of all, here is an example of part of the file

o shape_brow_Plane.030
v 3.719171 7.430269 -0.000989
v 3.719171 7.366541 -0.000989
v 3.655808 7.366541 -0.000989
v 3.655808 7.430269 -0.000989
v 3.687490 7.361845 -0.000989
v 3.729859 7.398441 -0.000989
v 3.687490 7.435111 -0.000989
v 3.645120 7.398441 -0.000989
l 28 31
l 29 31
l 27 32
l 28 32
l 27 33
l 30 33
l 29 34
l 30 34
o shape_nose_Plane.029
v 4.047793 6.746455 -0.000989
v 4.049577 6.631922 -0.000989
v 3.956243 6.631922 -0.000989
v 3.958028 6.746455 -0.000989
v 4.002910 6.616178 -0.000989
v 4.065321 6.678942 -0.000989
v 3.940499 6.678942 -0.000989
v 3.987510 6.801841 -0.000989
v 4.018311 6.801841 -0.000989
v 4.002910 6.808174 -0.000989
l 36 39
l 37 39
l 35 40
l 36 40
l 37 41
l 38 41
l 38 42
l 35 43
l 42 44
l 43 44

later on it also uses the usual vt and vn and f as well.
First of all, I am wondering what the extra numbers after the vertex co-ordinates are. Are they sub-faces for the object?
Second, I am wondering if vertex co-ordinates are globally maintained, or are they separate for each object.

I current have a loop that iterates through all of the v, vt, vn. However, I have ...

sirlink99 56 Practically a Master Poster

Hello All,

I am having trouble looping through a 2D array in C++ (should be very easy, but I am just starting C++). At the current moment I have this class file

#include "Cube.h"
#include <freeglut.h>
#include <stdio.h>

Cube::Cube(int cx, int cy, int cz , int cubeWidth)
{
    int p[][3] = { { cx, cy, cz }, { cx, cy-cubeWidth, cz }, { cx + cubeWidth, cy - cubeWidth, cz },{cx + cubeWidth, cy, cz},
                { cx, cy, cz - cubeWidth }, { cx, cy-cubeWidth, cz - cubeWidth }, { cx+cubeWidth, cy-cubeWidth, cz - cubeWidth }, { cx+cubeWidth, cy, cz - cubeWidth } };
    points = *p;
    int faces[][4] = { { 0, 1, 2, 3 }, { 3, 2, 6, 7 }, { 7, 6, 5, 4 }, {4, 5, 1, 0 }, {0, 3, 7, 4}, { 1, 5, 6, 2} };
}

bool printed = false;
void Cube::drawCube(){
    if (!printed){
        glBegin(GL_POLYGON);
        for (int i = 0 ; i != 24; i++){
            printf("%d: %d, ", i, *(points + i));
            if (i % 3 == 0)
                printf("\n");
        }

        printed = true;
        glEnd();
    }
}

Cube::~Cube()
{
}

amd this header file:

#pragma once
class Cube
{

private:
    int *points;//cd array containing all the points of the cube
    int points2[8][3];
    int *faces;

public:
    Cube(int, int, int, int);
    ~Cube();
    void drawCube();

};

As you can see, I tried looping through that way, but what the program prints out doesn't make any sense. I am wondering how I can loop through this ...

I know, but I don't want to provide too much code because like I said, the assignment is still ongoing.

I thought I was doing a deep copy on each individual using the

public Specimen getNewInstance(){
        return new Specimen (chromo);
    }

where chromo is the chromosome of that individual. While thinking about it, I was wondering what if it is because I don't get a copy of the city? But the cities don't change. Then I realized that it is because I don't deep copy the array of chromosomes too, so replacing the above code with

public Specimen getNewInstance(){
        return new Specimen (Arrays.copyOf(chromo, chromo.length));
    }

I think because I didn't deep copy my array, the mutations that I did to a new instance of the individual changed the old copy of the array in certai mulations, changing my answer.

So, the second code seems to fix the issue. Thank you for your help!

sirlink99 56 Practically a Master Poster

Hello everyone!

I am writing a GA, and I am trying to implement elitism. My problem is an interesting one. I cannot release too much code because it is an ongoing assignment. I have asked the TA, and he is unable to find the solution as of this moment. The assignment deals with solving the TSP. The elite is always the best value in the population. This elite gets placed from the old generation into the new generation in order to keep track of the best result, and hopefully improve it. There are the steps that I do after I initialize a random population.

The GA loop:

  1. replaces old population with generated new population
  2. Sort the returned population
  3. takes the best value from the new population and stores it if the fitness (length of the path) is lower than the current best.
    4: loop

Creating the new population:

  1. sort the old population
  2. generate the new population in a different list
  3. sort the new population
  4. replace the worst in the new population with the best in the old population.
  5. return the new population to my GA loop.

Of course, there are redundancies with the sorting, but only because of the error I am experiencing. This mysterious error is that if I print out the best from the population, and the best from all of the generations, they are not identical as they should be. Remember, the elite keeps track of the best value ...

A quick look at the documentation suggest to me that there is a getInputValue() function that you might want to look at.

I hope you can figure it out!

@JamesCherrill Thanks! I have managed to get the blur working, however my image moved a little down and to the left whenever I use the blur filter code.

This is the code I am using:
where *pixel Im is an image, and tmpBuffer is a temporary buffer to apply the blur.

void MyFilter(pixel* Im, int myIm_Width, int myIm_Height){
    int x, y;
    global.tmpBuffer = copyPic(global.data, global.w, global.h);
    for (x = 0; x < myIm_Width; x++)
        for (y = 0; y < myIm_Height; y++){
            int loc = x + y*myIm_Width;

            int blurX, blurY;
            int blurRad = 5;
            int totPix = 0;
            int blurSum[] = { 0, 0, 0 }; // {r, g, b} values for blur
            //gets the pixels in the matrix
            for (blurX = -((int)blurRad / 2); blurX < (int)blurRad / 2; blurX++){
                for (blurY = -((int)blurRad / 2); blurY < (int)blurRad / 2; blurY++){
                    if (!(blurX < 0 || blurX > global.w || blurY < 0 || blurY > global.h)){
                        blurSum[0] += global.data[loc + (blurX * global.w) + blurY].r;
                        blurSum[1] += global.data[loc + (blurX * global.w) + blurY].g;
                        blurSum[2] += global.data[loc + (blurX * global.w   ) + blurY].b;
                        totPix++;
                    }
                }
            }
            global.tmpBuffer[loc].r = blurSum[0] / totPix;
            global.tmpBuffer[loc].g = blurSum[1] / totPix;
            global.tmpBuffer[loc].b = blurSum[2] / totPix;
        }
    global.data = copyPic(global.tmpBuffer, global.w, global.h); // copies the picture to global.data (the picture being displayed)
}

the struct being used for the image looks like this

typedef struct {
    pixel *data; // Modified Image Buffer
    pixel *oImage; // Original Image
    pixel *tmpBuffer; ...
sirlink99 56 Practically a Master Poster

Hello Everyone!

I am wondering about the thory behind the box blur. I have an assignment, and I wrote a program implementing the box blur the way it was described in my assignment which is "When centered on a pixel, its values are multiplied with each corresponding surrounding pixel values, and then divided by the sum of the matrix values" and then it gave a 3 by 3 matrix of all ones.

The code I have works with the r, g and b values separately for an image for both the sum and the product portion of the formula, which I interpreted as (product of one color channel in every element in the matrix)/ (sum of those color channels). This does execute, however an all black image is created. I am wondering where I am going wrong. I did some sample calculations using one color stream just to see it if works, but it is way off. for example (100100160*50) / (100+100+160+50) = 80000000/ 410, which is definitely greater than the 255 max for the color value. If I could get some clarification then it would be much appreciated.

Thank you for your time and help

@newcoder310 as you can see in the second video code that I uploaded, the the sleep is based off the rate of execution rather than the user set fps. Even if I reduce the sleep time, the execution time cannot change, therefore the minimum fps I can get is the 1 second divided by the speed of the execution.

@JamesCherrill I will try the threading a bit later. For now I will just focus on getting the sound working. Thanks for all of your help!

I ran changed the video code thinking about your suggestion. I came up with a way that lowers the time. I set it to 10 seconds to compare, and the file produces an 8 second video. However, the way I solved it uses a variable frame rate, as I base it on how many times I could cycle the code based on the speed of the proccess. I checked, and taking the screenshot itself takes about 25ms, and doing the converting and writing along with the screenshot generally takes around 40ms on my computer. Would using multiple threads to take the screenshot and then pass it to the writer be more accurate in terms of timing?

I also looked at the audio file. The number of samples taken was 4410000. I placed the genereated mp3 file into audacity, and the only spikes I saw were tiny, and equally spaced. I am assuming that is is where each segment starts. I also forgot to mention that the mp3 file generated is 50 seconds long, so the length shouldn't be the issue.

Here is the new video capture code.

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.concurrent.TimeUnit;

import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;

public class TestScreenRecord {

    private static final double FRAME_RATE = 13;
    private static final int SECS_TO_RUN_FOR = 10;
    private static final String outputFilename = "C:/Users/Adam/Programs/Playhouse/SR/Test.mp4";
    private static Dimension screenBounds = Toolkit.getDefaultToolkit().getScreenSize();

    private static Robot robot;
    private static Rectangle capSize = new Rectangle(screenBounds);
    public static void main(String[] args) {
        // make IMediaWriter ...
sirlink99 56 Practically a Master Poster

Hello All.

I am having 2 problems here with my code. I will start off with the video code first. The video code should capture 20 seconds of the screen at 50fps, however, when I generate it, it generates a 1 minute 7 second video, and I am not sure why. The math adds up. I have tried lowering the FPS, but the time is still longer than 20 seconds. The is as follows:

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.concurrent.TimeUnit;

import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;

public class TestScreenRecord {

    private static final double FRAME_RATE = 50;
    private static final int SECS_TO_RUN_FOR = 20;
    private static final String outputFilename = "C:/Users/Adam/Programs/Playhouse/SR/Test.mp4";
    private static Dimension screenBounds = Toolkit.getDefaultToolkit().getScreenSize();

    public static void main(String[] args) {
        // make IMediaWriter write file to location
        final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);

        // add 1 video stream at position 0 and fixed frame rate of framerate
        writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, screenBounds.width, screenBounds.height);

        long startTime = System.nanoTime();

        for (int i = 0;  i < SECS_TO_RUN_FOR * FRAME_RATE; i++){
            //take screenshot
            BufferedImage screen = getScreenshot();

            //convert image to right type
            BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_4BYTE_ABGR);

            //encode image to stream
            writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);

            try{
                Thread.sleep((long)(1000/FRAME_RATE));
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        }
        writer.close();
    }

    public static BufferedImage convertToType(BufferedImage sourceImg, int targetType){
        BufferedImage img;

        if (sourceImg.getType() == targetType){
            img = sourceImg;
        }else{
            img = new BufferedImage(sourceImg.getWidth(), sourceImg.getHeight(), targetType);
            img.getGraphics().drawImage(sourceImg, 0, 0, null);
        }
        return img;
    }

    private static BufferedImage getScreenshot(){
        try{
            Robot robot = new Robot();
            Rectangle capSize = new Rectangle(screenBounds); ...
sirlink99 56 Practically a Master Poster

Hello Everyone,

I am experiencing errors when trying to compile a project in Java 8. The errors are caused by swing components. The code I am using is the following:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Main2 {

    public Main2(){
        JFrame f = new JFrame ();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(100, 100);
        JPanel p = new JPanel();
        JLabel l = new JLabel("Test");
        p.add(l);
        f.add(p);

        f.setVisible(true);

    }

    public static void main(String[] args) {
        new Main2();
    }

}

The problems are caused by the p.add(l) and the f.add(p). They throw a The method add(JLabel) is undefined for the type JPanel and a The method add(Component) in the type Container is not applicable for the arguments (JPanel) error respectively. I have tried cleaning the project, and I have searched through all the solutions online and none of them worked. If I change f.add(p) to f.getRootPane().add(l) then it throws a The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files. I have tried reinstalling the JDK, but I still have no success.

If I change the version of the JDK to 1.7 then the code works prefectly fine. The error is just with Java 8.

The exact versions of JDK I am using is 1.8.0_45 and 1.7.0_11

Thank you for any help.

@Slavi

I am not trying to split by every instance of a certain set of characters. I am just looking to break each of the characters apart into its components.

@JamesCherrill

I took a look at the character class, but the only seemingly useful information to me was the isIdeographic method, and it does not achieve what I am looking to do, although thanks for the suggestion. I will probably be able to make some use out of that later.

Let me try re-explaining what I am trying to achieve. For example, if I have the word , I would like to split it into , the character in the top left, , the character in the top right, and , the character on the bottom (the characters that make up the word). Since Korean characters are made up by combining different characters, the entire character code changed. In order to write that character you need to write ㅈ,ㅣ,ㅂ, in order without the commas. From this website you can see how the characters are combined and given different character values. So, as I am typing the character would go from UTF-8 code: E38588 to ECA780 to ECA791. When splitting the character apart I would like to get a character array containing the characters with the codes: E38588, E385A3 and E38582. I hope this clarified a bit.

If you have any other questions then please ask.

Thank you for your help!

sirlink99 56 Practically a Master Poster

Hello Everyone.

I am wondering if anyone has any experience working with Korean characters. I attempted to find out how to split them up, but I have had no success thus far. What I was thinking is having a character like "안" and having it split up into "ㅇ", "ㅏ"and "ㄴ". I am not sure if this exists in Java. If not, then I will have to make a table myself. If anyone has any idea how to accomplish this, then some simple guidance would be appreciated.

Thanks for the help.

PS: This is just a side project in case anyone was wondering

ok. First there are several thing I would like to point out. When you are summing you set the number at I equal to the sum at I. What you want to do is create another variable outside of the loop, and add the number at the I value to the sum variable. Second you will want to take a look at 2D arrays also to traverse the 2D array you will need a nested for loop (a for loop inside of the for loop) and make sure you don't use the same counter. You will also want to print out the sum after your outer for loop has completed.

I hope this helps

As you have not shown any work I cannot provide you with any specific examples, however you will want to take a look at the Random class and arrays

Please show the work you have done and ask a specific question to get more helpful results.

sirlink99 56 Practically a Master Poster

Good Day. I am currently running into a problem. I have 2 activities. My first activity launches the second one. Once the second one has done some work it calls the finish() method in order to destroy itself. Then my previous activity pops up which is what I would like, however when the first activity pops back up it does not seems to activate any of the methods (onCreate(), onResume, onRestart, onStart). I have all the methods included and logged if they have been executed, which they have not been. What could be the problem?

Thank you for your time.

Forgot to include the method to bring up the menu in my java code.

sirlink99 56 Practically a Master Poster

Good Day. I am relatively new to android programming and I am having problems displaying action Items on my action bar. I can manipulate my actionbar through Java code (show and hide text, Icon and action bar), however when I try to add my own images to the action bar they don't show up. I know it recognizes at least one of the png images as it shows up in android studop, however when I run the code it doesn't display. Is there any java code that I need to insert in order for this to happen?

Here is my xml code:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/add_icon"
        android:title="Add Contact"
        android:icon="@drawable/add"
        android:orderInCategory="0"
        android:showAsAction="ifRoom"/>
    <item
        android:id="@+id/setting_icon"
        android:title="Preferences"
        android:icon="@drawable/pref"
        android:orderInCategory="0"
        android:showAsAction="ifRoom"/>

</menu>

The xml is in the res/menu folder.

Thanks for any help that can be provided. (I am using API 11+ so there is no need for the support library)

Thanks for the help I couldn't manage to get it working correctly. I will try to create my custom tree class that I can test and use without having all the constraints of the assignment to worry about.

The new code for delete without the key is

public static Node delete(Node n){
        if (n == null)
            return n;

        if (("" + n.getPayload().charAt(0)).matches("[aeiouAEIOU]")){
            //System.out.println("In if with: " + n.getPayload());
            if (n.goLeft() != null && n.goRight() != null){
                Node s = successor(n);
                n.takeOver(s);
                delete(s);
                n.setRight(delete(n.goRight()));
                n = delete(n); // verifies that an element starting with a vowel did not replace the node

            }
            else
                if(n.goLeft() != null)
                    n = n.goLeft();
                else 
                    n = n.goRight();
        }
        try{
            n.setLeft(delete(n.goLeft()));
        }catch(NullPointerException e){}
        try{
            n.setRight(delete(n.goRight()));
        }catch(NullPointerException e){}

        return n;
    }

Which produces the output of

2 (2), BST (7), C (2), Consider , Delete , Find (2), Key , Key , Repeat , Repeat , String , The (3), When , You (2), Your , be (3), be (3), both , brackets , by , calculate , can , compare , compared , configuration , conserve , count (2), deletion , during , field , field , field , followed , following , for (4), format , from , function , g , going , has , just , just , just , length , like , line , multiple (2), node , number , paper , paper , paper , parallel , path , per , preceding , print , printing , process , programs , recursive , recursively (2), relative , removal , represent , represents , should (5), so , space , standard (2), storing , succeed , support , systems , the (21), then , there , thus , to ...

the role of the 2 argument delete was an attempt at fixing the problem by passing in the string which was the string of the node that replaces it, and then using it to delete the node which replaced it from the bottom of the tree. It worked once for the word "Key" and one for "field", but it didn't for repeat or the other copy of field and I have no idea why.

Thanks for the reply. I managed to get my deletion working to some degree where now it deletes all the words begninning with a vowel, however now I have run into the problem where words are duplicating. This is the output that I get from my code after I delete

2 (2), BST (7), C (2), Consider , Delete , Find (2), Key , Repeat , Repeat , String , The (3), When , You (2), Your , be (3), be (3), both , brackets , by , calculate , can , compare , compared , configuration , conserve , count (2), deletion , during , field , field , followed , following , for (4), format , from , function , g , going , has , just , just , length , like , line , multiple (2), node , number , paper , paper , parallel , path , per , preceding , print , printing , process , programs , recursive , recursively (2), relative , removal , represent , represents , should (5), so , space , standard (2), storing , succeed , support , systems , the (21), then , there , thus , to (3), traversal , tree (4), trees , variable , well , when , where (2), which (2), will (2), with , word (2), words , work , write , you (2), 

As you can see some words repeat ("Repeat" and "field"). Here is my new delete code

public static ...
sirlink99 56 Practically a Master Poster

I am having a problem deleting nodes from my Binary search tree. What I have so far does part of what it is supposed to do. I read in an input (paragraph of text) to create the tree (organized via ASCII character values). I make it, then print out all the elements. Then I need to delete the ones that begin with a vowel. MY algorithm deletes most of the ones that start with a vowel, but I believe that as it replaces values with other ones some of the words slip through. Here is my class. it is quite a bit of code, but the deletion part is from lines 43-81

package assign2;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        Node binRoot = null, avlRoot = null;
        try {
            Scanner s = new Scanner (new File("Files/input.txt"));
            s.useDelimiter("\\W");
            while (s.hasNext()){
                String st = s.next();

                binRoot = addbin(binRoot, st);
                avlRoot = insertavl(st, avlRoot);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.print("BST: ");
        printInOrder(binRoot);
        System.out.println("\n");
        System.out.print("AVL: ");
        printInOrder(avlRoot);
        System.out.println("\n");
        System.out.print("DBST ");
        binRoot = delete(binRoot);
        printInOrder(binRoot);
        //System.out.println(avlRoot.getPayload());
        //printTree(root);
    }

    public static Node delete(Node n){
        if (n == null)
            return n;

        if (("" + n.getPayload().charAt(0)).matches("[aeiouAEIOU]")){
            if (n.goLeft() != null && n.goRight() != null){
                n.takeOver(successor(n));
                n.setRight(delete(n.goRight()));
            }
            else
                if(n.goLeft() != null)
                    n = n.goLeft();
                else 
                    n = n.goRight();
        }
            try{
                n.setLeft(delete(n.goLeft()));
            }catch(NullPointerException e){}
            try{
                n.setRight(delete(n.goRight()));
            }catch(NullPointerException e){}

        return n;
    }

    private static Node successor(Node n) {
        if (n.goRight() != null){
            n = n.goRight(); ...

First of all when the button is pressed you want to make a connection to the database you are storing the information to. You would probably use JDBC to accomplish this. Then you would proceed to retrieve the data and store it in the correct fields through the connection. Once all the data has been written you will close the stream. Take a look at these examples.

Example 1
Example 2

This should help you get started.

sirlink99 56 Practically a Master Poster

Hello. I am designing a calculator app as part of a project. I have all the buttons inserted in the correct order. My problem is that the last column of buttons horizontally fills up the rest on the unused screen. As the device size scales, the more and more the buttons strech. I would like it so that all the buttons take on the excess space evenly. What would be the easiest way to accomplish this? What commands should I be looking at. If you need the code I can post it later, however I would prefer not to post it. Thank you for your help.

Here are 2 screenshots:
Nexus 4
Nexus 7

That is what I will end up doing if I can't figure out what the problem is.

Any other suggestions?

I have tried formatting the drive, but since it detects that there is no usb drive inserted (it only detects that something is inserted) I can't. It gives me the please insert a USB Drive message when I try.

sirlink99 56 Practically a Master Poster

Hello.

I have just purchased a Lexar JumpDrive S50 32 gigs and I am having trouble accessing the USB. The USB shows up in the my computer window with a grayed out icon and when I double click it it states "Please insert a drive". The same statement is displayed when I try to format it. I am using a Windows 8 as my main computer, but I have tried it on a windows vista and windows 7.

So far I have tried updating the drivers (through device manager and through Lexar's website). I have also reinstalled the usb drivers. I have tried changing the drive letter assigned. I have also changing usb ports and wiggling the usb in hopes that it is just a contact problem. None of the above worked. What else may be causing this problems, and what are possible solutions?

Thank you for your help.

use a while loop and check if the string matches the wtwo options.