Search Results

Search found 834 results on 34 pages for 'looping'.

Page 21/34 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • C# DateTime.ParseExact throwing format exception

    - by Rob
    I'm developing an .NET4 webapplication using MVC3. Let's say i'm getting the following DateTime as string from an XML-feed. The xml feed is being read by my application and i'm looping through all it's descendants. The DateTime i'm receiving is begin returned in the following format (as string); var myDateTime = "Sun Dec 19 11:45:45 +0000 2010" I'm using the piece of code below to try and parse the DateTime string i mentioned above to a valid DateTime format (preferably dutch) var CorrectDateTime = DateTime.ParseExact(myDateTime , "dd MMM yyyy HH:mm:ss", CultureInfo.InvariantCulture); When trying to execute this code i'm facing an formatexception. Somebody has got any ideas?

    Read the article

  • MS SQL Server Dates Excel

    - by KillerSnail
    I have data this is linked from SQL Server into an excel document. The column format on the SQL Server is datetime2. When I get the data via an ODBC connection it comes across as a string? I tried using CAST(column AS DATE ) but that didn't work. I tried reformatting via CONVERT(VARCHAR(10), column, 103) as well but that didn't work. I tried retrieving the data via Microsoft query as well but that didn't work. At the moment I am using VBA code like: While (ActiveCell.Value <> "") ActiveCell.Value = DATEVALUE(ActiveCell.Value) ActiveCell.Offset(1,0).Activate Wend and looping through each column that needs this treatment but 100000 rows in multiple columns takes forever to loop through. Are there any alternatives?

    Read the article

  • How do you get the ID of a control in ASP.NET

    - by James
    I am attempting to loop through an array of numbers, match them to the checkbox they they are associated with, and checkmark that box. My checkbox is set up like: <input type="checkbox" runat="server" id="someID" name="somename" value="1234" /> My code when the page loads currently looks like: foreach (string interest in interests_Var){ foreach (var c in Page.Controls) { } } interests_Var is my array containing different numbers. We'll assume one of them is 1234. While looping through the page controls, I want to compare the value of the control to my number. If it equals my number, I want to then apply the attribute checked="checked". I'm assuming I have to find the ID of the control I am using, then use that ID to add a new attribute. Or is there a way I can add the attribute using the c variable? I'm not dead set on this setup, so if you know a better way, I'm all ears. Thanks for any help and suggestions.

    Read the article

  • How to fix this IndexOutOfBoundsException

    - by Rida
    My program runs fine, but there is a little problem. When I add new tracks previously existing file to the ListBox, the program experiences an error. The code seems unwilling to do looping in a new file which was added in a different time. Please help me. Thanks .... public partial class Form1 : Form { //... string[] files, paths; private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { files = openFileDialog1.SafeFileNames; paths = openFileDialog1.FileNames; for (int i = 0; i < files.Length - 1; i++) { listBox1.Items.Add(files[i]); } } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { axWindowsMediaPlayer1.URL = paths[listBox1.SelectedIndex]; } }

    Read the article

  • findBy(x) Using Zend_Navigation with custom route

    - by Stephen
    I am creating my navigation from a db generated array and defining which route to use for some of the uris. when I set the route i am no longer able to use findByUri() as the uri seems to be moved under the properties key example array being used: [id] => 7 [label] => Legal [controller] => index [uri] => /legal [route] => cmsPage [visible] => 1 [params] => Array ( [first] => legal ) snippet of the output: [_properties:protected] => Array ( [uri] => /legal [created] => 2012-10-20 10:23:23 ) When I don't define the route I am able to use findByUri() successfully. currently I am looping through each to find the property that matches the request but it seems a long / wrong approach Is there a way to search by the nested param - or am i doing something wrong with the setup (everything else behaves as expected)

    Read the article

  • Hiding result sets from multiple selects in a stored procedure

    - by Josh Young
    I have a stored procedure that retrieves SQL queries as text and executes the statements using sp_executesql. Each of the dynamic queries is a count query in that it only returns the number of records found (select COUNT(id) from...). I am looping through a set of SQL queries stored as text and building a table variable out of the results. At the end, I am selecting all the results from the table variable as the result set that I want returned from the stored procedure. However, when I execute the stored procedure, I am naturally getting multiple result sets (one for each of the dynamic queries and one for the final select.) Is there any way I can suppress the results of a select statement executed through sp_executesql? I have found answers that reference storing the results in a temp table, but I don't have control of the query text that I am running so I can't change it to select into anything. Please help. Thank you for your time.

    Read the article

  • Adding Values to a Byte Array

    - by rross
    I'm starting with the two values below: finalString = "38,05,e1,5f,aa,5f,aa,d0"; string[] holder = finalString.Split(','); I'm looping thru holder like so: foreach (string item in holder) { //concatenate 0x and add the value to a byte array } On each iteration I would like to concatenate a 0x to make it a hex value and add it to a byte array. This is what I want the byte array to be like when I finish the loop: byte[] c = new byte[]{0x38,0x05,0xe1,0x5f,0xaa,0x5f,0xaa,0xd0}; So far all my attempts have not been successful. Can someone point me in the right direction?

    Read the article

  • Get only Excel column names in C#

    - by Newbie
    Is there any easy way apart from ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+fileName+";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'"; using (objConn = new OleDbConnection(ConnectionString)) { objConn.Open(); Logger.Info("Reading the file "+fileName+"...."); objCmdSelect = new OleDbCommand("SELECT * FROM [" + sheetName + "$] WHERE 0 = 1", objConn); objAdapter = new OleDbDataAdapter(); objAdapter.SelectCommand = objCmdSelect; objDataset = new DataSet(); Logger.Info("Filling the dataset...."); objAdapter.Fill(objDataset, fileName); Logger.Info("Returning the dataset...."); return objDataset; } and then looping the datatables for getting the excel column names given a filename and sheet name? Using C#(and no interop services) Thanks

    Read the article

  • Java - Optimize finding a string in a list

    - by Mark
    I have an ArrayList of objects where each object contains a string 'word' and a date. I need to check to see if the date has passed for a list of 500 words. The ArrayList could contain up to a million words and dates. The dates I store as integers, so the problem I have is attempting to find the word I am looking for in the ArrayList. Is there a way to make this faster? In python I have a dict and mWords['foo'] is a simple lookup without looping through the whole 1 million items in the mWords array. Is there something like this in java? for (int i = 0; i < mWords.size(); i++) { if ( word == mWords.get(i).word ) { mLastFindIndex = i; return mWords.get(i); } }

    Read the article

  • Transform LINQ Dataset into a Matrix for export

    - by Mad Halfling
    Hi folks, I've got a data table with columns in which include Item, Category and Value (and others, but those are the only relevant ones for this problem) that I access via LINQ in a C# ASP.Net MVC app. I want to transform these into a matrix and output that as a CSV file to pull into Excel as matrix with the items down the side, the categories across the top and the values in the row cells. However, I don't know how many, or what, categories there will be in this table, nor will there always be a record for each item/category combination. I've written this by looping round, getting my "master category" list, then looking again for each item, filling in either blank or Value, depending on whether the item/category record exists, but as there are currently 27000 records in the table, this isn't as fast as I'd like. Is there a slicker and faster way I can do this, maybe via LINQ (firing into a quicker SQL statement so the DB server can do the leg-work), or will any method essentially come back to what I am doing? Thx MH

    Read the article

  • C++ volatile required when spinning on boost::shared_ptr operator bool()?

    - by JaredC
    I have two threads referencing the same boost::shared_ptr: boost::shared_ptr<Widget> shared; On thread is spinning, waiting for the other thread to reset the boost::shared_ptr: while(shared) boost::thread::yield(); And at some point the other thread will call: shared.reset(); My question is whether or not I need to declare the shared pointer as volatile to prevent the compiler from optimizing the call to shared.operator bool() out of the loop and never detecting the change? I know that if I were simply looping on a variable, waiting for it to reach 0 I would need volatile, but I'm not sure if boost::shared_ptr is implemented in such a way that it is not necessary here.

    Read the article

  • exporting html table multi line columns to excel multi line cells

    - by Passat
    I have a html table in a view MVC4 that I am sending to excel as output. Inside the view page I have some columns that have multiple lines that are built with forloops within the HTML. What's the best way to add the or \r\n so that excel renders it correctly? I have a table and inside I build each row looping thru a recordset. In each row I also loop thru different recordsets to populate columns within each row so that some of the columns may contain more than one value and they should show in different lines in the table that will export to excel.

    Read the article

  • How can I find all records for a model without doing a long list of "OR" conditions?

    - by gomezuk
    I'm having trouble composing a CakePHP find() which returns the records I'm looking for. My associations go like this: User -(has many)- Friends , User -(has many)- Posts I'm trying to display a list of all a user's friends recent posts, in other words, list every post that was created by a friend of the current user logged in. The only way I can think of doing this is by putting all the user's friends' user_ids in a big array, and then looping through each one, so that the find() call would look something like: $posts = $this->Post->find('all',array( 'conditions' => array( 'Post.user_id' => array( 'OR' => array( $user_id_array[0],$user_id_array[1],$user_id_array[2] # .. etc ) ) ) )); I get the impression this isn't the best way of doing things as if that user is popular that's a lot of OR conditions. Can anyone suggest a better alternative?

    Read the article

  • MySql returning multiple rows from stored procedure / function

    - by pistacchio
    Hi, I need to make a stored procedure or function that returns a set of rows. I've noted that in a stored procedure i can SELECT * FROM table with success. If i fetch rows in a loop and SELECT something, something_other FROM table once per loop execution, I only get one single result. What I need to do is looping, doing some calculations and returning a rowset. What's the best way to do this? A temporary table? Stored functions? Any help appreciated.

    Read the article

  • Add columnname and data from datatable to a dictionary? C#

    - by Nick
    Hi, I am looping through a datatable and currently I do string customerId = row["CustomerId"].ToString(); string companyName = row["Company Name"].ToString(); Instead of declaring every variable how do I add these do a dictionary? I was thinking something like: foreach (DataRow row in customerTbl.Rows) { Dictionary<string, string> customerDictionary = new Dictionary<string, string>(); customerDictionary.Add(row[].ToString(), row[].ToString()); so yeah, how do I get the row name and value into there? Thanks in advance.

    Read the article

  • How do I make a multiple file upload?

    - by Bluemagica
    I am trying to make a multiple image uploader. The file upload fields are being added in the form dynamically using jquery. I tried making an array of the fields since I don't want to have a hidden field. so my generated upload fields look like <input type="file" id="img0" name="img[]"/> <input type="file" id="img1" name="img[]"/> <input type="file" id="img2" name="img[]"/> ..... .. And on the php side I did something like if(isset($_FILES['img'])) { foreach($_FILES['img'] as $k=>$v) { if($v!="") { uploadImage($k,0,0,0,"content/gallery/"); } } } Now I know I am way too wrong, since in that code I am looping through the 'img' file's properties instead of all images....but I have no idea how to fix this. PS: uploadImage is a function I wrote which expects the file input field's name as the first parameter.

    Read the article

  • Json object merge with unqiue id

    - by Hitu
    I have multiple json Objects json1 = [ {'category_id':1,'name':'test1' }, {'category_id':1,'name':'test2' }, {'category_id':1,'name':'test3' }, {'category_id':2,'name':'test2' }, {'category_id':3,'name':'test1' } ]; json2 = [{'category_id':1,'type':'test1'}]; json3 = [ {'category_id':1,'color':'black'}, {'category_id':2,'color':'black'}, {'category_id':3,'color':'white'} ]; I am expecting output like this final = [ {'category_id':1,'name':'test1','type':'test`','color':'black' }, {'category_id':1,'name':'test2','type':'test`','color':'black' }, {'category_id':1,'name':'test3','type':'test`','color':'black' }, {'category_id':2,'name':'test2','color':'black' }, {'category_id':3,'name':'test1','color':'white' } ]; As i have long json object. Looping is good idea or not ? Does there is any inbuilt function for doing the same.

    Read the article

  • Is there a way to optimise finding text items on a page (not regex)

    - by Jeepstone
    After seeing several threads rubbishing the regexp method of finding a term to match within an HTML document, I've used the Simple HTML DOM PHP parser (http://simplehtmldom.sourceforge.net/) to get the bits of text I'm after, but I want to know if my code is optimal. It feels like I'm looping too many times. Is there a way to optimise the following loop? //Get the HTML and look at the text nodes $html = str_get_html($buffer); //First we match the <body> tag as we don't want to change the <head> items foreach($html->find('body') as $body) { //Then we get the text nodes, rather than any HTML foreach($body->find('text') as $text) { //Then we match each term foreach ($terms as $term) { //Match to the terms within the text nodes $text->outertext = str_replace($term, '<span class="highlight">'.$term.'</span>', $text->outertext); } } } For example, would it make a difference to determine check if I have any matches before I start the loop maybe?

    Read the article

  • How to remove an item from a structure array in C++?

    - by Antik
    I have the following array structure (linked list): struct str_pair { char ip [50] ; char uri [50] ; str_pair *next ; } ; str_pair *item; I know to create a new item, I need to use item = new str_pair; However, I need to be able to loop through the array and delete a particular item. I have the looping part sorted. But how do I delete an item from an array of structures?

    Read the article

  • android listview loadmore button with xml parsing

    - by user1780331
    Hi i have to developed listview with load more button using xml parsing in android application. Here i have faced some problem. my xml feed is empty means how can hide the load more button on last page. i have used below code here. public class CustomizedListView extends Activity { // All static variables private String URL = "http://dev.mmm.com/xctesting/xcart444pro/retrieve.php?page=1"; // XML node keys static final String KEY_SONG = "Order"; static final String KEY_TITLE = "orderid"; static final String KEY_DATE = "date"; static final String KEY_ARTIST = "payment_method"; int current_page = 1; ListView lv; LazyAdapter adapter; ProgressDialog pDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lv = (ListView) findViewById(R.id.list); ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML from URL Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_SONG); // looping through all song nodes <song> for (int i = 0; i < nl.getLength(); i++) { // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); Element e = (Element) nl.item(i); // adding each child node to HashMap key => value map.put(KEY_ID, parser.getValue(e, KEY_ID)); map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE)); map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST)); songsList.add(map); } Button btnLoadMore = new Button(this); btnLoadMore.setText("Load More"); btnLoadMore.setBackgroundResource(R.drawable.lgnbttn); // Adding Load More button to lisview at bottom lv.addFooterView(btnLoadMore); // Getting adapter adapter = new LazyAdapter(this, songsList); lv.setAdapter(adapter); btnLoadMore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // Starting a new async task new loadMoreListView().execute(); } }); } private class loadMoreListView extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { // Showing progress dialog before sending http request pDialog = new ProgressDialog( CustomizedListView.this); pDialog.setMessage("Please wait.."); //pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.my_progress_indeterminate)); pDialog.setIndeterminate(true); pDialog.setCancelable(false); pDialog.show(); pDialog.setContentView(R.layout.custom_dialog); } protected Void doInBackground(Void... unused) { current_page += 1; // Next page request URL = "http://dev.mmm.com/xctesting/xcart444pro/retrieve.php?page=" + current_page; ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML from URL Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_SONG); NodeList nl = doc.getElementsByTagName(KEY_SONG); if (nl.getLength() == 0) { btnLoadMore.setVisibility(View.GONE); pDialog.dismiss(); } else // looping through all item nodes <item> for (int i = 0; i < nl.getLength(); i++) { // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); Element e = (Element) nl.item(i); // adding each child node to HashMap key => value map.put(KEY_ID, parser.getValue(e, KEY_ID)); map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE)); map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST)); songsList.add(map); } // get listview current position - used to maintain scroll position int currentPosition = lv.getFirstVisiblePosition(); // Appending new data to menuItems ArrayList adapter = new LazyAdapter( CustomizedListView.this, songsList); lv.setAdapter(adapter); lv.setSelectionFromTop(currentPosition + 1, 0); } }); return (null); } protected void onPostExecute(Void unused) { // closing progress dialog pDialog.dismiss(); } } } EDIT: Here i have to run the app means the listview is displayed on perpage 4 items.my last page having 1 item.please refer this screenshot:http://screencast.com/t/fTl4FETd In last page i have to click the load more button means have to go next activity and successfully hide the button on empty page..please refer this screenshot:http://screencast.com/t/wyG5zdp3r i have to check the condition for empty page: if (nl.getLength() == 0) { btnLoadMore.setVisibility(View.GONE); pDialog.dismiss(); } How can i write the conditon fot last page?????pleas ehelp me Here i wish to need the o/p is hide the button on last page. Please help me.how can i check the condition.give me some code programmatically.

    Read the article

  • AS3 Random repeat x seconds function

    - by Lilk
    Hi, I have the following function: function update(e:Event):void { var val:Number = Math.random() * 120; rgb.r.x = rgb.r.y = val; rgb.b.x = rgb.b.y = -val; } And im looping it with: stage.addEventListener(Event.ENTER_FRAME, update); But what I need to do would be something like: Random number between 1 and 20 If the number is > 10 Call function Update and keep caling it for 20 seconds else do nothing for 10 seconds Repeat this block of code forever Can someone help me write this please?

    Read the article

  • Problems to make programming more interesting for school students [closed]

    - by Jomoos
    I have to teach Java programming to school students and all are around the age of 15. None of them had any previous experience in programming. That is, I have to start from the very basics. I do like to make the sessions more interesting, and to make them love programming. I do need simple problems or puzzles -- not complex ones, simple ones -- that can increase their curiosity, and made them think and love programming. I do like to have problems for all of the concepts (like branching, looping, encapsulation, inheritance, composition, etc.,). Notes: I do have a time-frame of 1 hour for each session. Computers are not available. Maybe I can bring my laptop and show a demo to them. There are 7 students in the class.

    Read the article

  • How to ignore an exception and continue processing a foreach loop?

    - by Barry Dysert
    I have a test program that is supposed to loop over all the files under C:. It dies when it hits the "Documents and Settings" folder. I'd like to ignore the error and keep looping over the remaining files. The problem is that the exception is thrown in the foreach, so putting a try/catch around the foreach will cause the loop to exit. And putting a try/catch after the foreach never fires (because the exception is thrown in the foreach). Is there any way to ignore the exception and continue processing the loop? Here's the code: static void Main(string[] args) { IEnumerable<string> files = Directory.EnumerateFiles(@"C:\", "*.*", SearchOption.AllDirectories); foreach (string file in files) // Exception occurs when evaluating "file" Console.WriteLine(file); }

    Read the article

  • Getting data from the next row in Oracle cursor

    - by Chaotic_one
    Hi, I'm building nested tree and I need to get data for the next row in cursor, using Oracle. And I still need current row, so looping forward is not a solution. Example: OPEN emp_cv FOR sql_stmt; LOOP FETCH emp_cv INTO v_rcod,v_rname,v_level; EXIT WHEN emp_cv%NOTFOUND; /*here lies the code for getting v_next_level*/ if v_next_level > v_level then /*code here*/ elsif v_next_level < v_level then /*code here*/ else /*code here*/ end if; END LOOP; CLOSE emp_cv;

    Read the article

  • How to yield a single element from for loop in scala?

    - by Julio Faerman
    Much like this question: Functional code for looping with early exit Say the code is def findFirst[T](objects: List[T]):T = { for (obj <- objects) { if (expensiveFunc(obj) != null) return /*???*/ Some(obj) } None } How to yield a single element from a for loop like this in scala? I do not want to use find, as proposed in the original question, i am curious about if and how it could be implemented using the for loop. * UPDATE * First, thanks for all the comments, but i guess i was not clear in the question. I am shooting for something like this: val seven = for { x <- 1 to 10 if x == 7 } return x And that does not compile. The two errors are: - return outside method definition - method main has return statement; needs result type I know find() would be better in this case, i am just learning and exploring the language. And in a more complex case with several iterators, i think finding with for can actually be usefull. Thanks commenters, i'll start a bounty to make up for the bad posing of the question :)

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >