Search Results

Search found 13794 results on 552 pages for 'variable scope'.

Page 12/552 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • JS Variable inside another variable

    - by Tusk
    I have a function that would use other variables, depending on what has been passed. Like this = ActionBar(slot) slot contains "one". and I would like to create a call inside that like object.slot.name but it should convert it before hand to make the command look like object.one.name. Is there a way to do this in javascript/jquery? I remember vaguely that some other language does this as {slot} or something like that. Sorry if this question was already asked, I've checked google and stackoverflow too, but didn't find an answer. Also I'd like to know what's the proper programming term for this kind of variable passing? Edited it cause of misunderstandings. I'm looking into OOP js, so object is an object, one is an object, and name is an attribute, but when passing I'm passing "one" as a string to the function. Tried eval, it doesn't work while dotted with an object.

    Read the article

  • How do I use a variable within an extended class public variable

    - by Gerry Humphrey
    Have a class that I am using, I am overriding variables in the class to change them to what values I need, but I also not sure if or how to handle an issue. I need to add a key that is generated to each of this URLs before the class calls them. I cannot modify the class file itself. use Theme/Ride class ETicket extends Ride { public $key='US20120303'; // Not in original class public $accessURL1 = 'http://domain.com/keycheck.php?key='.$key; public $accessURL2 = 'http://domain.com/keycheck.php?key='.$key; } I understand that you cannot use a variable in the setting of the public class variables. Just not sure what would be the way to actually do something like this in the proper format. My OOP skills are weak. I admit it. So if someone has a suggestion on where I could read up on it and get a clue, it would be appreciated as well. I guess I need OOP for Dummies. =/

    Read the article

  • how to link a c++ object to a local variable in Lua

    - by MahanGM
    I'm completing my scripting interface with Lua, but recently I've stuck at some point. I have several functions for my Entitiy events like Update(). I have a function called create_entitiy() which instantiate a new entity from a given entity index: function Update() local bullet = create_entity(0, 0, "obj_bullet") end create_entity returns a table which is the properties of the created entity. Now how can I make a connection between bullet variable and my newly created object? Right now for previously added objects to the scene, I simply set a global table for each of them and then after every call to Update(), I go through registered names to find object tables and perform new changes. Like the one below: function Update() if keyboard_key_press(vk_right) then obj_player.x += 3 end I can get obj_player table because I know its name from C++, plus I can get it as a global table and simply reach for the first instance named obj_player. Is there any solution for me to make bullet variable act like this? I was thinking to get all local variables in Update() function and check for every one to see if is it table and it has an unique field attached to it like id, this way I can determine that this is an object table and do the rest of the process. By the way, is this interface going to work easier with luaBind if I implement it? Bottom line: How can I make a local variable in Lua that receives a table from create_entity function and track that local variable to capture it from C++. e. g. function Update() local bullet = create_entity(0, 0, "obj_bullet") bullet.x = 10 <== Commit a change in table end Now I want to get variable bullet from C++. And it's not just this variable, there might be a ton of these local variables with different names.

    Read the article

  • Whats the scope of c code within objective-c classes?

    - by roja
    I was reading up about bypassing objective-c's messaging to gain performance (irrelevant to this specific question) when i found an interesting bit of code: #import <Cocoa/Cocoa.h> @interface Fib : NSObject { } - (long long) cFib: (NSUInteger) number; @end @implementation Fib // c implementation of fib long long cFibIMP(NSUInteger number) { return (number < 3) ? 1 : cFib(number - 1) + cFib(number - 2); } // method wrapper for c implementation of fib - (long long) cFib: (NSUInteger) number { return cFibIMP(number); } @end My question is; when using c function, within an objective-c object, what scope is the c function (cFibIMP in this particular case) placed in? Does the objective-c class encapsulate the c function removing change of name-clash or is the c function simply dumped into the global scope of the whole objective-c program?

    Read the article

  • Whats the scope of a c function defined within objective-c class?

    - by roja
    I was reading up about bypassing objective-c's messaging to gain performance (irrelevant to this specific question) when i found an interesting bit of code: #import <Cocoa/Cocoa.h> @interface Fib : NSObject { } - (long long) cFib: (NSUInteger) number; @end @implementation Fib // c implementation of fib long long cFibIMP(NSUInteger number) { return (number < 3) ? 1 : cFib(number - 1) + cFib(number - 2); } // method wrapper for c implementation of fib - (long long) cFib: (NSUInteger) number { return cFibIMP(number); } @end My question is; when using c function, within an objective-c object, what scope is the c function (cFibIMP in this particular case) placed in? Does the objective-c class encapsulate the c function removing change of name-clash or is the c function simply dumped into the global scope of the whole objective-c program?

    Read the article

  • send variable fancybox onclick event

    - by samuel saul
    hi, i want to send href value. but its not working. function display () { $.fancybox({ 'href': 'index.php', 'width' : '75%', 'height' : '75%', 'autoScale' : false, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe' }); } i tryed this : function display (who) { $.fancybox({ 'href': 'index.php'+who, 'width' : '75%', 'height' : '75%', 'autoScale' : false, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe' }); } <a onclick="javascript:display("?id=11");" href="#" >create</a> this onclick event inside the innerhtml so its not working with '' why

    Read the article

  • UnboundLocalError: local variable 'rows' referenced before assignment

    - by patrick
    i'm trying to make a database connection by an other script. But the script didn't work propperly. and if I do a 'print' on the rows then I get the value 'null' But if I use a 'select * from incidents' query then i get the result from the table incidents. import database rows = database.database("INSERT INTO incidents VALUES(3 ,'test_title1', 'test', TO_DATE('25-07-2012', 'DD-MM-YYYY'), CURRENT_TIMESTAMP, 'sector', 50, 60)") #print database.database() print rows database.py script: import psycopg2 import sys import logfile def database(query): logfile.log(20, 'database.py', 'Executing...') con = None try: con = psycopg2.connect(database='incidents', user='ipfit5', password='tester') cur = con.cursor() #print query cur.execute(query) rows = cur.fetchall() con.commit() #test row does work #cur.execute("INSERT INTO incidents VALUES(3 ,'test_titel1', 'test', TO_DATE('25-07-2012', 'DD-MM-YYYY'), CURRENT_TIMESTAMP, 'sector', 50, 60)") except: logfile.log(40, 'database.py', 'Er is iets mis gegaan') logfile.log(40, 'database.py', str(sys.exc_info())) finally: if con: con.close() return rows

    Read the article

  • Variable Operators in PHP

    - by BenTheDesigner
    Given this example, how would I return the result of the equation rather than the equation itself as a string? $operator = '+'; foreach($resultSet as $item){ $result = $item[$this->orderField] . $operator . 1; echo $result; }

    Read the article

  • Find actual value of PHP variable

    - by Simon S
    Hi all. I am having a real headache with reading in a tab delimited text file and inserting it into a MySQL Database. The tab delimited text file was generated (I think) from a MS SQL Database, and I have written a simple script to read in the file and insert it into an existing table in my MySQL database. However, there seems to be some problem with the data in the txt file. When my PHP script parses the file and I output the INSERT statements, the values in each of the fields are longer than they should be. For example, the first field should be a simple two character alphanumeric value. If I echo out the INSERT statements, using Firebug (in Firefox), between each of the characters is a question mark in a black diamond. If I var_dump the values, I get the following: string(5) "A1" Now, this clearly shows a two character string, but var_dump tells me it is five characters long!! If I trim() the value, all I get is the first character (in this case "A"). How can I get at the other characters, even if it is only to remove them? Additionally, this appears to be forcing MySQL to insert the value as a BLOB, not as a varchar as it should. Simon

    Read the article

  • How to trim whitespace from bash variable?

    - by too much php
    I have a shell script with this code: var=`hg st -R "$path"` if [ -n "$var" ]; then echo $var fi But the conditional code always executes because hg st always prints at least one newline character. Is there a simple way to strip whitespace from $var (like trim() in php)? or Is there a standard way of dealing with this issue? I could use sed or awk, but I'd like to think there is a more elegant solution to this problem.

    Read the article

  • How to declare a variable in MS SQL and use it in the same Stored Procedure

    - by Nicklas
    Im trying to get the Value from BrandID in one tabel and add it to another tabel. But I can't get it to work. Anybody know how to do it right? CREATE PROCEDURE AddBrand AS DECLARE @BrandName nvarchar(50), @CategoryID int, @BrandID int SELECT @BrandID = BrandID FROM tblBrand WHERE BrandName = @BrandName) INSERT INTO tblBrandinCategory (CategoryID, BrandID) VALUES (@CategoryID, @BrandID) RETURN

    Read the article

  • Dollar ($) sign in password string treated as variable

    - by ncatnow
    Spent some time troubleshooting a problem whereby a PHP/MySQL web application was having problems connecting to the database. The database could be accessed from the shell and phpMyAdmin with the exact same credentials and it didn't make sense. Turns out the password had a $ sign in it: $_DB["password"] = "mypas$word"; The password being sent was "mypas" which is obviously wrong. What's the best way to handle this problem? I escaped the $ with a \ $_DB["password"] = "mypas\$word"; and it worked. I generally use $string = 'test' for strings which is probably how I avoided running into this before. Is this correct behavious? What if this password was stored in a database and PHP pulled it out - would this same problem occur? What am I missing here...

    Read the article

  • How to declare a variable in SQL Server and use it in the same Stored Procedure

    - by Nicklas
    Im trying to get the value from BrandID in one table and add it to another table. But I can't get it to work. Anybody know how to do it right? CREATE PROCEDURE AddBrand AS DECLARE @BrandName nvarchar(50), @CategoryID int, @BrandID int SELECT @BrandID = BrandID FROM tblBrand WHERE BrandName = @BrandName INSERT INTO tblBrandinCategory (CategoryID, BrandID) VALUES (@CategoryID, @BrandID) RETURN

    Read the article

  • c++ warning: address of local variable

    - by chnet
    int * ref () { int tmp = 100; return &tmp; } int main () { int * a = ref(); cout << *a << endl; } I know the function ref () is allocated stack space. It will get destroyed as soon as the function exits. So the complier will give warning information. But my question is why the returning result is still correct.

    Read the article

  • vb.net session variable passing "space" from one page to another

    - by iuret
    i have 2 aspx webpages with vb.net code. On the first page, I have a text box, on first page that says "Enter Hobby", but its not a required textbox. So if the user clicks submit, it'll load up the second page. Now in the second page i have textbox "hobby" which has maxlength = 10. and in the vb.net code i have hobby.text = session("hobby"). if the user doesnt fill up hobby in first page, the session comes with 10 "spaces" since maxlength is 10. I tried hobby.text = TRIM(session("hobby"), but nothing happens. Any idea how i can lose the spaces if nothing is inputted?

    Read the article

  • How do I supply a variable to put in a another variable in PHP?

    - by Jared
    I'm not sure if I asked the question correctly. I have some code I am trying to embed. For instance: $menuPopup ='<IMG SRC="' . $someVariable . '">'; Later on, I have the a few product variables: $someProduct1 ='image1.jpg'; $someProduct2 ='image2.jpg'; Later on, want to display the $menuPopup, using a src from $someProduct1, or $someProduct2. //Pseudo Code $menuPopup ( $someProduct1); Anyway to do that?

    Read the article

  • problem with extern variable

    - by sksingh73
    I have got 2 cpp files & a header file, which I have included in both cpp files. It's like this: abc.h extern uint32_t key; a.cpp #include "abc.h" uint32_t key; int main { ............. } b.cpp #include "abc.h" int main { printf("Key: %.8x\n", key); ............. } Now when I compile a.cpp, there is no error. but when i compile b.cpp it gives error "undefined reference to `key'". Please help me in finding the problem in this code.

    Read the article

  • how can i request a variable in my home.ctp of my cakePHP application?

    - by Simon
    I created a page using the MVC structure called 'sections' ( view is located in the app/views/sections folder, model in the model folder and the controller in the controller folder) when i request the variable $test, it works fine without any errors.. When i want to request this variable in my home.ctp, it provides me with an error, saying that the variable is undefined.. Is there any way in cakePHP to request this variable on any page you want it to? Thnx in advance!

    Read the article

  • Question about variable definitions in functions.

    - by Kaan Tekelioglu
    Hi. #include <stdio.h> main() { int a; for(a=1; a<=4 && printf("%d ",a); a++) { int a; static int b=a; printf("%d ",(a++)-b); } getchar(); getchar(); } In this code, the printout is 1 0 2 1 3 2 4 3. I understand why the int a; part works differently then the int a which was defined outside the for function, and why static int b; is only defined once with the primary value of a ; but why does the (a++) part in printf affect proceeding values of a? Don't we redefine int a; each time the for function runs? Thanks in advance.

    Read the article

  • Parsing String into multiple variable length String (C#)

    - by Nassign
    I am currently trying to convert a VB6 program into C#. There was extensive use of string splitting into structure. For example, Dim Sample AS String Sample = "John Doe New York Test Comment" Public Type Struct1 Name As String * 15 Address As String * 10 Comment As String * 20 End Type Dim dataStruct As Struct1 Set dataStruct = Sample When the dataStruct is set, it will automatically split value into the 3 structure member. Is there a special function to do this in C#. The only way I know how to do this is thru Attributes/Annotation describing the length and start position of string. Any other suggestion?

    Read the article

  • Use concat and maintain length of variable

    - by user1682055
    I'm trying to use concat on some variables. These variables have been declared as chars: declare v_order_date char(10); declare v_quantity char(11); declare v_plant char(100); I have a cursor where I am setting these as some outputs. To call the results, I am setting v_msg as set v_msg := concat( v_msg, '\n', v_order_date, v_quantity, v_plant); However, the result I am getting when I select v_msg is: 2012-01-222501008 Creeping Buttercup but I want to maintain the length of the declared variables in my select that looks like this 2012-01-22 250 1008 Creeping Buttercup Are there any suggestions? Thank you.

    Read the article

  • Validate HAML from ActiveRecord: scope/controller/helpers for link_to etc?

    - by Chris Boyle
    I like HAML. So much, in fact, that in my first Rails app, which is the usual blog/CMS thing, I want to render the body of my Page model using HAML. So here is app/views/pages/_body.html.haml: .entry-content= Haml::Engine.new(body, :format => :html5).render ...and it works (yay, recursion). What I'd like to do is validate the HAML in the body when creating or updating a Page. I can almost do that, but I'm stuck on the scope argument to render. I have this in app/models/page.rb: validates_each :body do |record, attr, value| begin Haml::Engine.new(value, :format => :html5).render(record) rescue Exception => e record.errors.add attr, "line #{(e.respond_to? :line) && e.line || 'unknown'}: #{e.message}" end end You can see I'm passing record, which is a Page, but even that doesn't have a controller, and in particular doesn't have any helpers like link_to, so as soon as a Page uses any of that it's going to fail to validate even when it would actually render just fine. So I guess I need a controller as scope for this, but accessing that from here in the model (where the validator is) is a big MVC no-no, and as such I don't think Rails gives me a way to do it. (I mean, I suppose I could stash a controller in some singleton somewhere or something, but... excuse me while I throw up.) What's the least ugly way to properly validate HAML in an ActiveRecord validator?

    Read the article

  • Performance considerations for common SQL queries

    - by Jim Giercyk
    Originally posted on: http://geekswithblogs.net/NibblesAndBits/archive/2013/10/16/performance-considerations-for-common-sql-queries.aspxSQL offers many different methods to produce the same results.  There is a never-ending debate between SQL developers as to the “best way” or the “most efficient way” to render a result set.  Sometimes these disputes even come to blows….well, I am a lover, not a fighter, so I decided to collect some data that will prove which way is the best and most efficient.  For the queries below, I downloaded the test database from SQLSkills:  http://www.sqlskills.com/sql-server-resources/sql-server-demos/.  There isn’t a lot of data, but enough to prove my point: dbo.member has 10,000 records, and dbo.payment has 15,554.  Our result set contains 6,706 records. The following queries produce an identical result set; the result set contains aggregate payment information for each member who has made more than 1 payment from the dbo.payment table and the first and last name of the member from the dbo.member table.   /*************/ /* Sub Query  */ /*************/ SELECT  a.[Member Number] ,         m.lastname ,         m.firstname ,         a.[Number Of Payments] ,         a.[Average Payment] ,         a.[Total Paid] FROM    ( SELECT    member_no 'Member Number' ,                     AVG(payment_amt) 'Average Payment' ,                     SUM(payment_amt) 'Total Paid' ,                     COUNT(Payment_No) 'Number Of Payments'           FROM      dbo.payment           GROUP BY  member_no           HAVING    COUNT(Payment_No) > 1         ) a         JOIN dbo.member m ON a.[Member Number] = m.member_no         /***************/ /* Cross Apply  */ /***************/ SELECT  ca.[Member Number] ,         m.lastname ,         m.firstname ,         ca.[Number Of Payments] ,         ca.[Average Payment] ,         ca.[Total Paid] FROM    dbo.member m         CROSS APPLY ( SELECT    member_no 'Member Number' ,                                 AVG(payment_amt) 'Average Payment' ,                                 SUM(payment_amt) 'Total Paid' ,                                 COUNT(Payment_No) 'Number Of Payments'                       FROM      dbo.payment                       WHERE     member_no = m.member_no                       GROUP BY  member_no                       HAVING    COUNT(Payment_No) > 1                     ) ca /********/                    /* CTEs  */ /********/ ; WITH    Payments           AS ( SELECT   member_no 'Member Number' ,                         AVG(payment_amt) 'Average Payment' ,                         SUM(payment_amt) 'Total Paid' ,                         COUNT(Payment_No) 'Number Of Payments'                FROM     dbo.payment                GROUP BY member_no                HAVING   COUNT(Payment_No) > 1              ),         MemberInfo           AS ( SELECT   p.[Member Number] ,                         m.lastname ,                         m.firstname ,                         p.[Number Of Payments] ,                         p.[Average Payment] ,                         p.[Total Paid]                FROM     dbo.member m                         JOIN Payments p ON m.member_no = p.[Member Number]              )     SELECT  *     FROM    MemberInfo /************************/ /* SELECT with Grouping   */ /************************/ SELECT  p.member_no 'Member Number' ,         m.lastname ,         m.firstname ,         COUNT(Payment_No) 'Number Of Payments' ,         AVG(payment_amt) 'Average Payment' ,         SUM(payment_amt) 'Total Paid' FROM    dbo.payment p         JOIN dbo.member m ON m.member_no = p.member_no GROUP BY p.member_no ,         m.lastname ,         m.firstname HAVING  COUNT(Payment_No) > 1   We can see what is going on in SQL’s brain by looking at the execution plan.  The Execution Plan will demonstrate which steps and in what order SQL executes those steps, and what percentage of batch time each query takes.  SO….if I execute all 4 of these queries in a single batch, I will get an idea of the relative time SQL takes to execute them, and how it renders the Execution Plan.  We can settle this once and for all.  Here is what SQL did with these queries:   Not only did the queries take the same amount of time to execute, SQL generated the same Execution Plan for each of them.  Everybody is right…..I guess we can all finally go to lunch together!  But wait a second, I may not be a fighter, but I AM an instigator.     Let’s see how a table variable stacks up.  Here is the code I executed: /********************/ /*  Table Variable  */ /********************/ DECLARE @AggregateTable TABLE     (       member_no INT ,       AveragePayment MONEY ,       TotalPaid MONEY ,       NumberOfPayments MONEY     ) INSERT  @AggregateTable         SELECT  member_no 'Member Number' ,                 AVG(payment_amt) 'Average Payment' ,                 SUM(payment_amt) 'Total Paid' ,                 COUNT(Payment_No) 'Number Of Payments'         FROM    dbo.payment         GROUP BY member_no         HAVING  COUNT(Payment_No) > 1   SELECT  at.member_no 'Member Number' ,         m.lastname ,         m.firstname ,         at.NumberOfPayments 'Number Of Payments' ,         at.AveragePayment 'Average Payment' ,         at.TotalPaid 'Total Paid' FROM    @AggregateTable at         JOIN dbo.member m ON m.member_no = at.member_no In the interest of keeping things in groupings of 4, I removed the last query from the previous batch and added the table variable query.  Here’s what I got:     Since we first insert into the table variable, then we read from it, the Execution Plan renders 2 steps.  BUT, the combination of the 2 steps is only 22% of the batch.  It is actually faster than the other methods even though it is treated as 2 separate queries in the Execution Plan.  The argument I often hear against Table Variables is that SQL only estimates 1 row for the table size in the Execution Plan.  While this is true, the estimate does not come in to play until you read from the table variable.  In this case, the table variable had 6,706 rows, but it still outperformed the other queries.  People argue that table variables should only be used for hash or lookup tables.  The fact is, you have control of what you put IN to the variable, so as long as you keep it within reason, these results suggest that a table variable is a viable alternative to sub-queries. If anyone does volume testing on this theory, I would be interested in the results.  My suspicion is that there is a breaking point where efficiency goes down the tubes immediately, and it would be interesting to see where the threshold is. Coding SQL is a matter of style.  If you’ve been around since they introduced DB2, you were probably taught a little differently than a recent computer science graduate.  If you have a company standard, I strongly recommend you follow it.    If you do not have a standard, generally speaking, there is no right or wrong answer when talking about the efficiency of these types of queries, and certainly no hard-and-fast rule.  Volume and infrastructure will dictate a lot when it comes to performance, so your results may vary in your environment.  Download the database and try it!

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >