Questions tagged [unassigned-variable]

93 questions
1
vote
1 answer

Variable not being assigned first time from input in a batch script

So I am trying to ask the user if they want to overwrite a current virtual machine if one already exists. I have extracted the problem part of this .bat file into a separate file to replicate the problem. The code from this file is: @echo…
MicWit
  • 655
  • 12
  • 31
1
vote
5 answers

c# foreach loop access variable

I have the following problem: i have a string variable, which has to store a filepath. In a foreach loop i go through all files in a certain directory and im looking for the oldest, which is saved in that string variable. When the loop is finished i…
sebastian
  • 13
  • 5
1
vote
1 answer

I Assigned a Variable but it Says I Did Not

Note: I am using Python 3.5 I just started creating a part two to a text based game I made, and here is the code I'm having trouble with: import random def game(): randomIp = random.randint(10, 999) def tutorial(): global…
1
vote
1 answer

Unassigned local variable/ alter XML Format

My program takes user input and uses it to create a query. The results of that query will then be put into an XML file with XElements based on their selections. I have a string staff which i set equal to the value of staffType. Where staff is…
Brandon Lumsden
  • 79
  • 1
  • 2
  • 9
1
vote
1 answer

Use of unassigned variable error in VS 2015

I'm having an issue with the answer2 string variable (about half way down, I included the entire main method because I wasn't sure if it would help or not). the compiler is telling me the variable is unassigned and ignoring the previous if-else…
beefoak
  • 136
  • 1
  • 10
1
vote
1 answer

Finding execution path leading to exception

My IDE is warning me against a possible variable reference before assignment. But I'm having trouble spotting it. I'm ready to turn in a bug report, but maybe you can see what I'm not seeing. The variable in question is a named check_dialog and the…
Alexandre Bell
  • 3,141
  • 3
  • 30
  • 43
1
vote
3 answers

Why is a local variable assigned in one method, but unassigned in a near-identical method?

When I compile this code, I receive a compilation error saying writer is an unassigned local variable in SaveArray. It doesn't complain about reader in the similar method LoadArray. Why is this the case? Shouldn't they behave the same? static…
1
vote
2 answers

Use of unassigned local variable that is assigned

The below code runs a 'for' loop to create months 1 through 12 then names each month Jan through Dec according to their number. That pieces compiles fine. At the bottom where I try to write the month name on the screen is where it is failing. It…
SeeSee
  • 13
  • 1
  • 3
1
vote
2 answers

Do you have to initialize a string variable inside a method?

I am programming in C# and I keep getting an error for my string variable result. When I hover over the line return result it says use of unassigned local variable. Do I have to assign result a value before I use it? How come i do not get the same…
user2510809
  • 235
  • 3
  • 14
1
vote
3 answers

Variable Assigned in try...catch - Scope

I have declared a variable before a try... catch and assigned it in the try block. I keep getting an unassigned variable error for "fileDate". class Something { string fACR = "BAK"; int numbDays = 5; Public static void Main() { …
OYORF
  • 433
  • 1
  • 5
  • 10
1
vote
2 answers

Use of unassigned local variable in a Try Catch

It seems that this particular error has been solved quite a few times but my code snippet has something different in that it will never cause an "unassigned" error. This code is from a project that I am doing for school. I am allowed to ask for help…
Plendor
  • 310
  • 1
  • 4
  • 16
1
vote
1 answer

Use of unassigned local variable - to me it should be assigned

I'm relatively new to programming in C#. The code I am attempting to realize should provide an Array value to my variable SEAT. private void btnFindSeat_Click(object sender, EventArgs e) { int AntalSaeder = int.Parse(txtbxSeats.Text); int…
mk100
  • 11
  • 1
1
vote
2 answers

When does Python create a name record in the local scope

This question is not about solving the issue, but rather about understanding the inner workings of the Python (2.7) compiler part. See the code below. It is a standard decorator function with arguments stripped of all the fancy stuff. def…
1
vote
3 answers

Strange behavior in C# for value types

I just tried a small code snippet to see how value type initialization works. Below is the code snippet public MainWindow() { InitializeComponent(); int num; char alpha; //if (num ==…
Narendra
  • 3,069
  • 7
  • 30
  • 51
1
vote
1 answer

Can't seem to fix unassigned local variables

So i Have been writing this program for a project and everything seemed to work out fine. I've been checking my work with my instructors code, but I don't have a copy of the top 40 lines of code to check with and I can't figure out what caused this…
IR_GRIM_KC
  • 23
  • 2