Search Results

Search found 12457 results on 499 pages for 'variable assignment'.

Page 7/499 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • php variable scope in oop

    - by mr o
    Hi, I wonder if anyone can help out here, I'm trying to understand how use an objects properties across multiple non class pages,but I can't seem to be able to get my head around everything i have tried so far. For example a class called person; class person { static $name; } but i have a number of different regular pages that want to utilize $name across the board. I have trying things like this; pageone.php include "person.php"; $names = new Person(); echo person::$name; names::$name='bob'; pagetwo.php include "person.php"; echo person::$name; I can work with classes to the extent I'm OK as long as I am creating new instances every page, but how can make the properties of one object available to all, like a shared variable ? Thanks

    Read the article

  • python variable scope

    - by Oscar Reyes
    I'm teaching my self python and I was translating some sample class Student: def __init__( self, name, a,b,c ): self.name = name self.a = a self.b = b self.c = c def average(self): return ( a+b+c ) / 3.0 Which is pretty much my intended class definition Later in the main method I create an instance and call it a if __name__ == "__main__" : a = Student( "Oscar", 10, 10, 10 ) That's how I find out that the variable a declared in main is available to the method average and that to make that method work , I have to type self.a + self.b + self.c instead What's the rationale of this? I found related questions, but I don't really know if they are about the same

    Read the article

  • sql - datetime variable versus string representation of datetime variable

    - by BhejaFry
    Hi folks, I have a query that takes too long to respond when the search parameter happens to be a varchar datatype with date. However, if i convert varchar to datetime variable, the query runs fine. For ex: This takes too long. select count(id) from names where updateddate '1/5/2010' This runs fine. declare @dateparam datetime set @dateparam = convert(datetime, '1/5/2010',102) select count(id) from names where updateddate @dateparam What's the reason one runs fine but the other doesn't? TIA

    Read the article

  • PHP Get variable to equal value of switch

    - by user342391
    I am trying to get a variable on my page to equal the result of a switch I have. This is the code: $payment_method = switch ($cardtype) { case "visa" : echo "VSA"; break; case "mastercard" : echo "MSC"; break; case "maestro" : echo "MAE"; break; case "amex" : echo "AMX" ; break; default : echo "Please specify a payment method!"; break; }; How can I get $payment_method to equal the result of this???? So far I recieve an error: Parse error: syntax error, unexpected T_SWITCH in /var/www/account/credits/moneybookers/process.php on line 65

    Read the article

  • C# Anonymous method variable scope problem with IEnumerable<T>

    - by PaN1C_Showt1Me
    Hi. I'm trying to iterate through all components and for those who implements ISupportsOpen allow to open a project. The problem is when the anonymous method is called, then the component variable is always the same element (as coming from the outer scope from IEnumerable) foreach (ISupportsOpen component in something.Site.Container.Components.OfType<ISupportsOpen>()) { MyClass m = new MyClass(); m.Called += new EventHandler(delegate(object sender, EventArgs e) { if (component.CanOpenProject(..)) component.OpenProject(..); }); itemsList.Add(m); } How should it be solved, please?

    Read the article

  • Variable length Blob in hibernate?

    - by Seth
    I have a byte[] member in one of my persistable classes. Normally, I'd just annotate it with @Lob and @Column(name="foo", size=). In this particular case, however, the length of the byte[] can vary a lot (from ~10KB all the way up to ~100MB). If I annotate the column with a size of 128MB, I feel like I'll be wasting a lot of space for the small and mid-sized objects. Is there a variable length blob type I can use? Will hibernate take care of all of this for me behind the scenes without wasting space? What's the best way to go about this? Thanks!

    Read the article

  • Using a variable as identifier in a json array

    - by Robbert van den Bogerd
    Hi folks! I'm wondering if it is possible to use assigned variables as identifier in a json array. When I tried this, I was getting some unexpected results: (Code is simplified, parameters are passed in a different way) var parameter = 'animal'; var value = 'pony'; Util.urlAppendParameters (url, {parameter : value}); Util.urlAppendParameters = function(url, parameters) { for (var x in parameters) { alert(x); } } Now the alert popup says: 'parameter' instead of 'animal'. I know I could use a different method (creating an array and assigning every parameter on a new line), but I want to keep my code compact. So my question is: Is it possible to use a variable as an identifier in the json array, and if so, could you please tell me how? Thanks in advance!

    Read the article

  • Rendering a variable with erb.

    - by TZer0
    I've got the following problem: I have rhtml (html minced together with ruby inside <% % and <%= % tags) stored in a database which I want to render. The information is acquired through a query. I need to be able to evaluate the information I get from the database as though as it was normal content inside the .erb-file. What I currently have: <% @mymods.each do |mod| %> <%= render_text(mod["html"])%> <% end %> Where mod["html"] is the variable containing the rhtml-code and @mymods an array of objects from the query. I have currently no idea what function I should use (render_text does, of course, not work). Help is greatly appreciated. /TZer0

    Read the article

  • C# Copying instance variable to local variable in functions of same class

    - by NickLarsen
    I have been looking through some code on an open source project recently and found many occurrences of this kind of code: class SomeClass { private int SomeNumber = 42; public ReturnValue UseSomeNumber(...) { int someNumberCopy = this.SomeNumber; if (someNumberCopy > ...) { // ... do some work with someNumberCopy } else { // ... do something else with someNumberCopy } } } Is there any real benefit to making a copy of the instance variable?

    Read the article

  • Java-script object - get variable name

    - by Mikk
    Hi, To begin with, I'm not even sure, if it is the right way to do it. Let's say, i have script (jquery included) like this: foo = function() { this.bar = function() { alert('I\'m bar'); } this.test = function() { $('body').append('<a onclick="my_var.bar();">Click me</a>'); } this.test(); } var my_var = new foo(); Is there any way, i could make variable "my_var" dynamic inside function "foo". So I could do something like $('body').append('<a onclick="'+the_variable_which_im_assigned_to+'.bar();">Click me</a>'); Thank you

    Read the article

  • Using the value of a variable as another variables name in Ruby

    - by hrickards
    Hi, I'm just starting out in learning Ruby and I've written a program that generates some numbers and assigns them to variables @one, @two, @three etc. The user can then specify a variable to change by inputting it's name (e.g one). I then need to do something like '@[valueofinout] = asd'. How would I do this, and is there a better way as the way I'm thinking of seems to be discouraged? I've found x = "myvar" myvar = "hi" eval(x) -> "hi" but I don't completely understand why the second line is needed. In my case would I use something like @one = "21" input = "one" input = "@" + input changeto = "22" eval(input) -> changeto Thanks

    Read the article

  • JQuery selector in variable

    - by nagut
    I wanted to ask about using selector from a variable first I have: function check() { $('.info input, .info select').each(function(n, element){ if ($(element).val()=='') alert('empty'); }); } and called it in $('input')change(check); and they worked fine. But now I want to pass some value to the function to make it dynamic, like $('input')change(check('.info')); and changed the function to function check(sel) { $(sel +' input, '+ sel + ' select').each(function(n, element){ if ($(element).val()=='') alert('empty'); }); } but it doesn't work. Any help please.. Thanks, nagut

    Read the article

  • Problem with variable inside gsp

    - by xain
    Hi, I have a loop inside a gsp page, and I want to do a calculation on the fly, so I set a variable: <g:set var="total" value="0" /> And in the loop: <g:each in="${mob}" var="m"> ... <g:set var="total" value="${total+(m.q*m.sts.uf)}"/> ... </g:each> The "total" value does not correspond to the expected calculation. m.q is an integer, and m.sts.uf is a float. Any hints ? Thanks.

    Read the article

  • PHP Global variable in class is reset

    - by Robert
    I have a web form that manipulates records in a MySQL database. I have a method for displaying an edit interface for both creating new records and editing them if ($_POST['new_page']) { print "<h2>Create new page</h2>\n"; $isNew=1; $this->EditForm(); } else if($_POST['edit']){ print "<h2>Edit page</h2>\n"; $isNew=0; $this->EditForm(); } I am trying to use the global variable $isNew to determine where a record is to be added or updated. However, whenever my SaveChanges() function is run, $isNew is always 0. $isNew is declared immediately after the class declaration, outside all of the functions. class Editor{ public $isNew;

    Read the article

  • Pass variable name to a function in r

    - by Misha
    Is it possible to pass just a variable name in a function call and have it utilised as such within the function?? pseudocode: q<-function(A){ b<-(w%in%A.2|w%in%A.7) factor(b,levels=c(F,T),labels=c("non-"A,A))} w<-c(0:10) e.2<-c(1,2) e.7<-c(6,7) what I´d like to do is q(e) and have returned non-e,e,e,non-e,non-e,e,e,non-e,non-e //M q<-function(A) { a2<-get(paste(a,".2",sep="")) a7<-get(paste(a,".7",sep="")) b<-(w%in%a2|%in%a7) factor(b,levels=c(F,T),labels=c(paste("non-",a,sep=""),a)) } q("e") Thx, M

    Read the article

  • Problem with variable argument function in C++

    - by Freezerburn
    I'm trying to create a variable length function (obviously, heh) in C++, and what I have right now works, but only for the first argument. If someone could please let me know how to get this working with all the arguments that are passed, I would really appreciate it. Code: void udStaticObject::accept( udObjectVisitor *visitor, ... ) { va_list marker; udObjectVisitor *i = visitor; va_start( marker, visitor ); while( 1 ) { i->visit_staticObject( this ); //the if here will always go to the break immediately, allowing only //one argument to be used if( ( i = va_arg( marker, udObjectVisitor* ) ) ) break; } va_end( marker ); } Based on my past posts, and any help posts I make in general, there is probably some information that I did not provide that you will need to know to help. I apologize in advance if I forgot anything, and please let me know what you need to know so I can provide the information.

    Read the article

  • Javascript global variable not working properly?

    - by Fabian
    My jQuery code: $(document).ready(function() { chrome.extension.sendRequest({get: "height"}, function(response) { height = response.value; }); $("#id").css("height", height+"px"); }); You don't have to be concerned about the chrome.extension.sendRequest(), basically it communicates with a background page to fetch the value for "height" from localStorage and stores the value in global variable height. The problem lies in $("#id") not being assigned the height value. However if I were to modify it such that it is now: $(document).click(function() { $("#id").css("height", height+"px"); }); it works. Any idea why?

    Read the article

  • jquery updating a div in ajax diesnt work properly, when using a variable

    - by maschek
    hi, i got the following code var zieldiv = $(this).attr(\'id\'); $.ajax({ url: \'index.php?params\', type: \'POST\', data: { color:thenewcolor, zieldiv:zieldiv }, timeout: 50000, beforeSend: function() { $("#" + zieldiv).css({background: "#" + thenewcolor} ); } }); I use this for dragging a small div into a bigger div. the variable at the beginnning would give out the string "test1". So in the ajax.thing the css of a div which matches the var zieldiv should be updatet. Problem is, if i would place a string instead a var into the $(...) like $("#test1") it acts like its supposed to, the #test1 gets updated. but if i use the var $("#" + zieldiv) the parent div, which is surrounding the #test1-div gets updated. but i know for sure the var zieldiv contains the string "test1", because when passing it to php it contains "test1". so i think this is a little strange. do you have any ideas? thanx, maschek

    Read the article

  • how to access a firefox extension variable from the current document/window

    - by bosky101
    my firefox extension has an object myExt . myExt = { request: function(){ //makes request to server}, callback: function(json) { //do something with this } }; From a dynamically added script element, I make a call to a server that returns json, i want the json to be sent to myExt.callback that exists within my extension's js code. //from my extension, i add a script element myExt.request(); //from server i get the following response myExt.callback ( {"some":"json"}) ; //but the window doesnt find a reference to myExt how do i make a reference to myExt variable from the webpage ?

    Read the article

  • Pass variable number of variables to a class in PHP

    - by user325282
    I need to pass a variable number of strings to instantiate different classes. I can always do a switch on the size of the array: switch(count($a)) { case 1: new Class(${$a[0]}); break; case 2: new Class(${$a[0]}, ${$a[1]}); break; etc... There has to be a better way to do this. If I have an array of strings ("variable1", "variable2", 'variable3", ...), how can I instantiate a Class without manually accounting for every possibility?

    Read the article

  • Iterative and Incremental Principle Series 1: The Dreaded Assignment

    - by llowitz
    A few days ago, while making breakfast for my teenage son… he turned to me and happily exclaimed, “I really like how my high school Government class assigns our reading homework.  In middle school, we had to read a chapter each week.  Everyone dreaded it.  In high school, our teacher assigns us a section or two every day.  We still end up reading a chapter each week, but this way is so much easier and I’m actually remembered what I’ve read!” Wow!  Once I recovered from my initial shock that my high school son actually initiated conversation with me, it struck me that he was describing one of the five basic OUM principles -- Iterative and Incremental.   Not only did he describe how his teacher divided a week long assignment into daily increments, but he went on to communicate some of the major benefits of having shorter, more achievable milestones.  I started to think about other applications of the iterative and incremental approach and I realized that I had incorporated this approach when I recently rededicated myself to physical fitness.  Join me over the next four days as I present an Iterative and Incremental blog series where I relate my personal experience incorporating the iterative and incremental approach and the benefits that I achieved.

    Read the article

  • How to create a variadic (with variable length argument list) function wrapper in JavaScript

    - by U-D13
    The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in a browser as well as in the Windows Script Host or other script engines. I am aware of 3 methods of which each one has its own drawbacks. eval() method: function wrapper () { var str = ''; for (var i=0; i<arguments.lenght; i++) str += (str ?', ':'') + ',arguments['+i+']'; return eval('[native_function] ('+str+')'); } switch() method: function wrapper () { switch (arguments.lenght) { case 0: return [native_function] (arguments[0]); break; case 1: return [native_function] (arguments[0], arguments[1]); break; ... case n: return [native_function] (arguments[0], arguments[1], ... arguments[n]); } } apply() method: function wrapper () { return [native_function].apply([native_function_namespace], arguments); } What's wrong with them you ask? Well, shall we delve into all the reasons why eval() is evil? And also all the string concatenation... Not a solution to be labeled "elegant". One can never know the maximum n and thus how many cases to prepare. This also would strech the script to immense proportions and sin against the holy DRY principle. The script could get executed on older (pre- JavaScript 1.3 / ECMA-262-3) engines that don't support the apply() method. Now the question part: is there any another solution out there?

    Read the article

  • Microsoft C Compiler: Inline variable declaration?

    - by Rosarch
    I'm writing C in Visual Studio 2010. The compiler doesn't seem to want to let me use inline variable declarations. The following code produces an error: unsigned int fibonacci_iterative(unsigned int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } unsigned int prev_prev = 0; // error unsigned int prev = 1; // error unsigned int next = 0; // error for (int term_number = 0; term_number < n; term_number++) { unsigned int temp = prev_prev + prev; prev = next; prev_prev = prev; next = temp; } return next; } Error: error C2143: syntax error : missing ';' before 'type' error C2143: syntax error : missing ';' before 'type' error C2143: syntax error : missing ';' before 'type' Why is this happening? Is there a setting to make the compiler not so strict?

    Read the article

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