Which Global Variable Is for Last Expression

which global variable is for last expression

You don't; save it in a variable.

List of 1.9 special variables

Could some explain the following behavior of global variable in python?

You can access global variables but for modifying them it should be explicitly declared that variable is a global variable.

I think this link would be useful.

The reason behind it is that when you say x = x + 1, python thinks that you want a local variable x and then when reaches the x + 1 expression python finds out that the local variable x was mentioned but not assigned any value so it gets confused.

why cant we assign a value to global variables using an expression in C ?

You can assign a global variable using an expression. But only inside a function. As said by the compiler/linker, outside a function you can initialize variables only to constant. This is because, outside a function, no code can be executed and the variables are initialized to constant value by the compiler/linker at build time. Note that if you don't init the variable (outside a function), the default initialization is to 0.
To make it work you should write

#include<stdio.h>
int a=8;
int b;
int main()
{
b=a+9;
printf("%d",b);
return 0;
}

A question about let when it acts as a global variable in ES6

As MDN explains:

At the top level of programs and functions, let, unlike var, does not create a property on the global object.

This is because let always creates a lexically scoped variable. If it were to create properties of a global object instead, those properties would be visible to code in other scopes. They wouldn't be lexically scoped anymore, defeating the point of using let.

If you're wondering how there can be "other scopes" not lexically contained within the global scope, there can be multiple script files. Or look at this variation of your example:

let getValue = function() {  return this.value;};
let value = 1;console.log(getValue());

In C,why is definition of a global variable in a separate statement raising warning,but is OK for a local variable?

You're compiling in C89 mode.

  int x;

is a tentative definition of x.

  x=303;

is then interpreted as a definiton of the variable x with implicit type int (int x = 303;). Under C99 or later, that code would not compile since the "implicit int" rule was abolished and without the "implicit int" rule, the second line could only be interpreted as a statement, which is not allowed at file scope.

Compiling with -std=c89 -Wall -Wextra -pedantic (and adding a return 0; to main), gcc warns

redef.c:4:1: warning: data definition has no type or storage class [enabled by default]
redef.c:4:1: warning: type defaults to ‘int’ in declaration of ‘x’ [-Wimplicit-int]

Match Methods with References to Global Variables

Description

I'd do this in two steps, first identify each of your functions and subs. Here I'm using a reference \1 to ensure we're matching the correct end function or end sub. This regex also grabs the function name and places that into group 2. This can then be used later if part 2 is correct

(?:Public|Private)\s+(Function|Sub)\s+([a-z0-9]*).*?End\s+\1
Sample Image

Then test each of these to see if they contain your variable, note in this test I'm using multiline matching to ensure the comment character does not appear before Global_Variable on the same line. This also checks that the GLOBAL_VARIABLE_1 is not preceded by any of the following

  • alphanumeric with or without a _ seperater. This would need to be updated with all the characters you might find in a variable name. Including a hyphen - here might be confused with a minus sign used in an equation.
  • comment character '

^[^']*?(?![a-z0-9][_]?|['])\bGLOBAL_VARIABLE_1

Sample Image

VB Part 1

Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sourcestring as String = "replace with your source string"
Dim re As Regex = New Regex("(?:Public|Private)\s+(Function|Sub)\s+([a-z0-9]*).*?End\s+\1",RegexOptions.IgnoreCase OR RegexOptions.Singleline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module

$matches Array:
(
[0] => Array
(
[0] => Public Function doThis(byVal xml)
'' Created : dd/mm/yyyy
'' Return : string
'' Param : xml- an xml blob

return = replace(xml, "><", ">" & vbLf & "<")

GLOBAL_VARIABLE_1 = 2 + 2

doThis = return

End Function
[1] => Public Function doThat(byVal xPath)
'' Created : dd/mm/yyyy
'' Return : array
' 'Param : xPath

return = split(mid(xPath, 2), "/")

GLOBAL_VARIABLE_2 = 2 + 2

doThat = return

End Function
[2] => Public Sub butDontDoThis()
'' Created : dd/mm/yyyy
'' Return : string
' 'Param : obj

For i = 0 To 5
return = return & "bye" & " "

Next

End Sub
[3] => Public Sub alsoDoThis(byRef obj)
'' Created : dd/mm/yyyy
'' Return : string
' 'Param : obj, an xml document object

For i = 0 To 4
return = return & "hi" & " "

Next

GLOBAL_VARIABLE_1 = 1 + 1

End Sub
)

[1] => Array
(
[0] => Function
[1] => Function
[2] => Sub
[3] => Sub
)

[2] => Array
(
[0] => doThis
[1] => doThat
[2] => butDontDoThis
[3] => alsoDoThis
)

)

VB Part 2

Found in this text

Public Function doThis(byVal xml)
'' Created : dd/mm/yyyy
'' Return : string
'' Param : xml- an xml blob

return = replace(xml, "><", ">" & vbLf & "<")

GLOBAL_VARIABLE_1 = 2 + 2

doThis = return

End Function

example

Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sourcestring as String = "replace with your source string"
Dim re As Regex = New Regex("^[^']*?GLOBAL_VARIABLE_1",RegexOptions.IgnoreCase OR RegexOptions.Multiline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module

$matches Array:
(
[0] => Array
(
[0] => Param : xml- an xml blob

return = replace(xml, "><", ">" & vbLf & "<")

GLOBAL_VARIABLE_1
)

)

not found in this text

Public Function doThis(byVal xml)
'' Created : dd/mm/yyyy
'' Return : string
'' Param : xml- an xml blob

return = replace(xml, "><", ">" & vbLf & "<")

' GLOBAL_VARIABLE_1 = 2 + 2

doThis = return

End Function

example

Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sourcestring as String = "replace with your source string"
Dim re As Regex = New Regex("^[^']*?GLOBAL_VARIABLE_1",RegexOptions.IgnoreCase OR RegexOptions.Multiline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module

Matches Found:
NO MATCHES.

also not found in this text

Public Sub butDontDoThis()
'' Created : dd/mm/yyyy
'' Return : string
' 'Param : obj

For i = 0 To 5
return = return & "bye" & " "

Next

End Sub

example

   Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sourcestring as String = "Public Sub butDontDoThis()
'' Created : dd/mm/yyyy
'' Return : string
' 'Param : obj

For i = 0 To 5
return = return & ""bye"" & "" ""

Next

End Sub"
Dim re As Regex = New Regex("^[^']*?GLOBAL_VARIABLE_1",RegexOptions.IgnoreCase OR RegexOptions.Multiline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module

Matches Found:
NO MATCHES.

Disclaimer

There are a lot of edge cases which can trip this up, for example if you have a comment with ' end function or have a if you assign a string value to a variable like thisstring = "end sub"

Yes I realize OP was for VBscript, I've included these examples to demonstrate the overall logic and that the regular expressions work.

How to declare a global variable to be used on a C# expression

Use IQueryable<TableEntity>, where TableEntity is the type of the objects in your Table DbSet.

It may also be an IEnumerable<TableEntity>, depending on whether you run your query against a database or some in-memory collection.

You can also see which type to use by hovering your mouse over myQuery.



Related Topics



Leave a reply



Submit