How can I loop through a Vector and compare

I'm working on a school project that is a quiz server. Instructors could telnet into the app and create quizes and then users can take them. I have it so it can set up new quizes so far. Right now I'm working on it so the user can choose a quiz and take the test. Since it requires proper user handling I have it so I display the quiz ID and quiz Name. The user would need to enter the quiz ID to take it. I have it that as it displays the ID's it enters them into a Vector. Then I do a loop through all elements until I get one that equals the user selection. I'm having problems with it though. Here's some code:
do
quizCheck = false;
for (int i=0;quizReference.size();i++)
if (selectionInt==quizReference.elementAt(i))
quizCheck=true;
}while (quizCheck==false);
It's giving me a Error #300:method==(int,java,lang.Object)not found in class testproject.TestProject on the if line. Is there a way to handle this scenario. Also is there a better way?

Hi,
elementAt(...) returns an Object - of what type is your selectionInt? - guess, it is a primitve int value, not an Object.
You can find it easier - say, you have Integer values in that Vector - and selectionInt is an int value - now you can find it using
int p = quizReference.indexOf(new Integer(selectionInt));
p is either -1 (if not found) or the index of the first found element, with the same int value as selectionInt.
Hope, this helps
greetings Marsian

Similar Messages

  • How can I put a stl::vector string into the DB and then get it out?

    Hello,
    As the title, here's a test case with problems,but anyway you can still run it. ( VC6/XP-32/BDB 4.7 )
    I know this may be wrong,and I'd like to know how can I do this.
    Can someone help me please? I would appreciate it very much.
    ************ Copy,Compile and Run ***************
    #include <iostream>
    #include <vector>
    #include "db_cxx.h"
    int main()
         std::string dbName("database.db");
         u_int32_t db_flags=DB_CREATE;
         Db* db=NULL;
         // Prepare key(int)/data(vector<string>) pair.
         int int_key=2;
         std::vector<std::string> rec_data;
         rec_data.push_back("apple");
         rec_data.push_back("Bob");
         rec_data.push_back("Me");
         // Prepare Dbt for receiving.
         std::vector<std::string> rec_readData;
         Dbt readData;
         readData.set_data(&rec_readData);
         readData.set_ulen(sizeof(rec_readData));
         readData.set_flags(DB_DBT_USERMEM);
         try
              // Open database.
              db = new Db(NULL,0);
              db->open(NULL,dbName.c_str(),NULL,DB_BTREE,db_flags,0);
              // Put
              int ret;
              if(ret=db->put(NULL,new Dbt(&int_key,sizeof(int_key)),new Dbt(&rec_data,sizeof(rec_data)),DB_NOOVERWRITE)==0)
                   std::cout<<"put successful!"<<std::endl;
              else { db->err(ret,"Db->put"); }
              // Get
              if(ret=db->get(NULL,new Dbt(&int_key,sizeof(int_key)),&readData,0)==0)
                   std::cout<<"get successful!"<<std::endl;
              else { db->err(ret,"Db->get"); }
         catch(DbException &e)
              std::cerr<<"Error: ";
              std::cerr<<e.what()<<std::endl;
         // Close the database
         try
              if(db!=NULL)
                   db->close(0);
         catch(DbException &e)
              std::cerr<<"Error closing database: ";
              std::cerr<<e.what()<<std::endl;
         // Display the results.
         // Index out of bounds. <-----
         std::cout << rec_readData[0].c_str();
         std::cout << rec_readData[1].c_str();
         std::cout << rec_readData[2].c_str();
         system("pause");
         // Press any key to go wrong. :(
         return 0;
    Regards,
    legendsino

    You need to convert the std::vector<std::string> into a sequence of bytes. For example, if all strings are shorter than 256 characters, you could create a fresh output string, iterator through the vector, and for each element, append the string length to the output string, followed by the string contents.
    Note that ordering in the database will be different from lexicographic order, and you have to keep that in mind when performing range queries.

  • How to Loop through another list and update a column with SharePoint Designer 2013 Workflow

    Hi,
    I am trying to get my head around the new 2013 Workflow Engine and SharePoint Designer 2013 Workflow Text-Based Designer.
    I have two lists.
    List A has 2 columns: Title, Completed (Yes/No)
    List B has 3 columns: Title, LookupListATitle, Completed (Yes/No)
    All the 2013 Workflow components have been installed and configured and I am selecting the 2013 Workflow option in SPD
    I am trying to set off a 2013 Workflow when an item in List A is edited to Loop through List B and select items where the LookupListATitle column's value is equal to the Title value of the current item, and set the value of the Completed column for those
    items in ListB to "Yes".
    I have the Workflow configured like this:
    Stage: Stage 1
    IF Current Item:Completed equals Yes
    Loop: 1
    The contents of this loop will run repeatedly while: ListB:LookupListATitle equals Current Item: Title
    Update item in ListB. 
    (The dialog options for the update item action as follows:
    List: ListB
    Field: Completed, Value: Yes
    In the Find the List Item section
    Field: LookupListATitle
    Value: Current Item: Title)
    Transition to stage
    Go to End of Workflow
    When I update an item in ListA and set its Completed column to Yes, I would expect the Workflow to find all the items in List B where the Lookup column is equal to ListA's Title (there are 2) and update their Completed column to Yes. But it doesn't work.
    When I look at the Workflow Status it says the Internal Status is "Canceled" and the information pop up has the following alien language (and may be truncated):
    RequestorId: 95f03b62-8956-ac14-c5cf-dc98c89c589c. Details: System.ArgumentException: Invalid JSON primitive: Item001. Parameter name: value at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.ConvertStringToJsonNumber(String value) at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.ReadPrimitive(String
    type, XmlDictionaryReader jsonReader) at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.JXMLToJsonValue(XmlDictionaryReader jsonReader) at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.JXMLToJsonValue(Stream jsonStream, Byte[] jsonBytes)
    at Microsoft.Activities.DynamicValue.ParseJson(String json) at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
    executor, BookmarkManager bookmarkManager, Location resultLocation)
    Unfortunately I don't have access to the server, logs etc.
    I would love to find some tutorials, or any books on SharePoint Designer 2013 in general and Workflows in particular but my searches haven't turned up much so far apart from a pre-release Beginning SharePoint Workflows which is in its very early stages and
    not much help yet.
    Can anyone give me some guidance on how to set up While Loops to iterate through a related list using SharePoint Designer 2013?
    Mark

    Hi,
    I understand that you wanted to update the items in the other list (Participants) where the Course equals the Current Item.
    You need to use “Call HTTP Web Service" action and “Build Dictionary" action to get the Maxid and then loop Participants to update the items.
    You can follow the steps as below to achieve what you want:
    Create a custom list named Courses, add columns: Title(Single line of text), Course ID(Single line of text), Course Finalised (Yes/No).
    Create a custom list named Participants, add columns: Title(Single line of text), Course(Lookup), CourseFinalised (Yes/No).
    Create workflow associated to Courses, start the workflow automatically when an item is created or changed.
    Add conditions and actions:
    The HTTP URL is set to
    https://sitename/_api/web/lists/GetByTitle('listname')/items?$orderby=Id%20desc and the HTTP method is set to “GET”. Then the list will be order by Id and desc.
    Then if Course Finalised is equal to Yes, the CourseFinalised  of the associated items in Participants will be updated to Yes.
    More information:
    http://sergeluca.wordpress.com/2013/04/09/calling-the-sharepoint-2013-rest-api-from-a-sharepoint-designer-workflow/
    Thank you for your understanding.
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How can i loop over treeview selected nodes and then to delete each node if it's a directory or a file ?

    I have this code:
    if (s == "file")
    file = false;
    for (int i = 0; i < treeViewMS1.SelectedNodes.Count; i++)
    DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
    I know it's a file and it is working if it's a single file.
    On the treeView i click on a file right click in the menu i select delete and it's doing the line:
    DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
    And it's working no problems.
    But i want to do that if i selected some files togeather multiple selection then to delete each file.
    So i added the FOR loop but then how do i delete from the SelectedNodes each node ?
    The treeView SelectedNodes dosen't have FullPath like SelectedNode also doing SelectedNodes[i] dosen't have the FullPath property.
    Same as for if i want to delete a single directory or multiple selected directories:
    This is the continue of the code if it"s not a "file" (else) it's null i know it's a directory and doing:
    else
    file = true;
    RemoveDirectoriesRecursive(treeViewMS1.SelectedNode, treeViewMS1.SelectedNode.FullPath);
    Also here i'm using SelectedNode but if i marked multiple directories then i how do i loop over the SelectedNodes and send each SelectedNode to the RemoveDirectoriesRecrusive method ?
    My problem is how to loop over SelectedNode(multiple selection of files/directories) and send each selected file/directory to it's method like i'm doing now ?

    foreach (TreeNode n in treeViewMS1.SelectedNodes)
    // Remove everything associated with TreeNode n here
    I don't think it's any harder than that, is it?
    If you can multi-select both an item and one of its descendents in the tree, then you'll have the situation that you may have deleted the parent folder and all of its children by the time you get around to deleting the descendent.  But that's not such
    a big deal.  A file can get deleted externally to your program too - so you'll just have to deal with it having been deleted already (or externally) when you get around to deleting it yourself.

  • I have downloaded a music file through a downloader . But the file is not found in the captured in music player . How can I locate the physical location and move the file . I cannot do via itunes also .

    I have downloaded a music file through a downloader . But the file is not found in the captured in music player . How can I locate the physical location and move the file . I cannot do via itunes also .

    Exactly what do you mean by a 'downloader'?
    Thanks
    Pete

  • I have Outlook 2011 installed on my Mac Pro, but I can not install it icloud. I can only get through imail, iCal and Address Book in Mac native anyone know teach me how to work with Outlook 2011 icloud? thank you

    I have Outlook 2011 installed on my Mac Pro, but I can not install it icloud. I can only get through imail, iCal and Address Book in Mac native anyone know teach me how to work with Outlook 2011 icloud? thank you

    "iCloud requires iOS 5 on iPhone 3GS or later, iPod touch (3rd and 4th generation), iPad, or iPad 2; a Mac computer with OS X Lion; or a PC with Windows Vista or Windows 7 (Outlook 2007 or 2010 or an up-to-date browser is required for accessing email, contacts, and calendars). Some features require a Wi-Fi connection. Some features are not available in all countries. Access to some services is limited to 10 devices."
    From here >  http://www.apple.com/icloud/

  • How can i recover my admin name and password from my i mac. i could not get through to it.

    how can i recover my admin name and password from my i mac. i could not get through to it.

    What do you mean "I could not get through to it" Are you trying to login remotely?

  • Multi-record block (how do I loop through the block)

    I created a two canvas form. On the first canvas, the user enters data and selects 1 - 30
    reports that they want to run. When they click on <NEXT> button, I create a multi-record
    control block and display each record on the second screen using
    go_block;
    clear_block;
    move data;
    create_record;
    The user then selects on the second canvas which reports to run now and which to run later via
    a LOV. When they press the <RUN> button, I want to start at the first record and either run the
    report or schedule it. Then I want to move onto the second and the third until all selected reports
    have been handled. I know I should use a loop but can't seem to make it work.
    So my question is, How do I loop through the records in a multi-record control block, pass the information
    for that one record to a parameter form and then execute the request? Each control block record contains
    10 parameter fields.
    Thanks.
    Bob

    go_record(1);
    << do your processing >> -- This is executed only for the first record.
    if :system.last_record = 'TRUE' then -- If the 1st record is also the last record.
    RETURN;
    end if;
    LOOP
    next_record;
    << do your processing >>
    if :system.last_record = 'TRUE' then
    EXIT;
    end if;
    END LOOP;
    I created a two canvas form. On the first canvas, the user enters data and selects 1 - 30
    reports that they want to run. When they click on <NEXT> button, I create a multi-record
    control block and display each record on the second screen using
    go_block;
    clear_block;
    move data;
    create_record;
    The user then selects on the second canvas which reports to run now and which to run later via
    a LOV. When they press the <RUN> button, I want to start at the first record and either run the
    report or schedule it. Then I want to move onto the second and the third until all selected reports
    have been handled. I know I should use a loop but can't seem to make it work.
    So my question is, How do I loop through the records in a multi-record control block, pass the information
    for that one record to a parameter form and then execute the request? Each control block record contains
    10 parameter fields.
    Thanks.
    Bob

  • How can I start anew with Photos and clear the (minimal) stuff it has uploaded

    I've about had it up to here with this new Photos scheme. I reorganised my Aperture libraries on both my iMac and MBA in preparation for this, delayed turning Photos on for a couple of days until I thought everything was ready based upon the limited advice that was out there, and then got stuck in an endless loop of "uploading" and "preparing" every time I opened Photos. There are 19,975 images in my Aperture library on the iMac. I was stuck at Uploading at anywhere between that number and 19,000 with no progress after hours of waiting. I tried all the tricks mentioned here including re booting, restarting the app, repairing/rebuilding the database, killing the "cloudd" process, etc.today Today when I restarted Photos, it now said I had 23,775 images to upload- 4000
    more than I have-and of course it got stuck there, like it has for the last week.
    I copied the previous Aperture library (pre Photos migration)back to my iMac and opened it in Aperture. Thankfully, all the photos I had taken on my iPhone this week during this Photos clusterphuck transition were in the Aperture Stream so I didn't lose any of those. I'm willing to give this whole thing one more shot. So  i need some advice. How can I start anew with Photos and clear the (minimal) stuff it has uploaded (about 6000 of 19,000 images in the last 7 days) ? If I simply delete the Photos.photolibrary file will that do the trick and lt me start a new fresh library using?
    <Re-Titled By Host>

    How can I start anew with Photos and clear the (minimal) stuff it has uploaded (about 6000 of 19,000 images in the last 7 days) ? If I simply delete the Photos.photolibrary file will that do the trick and lt me start a new fresh library using?
    It is hard to say from your post, why the migration did not succeed in your case.
    by "stuck on upload" do you mean, you opened the Aperture library in Photos, and Photos converted it to a Photo Library, and then the upload to iCloud Photo Library did hang?  Or did already the upgrade to the Photo Library fail?
    If you want the Aperture library to upload to iCloud Photo Library, it needs to be on a disk formatted MacOS Extended (Journaled) and the original image files must not be referenced. Referenced originals will not upload.
    Also, the upload may hang, if you do not have enough free iCloud storage, orr if one of the videos or photos in your library is in an unsupported format or corrupted.
    To start over, try to repair and rebuild the Aperture library before opening it in Photos. Try all Aperture Library First Aid options - starting with repairing the permissions.  (Repairing and Rebuilding Your Aperture Library: Aperture 3 User Manual)
    If I simply delete the Photos.photolibrary file will that do the trick and lt me start a new fresh library using?
    You will have to delete the photos that are already in icloud too; otherwise you are risking duplicates.
    Can you launch Photos at all?  If yes, delete all photos in Photos and empty the Recently Deleted album. Wait for the deletion to sync to iCloud. Then delete the Photos.photolibrary.

  • HT4889 How can I transfer my iPhoto photos and iTunes library to my new iMac?

    How can I transfer my iPhoto photos and iTunes library to my new iMac?

    If the Migration Assistant won't do it, move them over as you would any other folder; they're located in the Pictures and Music folders of your home folder by default. The iPhoto library needs to be transferred via a drive, partition, or disk image formatted as Mac OS Extended or through an AFP network share.
    (72915)

  • How can I delete apps in iTunes and have that sync to my iPhone and iPad?

    How can I delete apps in iTunes and have that sync to my iPhone and iPad? I don't want to delete 3 separate times for each item. I just carefully chose 30-35 apps to get rid of via iTunes, hoping it would sync to my devices, only to find I have to repeat the process on my iPad, take notes, then repeat it on my iPhone. It wasn't always so tedious was it?
    Here's the "Help" I got from Apple. They even quoted my question back to me then proceeded to answer with something very different and completely missing the point.
    I understand that you would like to delete the Apps. I know how eager you are to get the required information and I will be happy to assist you.
    You can remove individual songs, audiobooks, and videos from your iPod, iPhone, or iPad. Removing an item from your device doesn't delete it from your iTunes library.
    To remove items from a device other than an iPod shuffle, first make sure that iTunes is set up to manually manage items.
    1. Connect your iPod, iPhone, or iPad to your computer.
    2. When the iPod, iPhone, or iPad icon appears in iTunes, select it.
    3. Unless your device is an iPod shuffle, click the Summary tab and make sure "Manually manage music and videos" or "Manually manage music" is selected.
    4. If the disclosure triangle to the left of your iPod, iPhone, or iPad (below Devices) is closed, click the triangle so that you can see the device's contents.
    5. Select the item you want to delete and press the Delete key.
    This was not helpful in any way and I am still unable to delete apps on my devices in a global, iTunes based way. Each device still requires its own independent process.

    Match was off.  I made all of the changes and then went through the "Turn on iTunes Match" option.  I now have deleted some tracks, edited the Metadata in CDDA, and then added it back.  This worked fine, but it is not a good solution.
    I just tried making some edits and use the "Update iTunes Match" and that seemed to work.  It looks like the real answer is that Match must be up and operational, then you can make changes and run the Update to incorporate the changes.  However, if Match has a problem then Signing Out and back in to your store account and going through the process of Turning On Match (were you get the questions, "Add this Computer to Match" will overwrite any changes. 
    Since this relies on the stability of iTunes, I won't be making a lot of changes between updates.

  • How can i add a new user and change user'password with javamail?

    how can i add a new user and change user'password from a mailserver with javamail?
    email:[email protected]

    Well user creation and updation is a system property..U need to go through that part...as it depends on the system you are hosting pout your application...
    if it is linux...u have to use some shell programming\
    bye for now let me know if this guides you or if you need some more stuff.
    bye

  • How can I transfer all my music and apps from my computer to my new iphone?

    how can I transfer all my music and apps from my computer to my new iphone?

    This is one of the most basic of functions of the iPhone.  This is a good time for you to read the User Guide.  All the instructions on how to operate yor phone are included.  I suggest you read through it.
    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf

  • InDesign CS5 is not opening after deactivation/activation. How can I fix this? Illustrator and Photoshop open and are working fine. Please help!

    InDesign CS5 is not opening after deactivation/activation. How can I fix this? Illustrator and Photoshop open and are working fine. Please help!

    First of all, thank you for replying so promptly to my posts this morning!
    I can't remember how I got the software on his computer, but I'm pretty sure it wasn't through migration assistant.
    I was looking into doing an uninstall of InDesign and a fresh install. However, I initially downloaded the CS5 suite digitally and I can't find out how I am able to perform a fresh install of InDesign. Do you know where I find this info or gain access to download just InDesign again? I can't seem to find anything in my Adobe account that shows where I might do another download.

  • A friend gave me her VAIO laptop.How can I remove her ITUNES library and use mine which I want to sync with my Ipad and Iphone?

    A Friend gave me her VAIO laptop.How can I remove her ITUNES library and use my library.  Want to sync my Ipad and Iphone to My library.

    I believe when you plug her old iPhone in to your computer it will notify you that the phone is synced with another library and ask if you want to register it with your library.  At least this is how iPods work.  I'm not sure about iPhones.  If you want to actually use the phone as your own you may need to go through AT&T.
    If you're just looking to use the iPhone as an iPod (without the phone portion of it) you may run in to some problems.  The iPhone really wants to be on a cell network all the time.  I think you'd have to jailbreak it to get it to work properly as an iPod.
    Let us know what happens when you plug the phone in to your computer.

Maybe you are looking for