Search Results

Search found 6988 results on 280 pages for 'statement'.

Page 2/280 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why use an OO approach instead of a giant "switch" statement?

    - by James P. Wright
    I am working in a .Net, C# shop and I have a coworker that keeps insisting that we should use giant Switch statements in our code with lots of "Cases" rather than more object oriented approaches. His argument consistently goes back to the fact that a Switch statement compiles to a "cpu jump table" and is therefore the fastest option (even though in other things our team is told that we don't care about speed). I honestly don't have an argument against this...because I don't know what the heck he's talking about. Is he right? Is he just talking out his ass? Just trying to learn here.

    Read the article

  • Are there legitimate uses for JavaScript's "with" statement?

    - by Shog9
    Alan Storm's comments in response to my answer regarding the with statement got me thinking. I've seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I'm curious as to how I might make effective use of with, while avoiding its pitfalls... So my question is, where have you found the with statement useful?

    Read the article

  • if statement in aspx page

    - by Brad
    I want to write a basic if statement on my site to display either item 1 or item 2 depending on if a variable is set to true. I am not to familiar with .Net and need a little help with the basic structure of how to get an if statement to work on the aspx page. thank you for your help.

    Read the article

  • Return number of rows affected by SQL UPDATE statement in Java

    - by Krt_Malta
    I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement("UPDATE user_table SET Level = 'Super' WHERE Username = ?"); prep1.setString(1, username); The update statement above works fine however I'd like to get the number of rows affected with this statement. Is this possible please?

    Read the article

  • Separate clauses of an if statement?

    - by tarnfeld
    Is there any way to have multiple clauses in an if() statement? For instance: if( ($username=='textUser' && $role=='admin') || ($admin=='yes')) { // If the username AND role are set to admin OR if the admin is set to 'yes' } else { // Neither clauses of the if statement are true } Perhaps this is actually the correct code, i have no tried it - but if not, could anyone tell me how? :)

    Read the article

  • MYSQL if statement question...

    - by Dennis_M
    Is there any way to get the if statement to evaluate a query? SELECT if(50,'EQ_Type','*') FROM EQUIPMENT; Resulting in: +-----------------------+ | IF(50,'EQ_Type','*') | +-----------------------+ | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | | EQ_Type | +-----------------------+ 9 rows in set (0.00 sec) I would like the above statement to be equivalent to the following: SELECT 'EQ_Type' FROM EQUIPMENT; And produce: +--------------+ | EQ_Type | +--------------+ | ENGINE | | ENGINE | | ENGINE | | TRAILER | | TRAILER | | TRAILER | | WATER TENDER | | WATER TENDER | | WATER TENDER | +--------------+ Thanks for any help

    Read the article

  • use a sql select statement to get parameters for 2nd select statement

    - by diver-d
    Hi there, I am trying to write a sql statement that I have 2 tables Store & StoreTransactions. My first select command looks like SELECT [StoreID],[ParentStoreID] FROM Store Very simple stuff. How do I take the returned StoreID's and use them for my 2nd select statement? SELECT [StoreTransactionID],[TransactionDate],[StoreID] FROM StoreTransactions WHERE StoreID = returned values from the above query Any help would be great!

    Read the article

  • Performance of VIEW vs. SQL statement

    - by Matt W.
    I have a query that goes something like the following: select <field list> from <table list> where <join conditions> and <condition list> and PrimaryKey in (select PrimaryKey from <table list> where <join list> and <condition list>) and PrimaryKey not in (select PrimaryKey from <table list> where <join list> and <condition list>) The sub-select queries both have multiple sub-select queries of their own that I'm not showing so as not to clutter the statement. One of the developers on my team thinks a view would be better. I disagree in that the SQL statement uses variables passed in by the program (based on the user's login Id). Are there any hard and fast rules on when a view should be used vs. using a SQL statement? What kind of performance gain issues are there in running SQL statements on their own against regular tables vs. against views. (Note that all the joins / where conditions are against indexed columns, so that shouldn't be an issue.) EDIT for clarification... Here's the query I'm working with: select obj_id from object where obj_id in( (select distinct(sec_id) from security where sec_type_id = 494 and ( (sec_usergroup_id = 3278 and sec_usergroup_type_id = 230) or (sec_usergroup_id in (select ug_gi_id from user_group where ug_ui_id = 3278) and sec_usergroup_type_id = 231) ) and sec_obj_id in ( select obj_id from object where obj_ot_id in (select of_ot_id from obj_form left outer join obj_type on ot_id = of_ot_id where ot_app_id = 87 and of_id in (select sec_obj_id from security where sec_type_id = 493 and ( (sec_usergroup_id = 3278 and sec_usergroup_type_id = 230) or (sec_usergroup_id in (select ug_gi_id from user_group where ug_ui_id = 3278) and sec_usergroup_type_id = 231) ) ) and of_usage_type_id = 131 ) ) ) ) or (obj_ot_id in (select of_ot_id from obj_form left outer join obj_type on ot_id = of_ot_id where ot_app_id = 87 and of_id in (select sec_obj_id from security where sec_type_id = 493 and ( (sec_usergroup_id = 3278 and sec_usergroup_type_id = 230) or (sec_usergroup_id in (select ug_gi_id from user_group where ug_ui_id = 3278) and sec_usergroup_type_id = 231) ) ) and of_usage_type_id = 131 ) and obj_id not in (select sec_obj_id from security where sec_type_id = 494) )

    Read the article

  • My IF statement is changing variables in PHP

    - by user1902509
    I am fairly new to the whole programming thing, so forgive me if this is a stupid question. It seems odd that I haven't run into it before. I am trying to make an order form for a cake. You fill out the form, submit it, and it will then display the order in a new window, where you then hit "submit," and upload it to the Database. I have a series of If Statements to check for errors in the form before submitting it. Here is a simplified version of the code. Writing means any writing you want on the cake, Name is your name, and cake is what type of cake you want (the default is "None"). try { $name = trim($params->name); $cake = trim($params->cake); $writing = trim($params->writing); if (strlen($name) < 3){ throw new Exception("Please enter Your name."); } if ($cake = "None") { throw new Exception("Please select a Cake" } if ($cake = "Caramel Apple Pie" or $cake = "Pumpkin Pie" or $cake = "Eggnog Pie" and strlen($writing) > 1) { throw new Exception("We are sorry, but you can't write on any of our specialty pies."); } } catch(Exception $x) { $error = $x->getmessage(); } So what is happening is that when I go and hit submit the first time, the correct cake type comes up, but when you submit it the second time, the error comes up saying that I have "None" selected. All the other values are there and remain the same. I think the problem is that the first "IF" statement (Where it says "If($cake = "None")) is automatically changing $cake to "None" because I have tried commenting just that statement out, and it will then change the cake to be "Caramel Apple Pie," which is in the top of the next IF statement. Anyone know why it is doing this? And how to fix it?

    Read the article

  • Using statement question

    - by Dan
    I have two questions. 1) Should you always use a using statement on a connection? So, I would use it on the connection and then another one on a reader within the connection? So I would be using two using statements. 2) Lets say you use the using statement on the connection and also a reader being returned on the connection. So you have two using statements. Does it create two Try{}Finally{} blocks or just one? Thanks!

    Read the article

  • Is a switch statement the fastest way to implement operator interpretation in Java

    - by Mordan
    Is a switch statement the fastest way to implement operator interpretation in Java public boolean accept(final int op, int x, int val) { switch (op) { case OP_EQUAL: return x == val; case OP_BIGGER: return x > val; case OP_SMALLER: return x < val; default: return true; } } In this simple example, obviously yes. Now imagine you have 1000 operators. would it still be faster than a class hierarchy? Is there a threshold when a class hierarchy becomes more efficient in speed than a switch statement? (in memory obviously not) abstract class Op { abstract public boolean accept(int x, int val); } And then one class per operator.

    Read the article

  • Selecting the most common value from relation - SQL statement

    - by Ronnie
    I have a table within my database that has many records, some records share the same value for one of the columns. e.g. | id | name | software | ______________________________ | 1 | john | photoshop | | 2 | paul | photoshop | | 3 | gary | textmate | | 4 | ade | fireworks | | 5 | fred | textmate | | 6 | bob | photoshop | I would like to return the value of the most common occurring piece of software, by using an SQL statement. So in the example above the required SQL statement would return 'photoshop' as it occurs more than any other piece of software. Is this possible? Thank you for your time.

    Read the article

  • C++ Switch Statement Case Error

    - by Metal_Drummer
    I'm programming a simple text-based RPG using a switch statement for a game loop. The program works fine until I attempt to add another case statement, at which point it gives me the following three errors: "jump to case label" (error occurs at the line of the newly added case), and two "crosses initialization of 'ClassName *objectName'"(errors occur when the new objects are created in case 2). I'll paste the important code, if anyone needs more, please let me know. int main(void) { //initiate first object array and add some objects //initiate second object array and add some objects while(gamestate != 8) { switch(gamestate) { case 0: //do some stuff break; case 1: //do some stuff break; case 2: //declare new objects of the two... //...classes I have (ClassName *objectName) //do some stuff break; case 3: //this is the case I am trying to add //do nothing break; } } return 0; }

    Read the article

  • Using Container.DataItem with an If statement within <% %>

    - by William Calleja
    I have the following code in a c# aspx page: <ItemTemplate> <a <% if(((Dictionary<string, string>)Container.DataItem)["type"]==Session["type"]){%> class="active"<%}%> This code is causing the following error. Compiler Error Message: CS0117: 'System.ComponentModel.Container' does not contain a definition for 'DataItem' Why is that and how can I make a conditional statement that uses the Container.DataItem? Container.DataItem works perfectly when used within a <%# %> however putting the if statement within the <%# %> causes the following error: Compiler Error Message: CS1518: Expected class, delegate, enum, interface, or struct

    Read the article

  • Need help with a conditional SELECT statement

    - by Ethan
    I've got a stored procedure with a select statement, like this: `SELECT author_ID, author_name, author_bio FROM Authors WHERE author_ID in (SELECT author_ID from Books) ` This limits results to authors who have book records. This is the Books table: Books book_ID INT author_ID INT book_title NVARCHAR featured_book BIT What I want to do is conditionally select the ID of the featured book by each author as part of the select statement above, and if none of the books for a given author are featured, select the ID of the first (top 1) book by the author from the books table. How do I approach this?

    Read the article

  • Oracle SQL: How to use more than 1000 items inside an IN statement

    - by Mehper C. Palavuzlar
    I have an SQL statement where I would like to get data of 1200 ep_codes by making use of IN. When I include more than 1000 ep_codes inside IN statement, Oracle says I'm not allowed to do that. To overcome this, I tried to change the SQL code as follows: SELECT ... FROM ... WHERE ... AND ep_codes IN (...1000 ep_codes...) OR ep_codes IN (...200 ep_codes...) The code was executed succesfully but the results are strange. Is it appropriate to do that using OR between INs or should I execute two separate codes as one with 1000 and the other with 200 ep_codes?

    Read the article

  • Creating an IF statement for datagrid value

    - by EvanRyan
    This is something I thought would be easier than it's turning out to be. For whatever reason, I can't seem to figure out a way to make what I'm trying to do here work with an If statement: List<int> miscTimes = new List<int>(); for (int i = 0; i < MISCdataGridView1.RowCount; i++) { if (MISCdataGridView1.Rows[i].Cells[2].Value == "Something") { miscTimes.Add(Convert.ToInt32(MISCdataGridView1.Rows[i].Cells[3].Value)); } } return miscTimes; For some reason, I can't get it to like anything I do with the if statement. I've tried converting to string and all of that. How should I go about this?

    Read the article

  • How to use switch statement with Enumerations C#

    - by Maximus Decimus
    I want to use a switch statement in order to avoid many if's. So I did this: public enum Protocol { Http, Ftp } string strProtocolType = GetProtocolTypeFromDB(); switch (strProtocolType) { case Protocol.Http: { break; } case Protocol.Ftp: { break; } } but I have a problem of comparing an Enum and a String. So if I added Protocol.Http.ToString() there is another error because it allows only CONSTANT evaluation. If I change it to this switch (Enum.Parse(typeof(Protocol), strProtocolType)) It's not possible also. So, it's possible to use in my case a switch statement or not?

    Read the article

  • SQL: Using a CASE Statement to update 1000 rows at once

    - by SoLoGHoST
    Ok, I would like to use a CASE STATEMENT for this, but I am lost with this. Basically, I need to update a ton of rows, but just on the "position" column. I need to update all "position" values from 0 - count(position) for each id_layout_position column per id_layout column. OK, here is a pic of what the table looks like: Now let's say I delete the circled row, this will remove position = 2 and give me: 0, 1, 3, 5, 6, 7, and 4. But I want to add something at the end now and make sure that it has the last possible position, but the positions are already messed up, so I need to reorder them like so before I insert the new row: 0, 1, 2, 3, 4, 5, 6. But it must be ordered by lowest first. So 0 stays at 0, 1 stays at 1, 3 gets changed to 2, the 4 at the end gets changed to a 3, 5 gets changed to 4, 6 gets changed to 5, and 7 gets changed to 6. Hopefully you guys get the picture now. I'm completely lost here. Also, note, this table is tiny compared to how fast it can grow in size, so it needs to be able to do this FAST, thus I was thinking on the CASE STATEMENT for an UPDATE QUERY. Here's what I got for a regular update, but I don't wanna throw this into a foreach loop, as it would take forever to do it. I'm using SMF (Simple Machines Forums), so it might look a little different, but the idea is the same, and CASE statements are supported... $smcFunc['db_query']('', ' UPDATE {db_prefix}dp_positions SET position = {int:position} WHERE id_layout_position = {int:id_layout_position} AND id_layout = {int:id_layout}', array( 'position' => $position++, 'id_layout_position' => (int) $id_layout_position, 'id_layout' => (int) $id_layout, ) ); Anyways, I need to apply some sort of CASE on this so that I can auto-increment by 1 all values that it finds and update to the next possible value. I know I'm doing this wrong, even in this QUERY. But I'm totally lost when it comes to CASES. Here's an example of a CASE being used within SMF, so you can see this and hopefully relate: $conditions = ''; foreach ($postgroups as $id => $min_posts) { $conditions .= ' WHEN posts >= ' . $min_posts . (!empty($lastMin) ? ' AND posts <= ' . $lastMin : '') . ' THEN ' . $id; $lastMin = $min_posts; } // A big fat CASE WHEN... END is faster than a zillion UPDATE's ;). $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET id_post_group = CASE ' . $conditions . ' ELSE 0 END' . ($parameter1 != null ? ' WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''), array( 'members' => $parameter1, ) ); Before I do the update, I actually have a SELECT which throws everything I need into arrays like so: $disabled_sections = array(); $positions = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($disabled_sections[$row['id_group']][$row['id_layout']])) $disabled_sections[$row['id_group']][$row['id_layout']] = array( 'info' => $module_info[$name], 'id_layout_position' => $row['id_layout_position'] ); // Increment the positions... if (!is_null($row['position'])) { if (!isset($positions[$row['id_layout']][$row['id_layout_position']])) $positions[$row['id_layout']][$row['id_layout_position']] = 1; else $positions[$row['id_layout']][$row['id_layout_position']]++; } else $positions[$row['id_layout']][$row['id_layout_position']] = 0; } Thanks, I know if anyone can help me here it's definitely you guys and gals... Anyways, here is my question: How do I use a CASE statement in the first code example, so that I can update all of the rows in the position column from 0 - total # of rows found, that have that id_layout value and that id_layout_position value, and continue this for all different id_layout values in that table? Can I use the arrays above somehow? I'm sure I'll have to use the id_layout and id_layout_position values for this right? But how can I do this? Ok, guy, I get an error, saying "Hacking Attempt" with the following code: // Updating all positions in here. $smcFunc['db_query']('', ' SET @pos = 0; UPDATE {db_prefix}dp_positions SET position=@pos:=@pos+1 ORDER BY id_layout_position, position', array( ) ); Am I doing something wrong? Perhaps SMF has safeguards against this approach?? Perhaps I need to use a CASE STATEMENT instead?

    Read the article

  • Is this multi line if statement too complex?

    - by AndHeCodedIt
    I am validating input on a form and attempting to prompt the user of improper input(s) based on the combination of controls used. For example, I have 2 combo boxes and 3 text boxes. The 2 combo boxes must always have a value other than the first (default) value, but one of three, or two of three, or all text boxes can be filled to make the form valid. In one such scenario I have a 6 line if statement to try to make the test easily readable: if ((!String.Equals(ComboBoxA.SelectedValue.ToString(), DEFAULT_COMBO_A_CHOICE.ToString()) && !String.IsNullOrEmpty(TextBoxA.Text) && !String.Equals(ComboBoxB.SelectedValue.ToString(), DEFAULT_COMBO_B_CHOICE.ToString())) || (!String.IsNullOrEmpty(TextBoxB.Text) || !String.IsNullOrEmpty(TextBoxC.Text))) { //Do Some Validation } I have 2 questions: Should this type of if statement be avoided at all cost? Would it be better to enclose this test in another method? (This would be a good choice as this validation will happen in more than one scenario) Thanks for your input(s)!

    Read the article

  • PHP IF statement not taking variable into account!

    - by Jess
    I have a tabled view in a while loop, where a user can view information on books. For example, book ISBN, book name, read status... Basically, when the user sets their 'readstatus' to 'complete' I want that specific table row to become grey! The logic is very straight forward, however I can't get my IF statement to recognise this: $readstatus = $_GET['readstatus']; if ($readstatus == 'complete') { echo '<tr class="completed">'; } else if ($readstatus != 'complete') { echo '<tr class="reading">'; } I'm obviously doing something wrong here, but all I need is the CSS class of the table row to change if the value of 'readstatus' = 'complete', if not, then output the default CSS table row color ('reading') Should I be putting $result as the variable or something? I have this coming just before my nested IF statement: $result = mysql_query($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); while($row = mysql_fetch_array($result)) { ?>

    Read the article

  • jQuery can't get if statement to work

    - by jstacks
    I'm looking help with an If Statement. I'm trying to finalize this horizontal scrolling I have and the last bit is to not just disable scrolling when the end is reached, but to also disable (well, change color) the scroll buttons at that point as well. And change back when they are scrollable again. http://jsfiddle.net/stfzy/83/ EDIT* I've updated the JQuery and have everything working except just one if statement: $('div#arrowL').click(function(){ if(index < 0 ){ //can't scroll $('div#arrowL').addClass('active'); } }); I need to add this class back when you can't scroll left anymore. And I think the issue is with the "index < 0" portion but I don't see what I need to change it to to get it to work. Any help is appreciated.

    Read the article

  • Switch statement usage - C

    - by Jamie Keeling
    Hello, I have a thread function on Process B that contains a switch to perform certain operations based on the results of an event sent from Process A, these are stored as two elements in an array. I set the first element to the event which signals when Process A has data to send and I have the second element set to the event which indicates when Process A has closed. I have began to implement the functionality for the switch statement but I'm not getting the results as I expect. Consider the following: // //Thread function DWORD WINAPI ThreadFunc(LPVOID passedHandle) { for(i = 0; i < 2; i++) { ghEvents[i] = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("Global\\ProducerEvents")); if(ghEvents[i] == NULL) { getlasterror = GetLastError(); } } dwProducerEventResult = WaitForMultipleObjects( 2, ghEvents, FALSE, INFINITE); switch (dwProducerEventResult) { case WAIT_OBJECT_0 + 0: { //Producer sent data //unpackedHandle = *((HWND*)passedHandle); MessageBox(NULL,L"Test",L"Test",MB_OK); break; } case WAIT_OBJECT_0 + 1: { //Producer closed ExitProcess(1); break; } default: return; } } As you can see if the event in the first array is signalled Process B should display a simple message box, if the second array is signalled the application should close. When I actually close Process A, Process B displays the message box instead. If I leave the first case blank (Do nothing) both applications close as they should. Furthermore Process B sends data an error is thrown (When I comment out the unpacking): Have I implemented my switch statement incorrectly? I though I handled the unpacking of the HWND correctly too, any suggestions? Thanks for your time.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >