Search Results

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

Page 32/552 | < Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >

  • Ruby: what is the pitfall in this simple code excerpt that tests variable existence

    - by zipizap
    I'm starting with Ruby, and while making some test samples, I've stumbled against an error in the code that I don't understand why it happens. The code pretends to tests if a variable finn is defined?() and if it is defined, then it increments it. If it isn't defined, then it will define it with value 0 (zero). As the code threw an error, I started to decompose it in small pieces and run it, to better trace where the error was comming from. The code was run in IRB irb 0.9.5(05/04/13), using ruby 1.9.1p378 First I certify that the variable finn is not yet defined, and all is ok: ?> finn NameError: undefined local variable or method `finn' for main:Object from (irb):134 from /home/paulo/.rvm/rubies/ruby-1.9.1-p378/bin/irb:15:in `<main>' >> Then I certify that the following inline-condition executes as expected, and all is ok: ?> ((defined?(finn)) ? (finn+1):(0)) => 0 And now comes the code that throws the error: ?> finn=((defined?(finn)) ? (finn+1):(0)) NoMethodError: undefined method `+' for nil:NilClass from (irb):143 from /home/paulo/.rvm/rubies/ruby-1.9.1-p378/bin/irb:15:in `<main>' I was expecting that the code would not throw any error, and that after executing the variable finn would be defined with a first value of 0 (zero). But instead, the code thows the error, and finn get defined but with a value of nil. >> finn => nil Where might the error come from?!? Why does the inline-condition work alone, but not when used for the finn assignment? Any help apreciated :)

    Read the article

  • Reset variable in javascrtp (jQuery)

    - by superUntitled
    I am trying to reset a variable (that updates the src value for an image) when an area of an image map is clicked, so that the hover function calls a different image when the user hovers over another area in the image map. I have a variable called "state" that I set right off the bat. This is the variable that I want to reset when an area is clicked. var state = "path/to/images/feed1.png"; I have a couple of functions involving hover() and click(). $("#Map area").click( function () { var button = $(this).attr("id"); // here is where i want to reset the 'state' variable var state = "path/to/images/" + button + ".png"; alert("you clicked "+button+" hello"); return false; } ); $("#Map area").hover( function () { var button = $(this).attr("id"); over("path/to/images/" + button + ".png"); }, function () { off(); }); And some functions that these functions call: function over(image) { $("#feednavImg").attr("src", image); } function off() { $("#feednavImg").attr("src", state); }

    Read the article

  • static variable lose its value

    - by user542719
    I have helper class with this static variable that is used for passing data between two classes. public class Helper{ public static String paramDriveMod;//this is the static variable in first calss } this variable is used in following second class mathod public void USB_HandleMessage(char []USB_RXBuffer){ int type=USB_RXBuffer[2]; MESSAGES ms=MESSAGES.values()[type]; switch(ms) { case READ_PARAMETER_VALUE: // read parameter values switch(prm){ case PARAMETER_DRIVE_MODE: // paramet drive mode Helper.paramDriveMod =(Integer.toString(((USB_RXBuffer[4]<< 8)&0xff00))); System.out.println(Helper.paramDriveMod+"drive mode is selectd ");//here it shows the value that I need. ..........}}//let say end switch and method and the following is an third class method use the above class method public void buttonSwitch(int value) throws InterruptedException{ boolean bool=true; int c=0; int delay=(int) Math.random(); while(bool){ int param=3; PARAMETERS prm=PARAMETERS.values()[param]; switch(value){ case 0: value=1; while(c<5){ Thread.sleep(delay); protocol.onSending(3,prm.PARAMETER_DRIVE_MODE.ordinal(),dataToRead,dataToRead.length);//read drive mode System.out.println(Helper.paramDriveMod+" drive mode is ..........in wile loop");//here it shows null value }}//let say end switch and method what is the reason that this variable lose its value?

    Read the article

  • Retrieve the Value of An Integer Variable

    - by Abluescarab
    This is probably easily figured out (I feel very stupid right now), but I can't find a solution anywhere, for some reason. Perhaps I'm not searching for the right thing. And maybe it's in some beginner tutorial I haven't watched. Anyway, I was wondering how to retrieve the value of an integer variable in C++? I know you can use cin.getline() for string variables, but I received an error message when I attempted that with an integer variable (and rightfully so, I know it was wrong, but I was looking for a solution). My project is a Win32 console application. What I'm trying to do is ask a user to input a number, stored in the variable n. Then I take the value of n and perform various math functions with it. In my header file, I have string, windows, iostream, stdio, math, and fstream. Do I need to add another library? There's not much more to tell. I can post my code if I must. EDIT: cout << "TEST SINE"; cout << "\nPlease enter a number.\n\n"; cin >> n; break; Here's the code I'm trying to use. Is this all I need to do? If so, how do I incorporate the variable so I can test it using sin, cos, and tan? Yet again, thanks ahead of time.

    Read the article

  • Variable not implementing correctly from if statement

    - by swiftsly
    I have an if statement that is supposed to set the variable $pc162v to a link specified in the MySQL table if content exists in the $vid column of the row. The problem is, the PHP is detecting that there's a link in the MySQL, but isn't setting the $pc162v variable correctly. Here's the variable declarations: $pc162v = ""; $vid162 = '<embed width="420" height="236" src="'.$pc162v.'" type="application/x-shockwave-flash"></embed>'; Here's the section of the if statement: if (empty($row[7])) { $vid162 = ''; } else { $pc162v = $row[7]; } In my web browsers, the part of the code where the variable $vid162 is used, shows up as the following: <embed width="420" height="236" src="" type="application/x-shockwave-flash"> I have also tried setting $vid162 to: <embed width="420" height="236" src="<?php echo $pc162v; ?>" type="application/x-shockwave-flash"></embed> and that just makes the code in my web browser: <embed width="420" height="236" src="<?php echo $pc162v; ?>" type="application/x-shockwave-flash"> Hope someone has a solution! Thanks in advance.

    Read the article

  • Use of unassigned local variable 'xxx'

    - by Tomislav
    I'm writing a database importer from our competitors to ours database:) I have a code generator which create Methods form import to our database like public void Test_Import_Customer_1() // variables string conn; string sqlSelect; string sqlInsert; int extID; string name; string name2; DateTime date_inserted; sqlSelect="select id,name,date_inserted from table_competitors_1"; oledbreader reader = new GetOledbRader(sqlString,conn); while (reader.read()) { name=left((string)myreader["name"],50); //limitation of my field date_inserted=myreader["date_inserted"]; sqlInsert=string.Format("insert into table(name,name2,date_inserted)values '{0}', '{1}', {2})",name,name2,date_inserted); //here is the problem name2 "Use of unassigned local variable" ExecuteSQL(sqlInsert) } As different companies database has different fields i can not set value to each variable and there is a big number of tables to go one variable to next. like sqlSelect_Company_1 = "select name,date_inserted from table_1"; sqlSelect_Company_2 = "select name,name2 from table_2"; is there a way to override the typing of each variable one by one with default values?

    Read the article

  • javascript watching for variable change via a timer

    - by DA
    I have a slide show where every 10 seconds the next image loads. Once an image loads, it waits 10 seconds (setTimeout) and then calls a function which fades it out, then calls the function again to fade in the next image. It repeats indefinitely. This works. However, at times, I'm going to want to over-ride this "function1 call - pause - function2 call - function1 call" loop outside of this function (for instance, I may click on a slide # and want to jump directly to that slide and cancel the current pause). One solution seems to be to set up a variable, allow other events to change that variable and then in my original function chain, check for any changes before continuing the loop. I have this set up: var ping = 500; var pausetime = 10000; for(i=0; i<=pausetime; i=i+ping){ setTimeout(function(){ console.log(gocheckthevariable()); console.log(i); pseudoIf('the variable is true AND the timer is done then...do the next thing') },i) } The idea is that I'd like to pause for 10 seconds. During this pause, every half second I'll check to see if this should be stopped. The above will write out to the console the following every half second: true 10000 true 10000 true 10000 etc... But what I want/need is this: true 0 true 500 true 1000 etc... The basic problem is that the for loop executes before each of the set timeouts. While I can check the value of the variable every half second, I can't match that against the current loop index. I'm sure this is a common issue, but I'm at a loss what I should actually be searching for.

    Read the article

  • linux bash script: set date/time variable to auto-update (for inclusion in file names)

    - by user1859492
    Essentially, I have a standard format for file naming conventions. It breaks down to this: target_dateUTC_timeUTC_tool So, for instance, if I run tcpdump on a target of 'foo', then the file would be foo_dateUTC_timeUTC_tcpdump. Simple enough, but a pain for everyone to constantly (and consistently) enter... so I've tried to create a bash script which sets system variables like so: FILENAME=$TARGET\_$UTCTIME\_$TOOL Then, I can just call the variable at runtime, like so: tcpdump -w $FILENAME.lpc All of this works like a champ. I've got a menu-driven .sh which gives the user the options of viewing the current variables as well as setting them... file generation is a breeze. Unfortunately, by setting the date/time variable, it is locked to the value at the time of creation (naturally). I set the variable like so: UTCTIME=$(/bin/date --utc +"%Y%m%d_%H%M%Z") What I really need is either a way to create a variable which updates at runtime, or (more likely) another way to skin this cat. While scouring for solutions, I came across a similar issues... like this. But, to be honest, I'm stumped on how to marry the two approaches and create a simple, distributable solution. I can post the entire .sh if anyone cares to review (about 120 lines)

    Read the article

  • Can I access Spring session-scoped beans from application-scoped beans? How?

    - by Corvus
    I'm trying to make this 2-player web game application using Spring MVC. I have session-scoped beans Player and application-scoped bean GameList, which creates and stores Game instances and passes them to Players. On player creates a game and gets its ID from GameList and other player sends ID to GameList and gets Game instance. The Game instance has its players as attributes. Problem is that each player sees only himself instead of the other one. Example of what each player sees: First player (Alice) creates a game: Creator: Alice, Joiner: Empty Second player (Bob) joins the game: Creator: Bob, Joiner: Bob First player refreshes her browser Creator: Alice, Joiner: Alice What I want them to see is Creator: Alice, Joiner: Bob. Easy way to achieve this is saving information about players instead of references to players, but the game object needs to call methods on its player objects, so this is not a solution. I think it's because of aop:scoped-proxy of session-scoped Player bean. If I understand this, the Game object has reference to proxy, which refers to Player object of current session. Can Game instance save/access the other Player objects somehow? beans in dispatcher-servlet.xml: <bean id="userDao" class="authorization.UserDaoFakeImpl" /> <bean id="gameList" class="model.GameList" /> <bean name="/init/*" class="controller.InitController" > <property name="gameList" ref="gameList" /> <property name="game" ref="game" /> <property name="player" ref="player" /> </bean> <bean id="game" class="model.GameContainer" scope="session"> <aop:scoped-proxy/> </bean> <bean id="player" class="beans.Player" scope="session"> <aop:scoped-proxy/> </bean> methods in controller.InitController private GameList gameList; private GameContainer game; private Player player; public ModelAndView create(HttpServletRequest request, HttpServletResponse response) throws Exception { game.setGame(gameList.create(player)); return new ModelAndView("redirect:game"); } public ModelAndView join(HttpServletRequest request, HttpServletResponse response, GameId gameId) throws Exception { game.setGame(gameList.join(player, gameId.getId())); return new ModelAndView("redirect:game"); } called methods in model.gameList public Game create(Player creator) { Integer code = generateCode(); Game game = new Game(creator, code); games.put(code, game); return game; } public Game join(Player joiner, Integer code) { Game game = games.get(code); if (game!=null) { game.setJoiner(joiner); } return game; }

    Read the article

  • Setting default_scope according to some criteria

    - by Tam
    I'm trying to set default scope according to some criteria determined by ana ActionController before_filter. In controller: before_filter :authorize ... def authorize if some_condition @default_scope_conditions = something elsif another_condition @default_scope_conditions = something_else end end Inside the ActiveRecord default_scope :conditions => @default_scope_conditions But it doesn't seem to work, the before filter gets called but the default_scope doesn't get set. Could you please advise me what I'm doing wrong and how to fix it or suggest me some other way of achieving that.

    Read the article

  • Lifetime of a const string literal returned by a function

    - by Neeraj
    Consider this code: const char* someFun() { // ... some stuff return "Some text!!" } int main() { { // Block: A const char* retStr = someFun(); // use retStr } } My question is in the function sumFun() where is "some Text!!", stored (i think may be in some static area in ROM) and what will be its scope? Will the memory pointed by retStr be occupied throughout the program or be released once the block A exits? -- Thanks

    Read the article

  • JQuery will not set a higher scoped object in callback

    - by user344666
    Hello, I have a jquery callback function. In that function I want it to change the value of a varible that is in a higher scope, for somereason it is not doing that. Here is the code. Thanks function add() { var returnedData = { my_id: 0 }; $.post("add_event.php", { event : toSendText }, function(data) {returnedData.my_id = 5;}, "json"); if(add_page == true){ alert(returnedData.my_id); window.open('content-list.php?cal_id='); } }

    Read the article

  • Object allocation in C++

    - by Poiuyt
    char *myfunc() { char *temp = "string"; return temp; } In this piece of code, where does the allocation of the object pointed to by temp happen and what would be its scope? Is this function a valid way to return a char* pointer?

    Read the article

  • How to access a (shadowed) global function in ruby.

    - by yngvedh
    Hi, I was wondering how to access a global function fn in ruby from a class which also defined a method fn. I have made a workaround by aliasing the function like so: def fn end class Bar alias global_fn fn def fn # how to access the global fn here without the alias global_fn end end I'm looking for something along the lines of c++'s :: to access global scope but I can't seem to locate any information about it. I guess I don't know specifically what I'm looking for.

    Read the article

  • skipping a variable using while read in bash

    - by Aleksandar Ivanisevic
    i'm reading a few variables from a file using while read a b c; do (something) done < filename is there an elegant way to skip a variable (read in an empty value), i.e. if I want a=1 b= c=3, what should I write in the file? Right now i'm putting 1 "" 3 and then use b=$(echo $b | tr -d \" ) but this is pretty cumbersome, IMHO any ideas?

    Read the article

  • how do I get vim home directory?

    - by nsharish
    I wanted to set VIMHOME variable this way(common to windows and linux), let $VIMHOME=expand("%:p")."/..", so that VIMHOME is "~/.vim" in linux or "path/to/vimfiles" in windows. I put this in a var.vim file and placed this in the plugin directory. It loads properly, but VIMHOME is set only to "./..". How do I get the full path of a file using expand? Is there an easy way to set VIMHOME?

    Read the article

  • Escaping Variable in Cat

    - by Peter
    I'm trying to write a shell script over ssh via a bash prompt. The shell, however, insists on interpreting any variable I want to write instead of writing it directly to file. For example, cat <<EOF >checkup.sh\n'$command'EOF is simply written as '' to file. How do I get $command written instead? I've tried every practical method of escaping I can think of. If it changes anything, I'm doing it over PHP using phpseclib.

    Read the article

  • How do I change Jenkins-ci systemInfo PATH variable

    - by Thomas Schultz
    I have Jenkins setup and it was working but then I updated java and now Jenkins acts like it doesn't know where it is. When I goto my Jenkins server and click manage jenkins-system information under the "Environment Variables" section the PATH variable is wrong. How can I change it? Jenkins is running as root but root's PATH is correct but Jenkins isn't pulling that correctly. Right now Jenkins can't find hg(mercurial) or anything else.

    Read the article

  • Scan all domain workstations for specific registry key/environmental variable

    - by Trevor
    I'm looking for scripts or software that can scan workstations on a domain for a particular environmental variable (for interest, it was used to store the SOE build version) and generate a report. Accuracy is key, I don't want any workstations skipped or missed. And considering workstations will need to be powered on for anything to remotely read from the registry (and there's no guarantee they will be), that means something that can sit and run continuously for a while, updating its own records as it goes. Does anyone know of such a beast?

    Read the article

  • nginx rewrite subdomain to file as a variable

    - by ethree
    How do you get the subdomain as a variable to add in a rewrite? hello.example.com should go to example.com/user.php?u=hello but still display as just hello.example.com I'm currently doing http://example.com/users/hello but would like to have Tumblr style domain names for users. rewrite ^/users/(.*)$ /user.php?u=$1 last; Also, if there are pages like /settings/ after the subdomain hello.example.com/settings/ I'll need to rewrite to a settings.php

    Read the article

< Previous Page | 28 29 30 31 32 33 34 35 36 37 38 39  | Next Page >