By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

GetVariableValueFromName

P: n/a
Does exists a function GetVariableValueFromName (o something similar) to get
a variable value from a string that contains variable name ?
Example:
Dim Target as string
Dim Source as string = "aaa"
Dim sSourceName as string = "Source" 'This is the name of the variable
Target = GetVariableValueFromName(sSourceName)
' -- now Target has the value "aaa"

Thanks

Piermaria
Jul 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
You could likely use System.Reflection.

Also, having the whole scenario could help to raise a whole new solution
than using "indirection" (i.e. having a variable that contains the name of
the variable you want to access).

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de
news:D3**********************************@microsof t.com...
Does exists a function GetVariableValueFromName (o something similar) to get a variable value from a string that contains variable name ?
Example:
Dim Target as string
Dim Source as string = "aaa"
Dim sSourceName as string = "Source" 'This is the name of the variable
Target = GetVariableValueFromName(sSourceName)
' -- now Target has the value "aaa"

Thanks

Piermaria

Jul 21 '05 #2

P: n/a
First, thanks a lot for your suggestion.
I try to explain better my problem:

I need to convert in vb.net (asp.net) Gupta SqlWindows application. This
application uses some thousand of Sql statements stored in an external file.
In SqlWindows i have this function :

SqlPrepareAndExecute("select field1,field2, field3 from TABLE1, TABLE2, ...
where .... into :vh1,:vh2,:vh3")

So i can pass to SqlPrepareAndExecute a string (read from external file)
with the Sql Command (with bind and into variables written as substring
inside the string). In the example vh1,vh2,vh3 are variables declared in the
caller function of SqlPrepareAndExecute. When SqlPrepareAnd Execute finish
vh1,vh2 and vh3 contain the fetch values retrieved by the select.

Now in vb.net i dont't want to change all the Sql statements. I think to
build a function SqlPrepareAndExecute with the existing string parameter and
another parameter (a object array) for receiving fetch value. But after
execution i have the problem to dinamically assign the value in object array
to the real into variables (in the example vh1,vh2,vh3).

Thanks in advance for suggestions and help.

Piermaria
"Patrice" wrote:
You could likely use System.Reflection.

Also, having the whole scenario could help to raise a whole new solution
than using "indirection" (i.e. having a variable that contains the name of
the variable you want to access).

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de
news:D3**********************************@microsof t.com...
Does exists a function GetVariableValueFromName (o something similar) to

get
a variable value from a string that contains variable name ?
Example:
Dim Target as string
Dim Source as string = "aaa"
Dim sSourceName as string = "Source" 'This is the name of the variable
Target = GetVariableValueFromName(sSourceName)
' -- now Target has the value "aaa"

Thanks

Piermaria


Jul 21 '05 #3

P: n/a
AFAIK you'll have anyway to drop (perhaps programmatically) the into clause
that will not be recognized by the DBMS.

I would do something like :

SqlPrepareAndExecute(Statement,vh1,vh2,vh3)

The routine will just perform the select and will affect the first column to
vh1 (without any concern with the name just using the position), second to
vh2, etc allowing to transport the binding outside of the SQL Statement....

If not acceptable, have a look at System.Reflection that will allow what you
need but I would really drop the tight coupling between SQL code and
application variables...

Also I would check how Gupata SqlWindows handles multiple rows ? Does it
have some kind of mechanism for this ?

Good luck.

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de
news:53**********************************@microsof t.com...
First, thanks a lot for your suggestion.
I try to explain better my problem:

I need to convert in vb.net (asp.net) Gupta SqlWindows application. This
application uses some thousand of Sql statements stored in an external file. In SqlWindows i have this function :

SqlPrepareAndExecute("select field1,field2, field3 from TABLE1, TABLE2, .... where .... into :vh1,:vh2,:vh3")

So i can pass to SqlPrepareAndExecute a string (read from external file)
with the Sql Command (with bind and into variables written as substring
inside the string). In the example vh1,vh2,vh3 are variables declared in the caller function of SqlPrepareAndExecute. When SqlPrepareAnd Execute finish
vh1,vh2 and vh3 contain the fetch values retrieved by the select.

Now in vb.net i dont't want to change all the Sql statements. I think to
build a function SqlPrepareAndExecute with the existing string parameter and another parameter (a object array) for receiving fetch value. But after
execution i have the problem to dinamically assign the value in object array to the real into variables (in the example vh1,vh2,vh3).

Thanks in advance for suggestions and help.

Piermaria
"Patrice" wrote:
You could likely use System.Reflection.

Also, having the whole scenario could help to raise a whole new solution
than using "indirection" (i.e. having a variable that contains the name of the variable you want to access).

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de news:D3**********************************@microsof t.com...
Does exists a function GetVariableValueFromName (o something similar)
to get
a variable value from a string that contains variable name ?
Example:
Dim Target as string
Dim Source as string = "aaa"
Dim sSourceName as string = "Source" 'This is the name of the variable
Target = GetVariableValueFromName(sSourceName)
' -- now Target has the value "aaa"

Thanks

Piermaria


Jul 21 '05 #4

P: n/a
Piermaria <Pi*******@discussions.microsoft.com> wrote:
Does exists a function GetVariableValueFromName (o something similar) to get
a variable value from a string that contains variable name ?
Example:
Dim Target as string
Dim Source as string = "aaa"
Dim sSourceName as string = "Source" 'This is the name of the variable
Target = GetVariableValueFromName(sSourceName)
' -- now Target has the value "aaa"


You can do this for static and member variables using reflection
(Type.GetField to get a FieldInfo, then FieldInfo.GetValue to get the
value) but I find that in most situations where this is requested, a
simple map from name to value would be a better solution.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5

P: n/a
Thanks for your answer.
I agree to cut the into clause of the sql statement.
But i don't understand how build the SqlPrepareAndExecute function.
It must have a variable number of paramters vh1,vh2,vh3,vh4, ... depending
from the number of fields extracting by the select. I could have a ParamArray
paramater but in .Net this is only byval and not byref. What do you think
about this ?
About multiple rows: for now we can ignore this problem because most of all
the select return only one row.

Piermaria

"Patrice" wrote:
AFAIK you'll have anyway to drop (perhaps programmatically) the into clause
that will not be recognized by the DBMS.

I would do something like :

SqlPrepareAndExecute(Statement,vh1,vh2,vh3)

The routine will just perform the select and will affect the first column to
vh1 (without any concern with the name just using the position), second to
vh2, etc allowing to transport the binding outside of the SQL Statement....

If not acceptable, have a look at System.Reflection that will allow what you
need but I would really drop the tight coupling between SQL code and
application variables...

Also I would check how Gupata SqlWindows handles multiple rows ? Does it
have some kind of mechanism for this ?

Good luck.

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de
news:53**********************************@microsof t.com...
First, thanks a lot for your suggestion.
I try to explain better my problem:

I need to convert in vb.net (asp.net) Gupta SqlWindows application. This
application uses some thousand of Sql statements stored in an external

file.
In SqlWindows i have this function :

SqlPrepareAndExecute("select field1,field2, field3 from TABLE1, TABLE2,

....
where .... into :vh1,:vh2,:vh3")

So i can pass to SqlPrepareAndExecute a string (read from external file)
with the Sql Command (with bind and into variables written as substring
inside the string). In the example vh1,vh2,vh3 are variables declared in

the
caller function of SqlPrepareAndExecute. When SqlPrepareAnd Execute finish
vh1,vh2 and vh3 contain the fetch values retrieved by the select.

Now in vb.net i dont't want to change all the Sql statements. I think to
build a function SqlPrepareAndExecute with the existing string parameter

and
another parameter (a object array) for receiving fetch value. But after
execution i have the problem to dinamically assign the value in object

array
to the real into variables (in the example vh1,vh2,vh3).

Thanks in advance for suggestions and help.

Piermaria
"Patrice" wrote:
You could likely use System.Reflection.

Also, having the whole scenario could help to raise a whole new solution
than using "indirection" (i.e. having a variable that contains the name of the variable you want to access).

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de news:D3**********************************@microsof t.com...
> Does exists a function GetVariableValueFromName (o something similar) to get
> a variable value from a string that contains variable name ?
> Example:
> Dim Target as string
> Dim Source as string = "aaa"
> Dim sSourceName as string = "Source" 'This is the name of the variable
> Target = GetVariableValueFromName(sSourceName)
> ' -- now Target has the value "aaa"
>
> Thanks
>
> Piermaria
>
>


Jul 21 '05 #6

P: n/a
In VB.NET you can easily have multiple parameters using the ParamArray
keyword...

You could also create explicitely multiple overloads depending on the
easiest way (i you have a low different number of parameters and a unique
combination of types, it would give type safety as a benefit). You can
always start by the quick "ParamArray" way and move on at a later time once
you have are more confident with the whole design...

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de
news:08**********************************@microsof t.com...
Thanks for your answer.
I agree to cut the into clause of the sql statement.
But i don't understand how build the SqlPrepareAndExecute function.
It must have a variable number of paramters vh1,vh2,vh3,vh4, ... depending
from the number of fields extracting by the select. I could have a ParamArray paramater but in .Net this is only byval and not byref. What do you think
about this ?
About multiple rows: for now we can ignore this problem because most of all the select return only one row.

Piermaria

"Patrice" wrote:
AFAIK you'll have anyway to drop (perhaps programmatically) the into clause that will not be recognized by the DBMS.

I would do something like :

SqlPrepareAndExecute(Statement,vh1,vh2,vh3)

The routine will just perform the select and will affect the first column to vh1 (without any concern with the name just using the position), second to vh2, etc allowing to transport the binding outside of the SQL Statement....
If not acceptable, have a look at System.Reflection that will allow what you need but I would really drop the tight coupling between SQL code and
application variables...

Also I would check how Gupata SqlWindows handles multiple rows ? Does it
have some kind of mechanism for this ?

Good luck.

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de news:53**********************************@microsof t.com...
First, thanks a lot for your suggestion.
I try to explain better my problem:

I need to convert in vb.net (asp.net) Gupta SqlWindows application. This application uses some thousand of Sql statements stored in an external

file.
In SqlWindows i have this function :

SqlPrepareAndExecute("select field1,field2, field3 from TABLE1, TABLE2,
....
where .... into :vh1,:vh2,:vh3")

So i can pass to SqlPrepareAndExecute a string (read from external
file) with the Sql Command (with bind and into variables written as substring inside the string). In the example vh1,vh2,vh3 are variables declared in the
caller function of SqlPrepareAndExecute. When SqlPrepareAnd Execute
finish vh1,vh2 and vh3 contain the fetch values retrieved by the select.

Now in vb.net i dont't want to change all the Sql statements. I think to build a function SqlPrepareAndExecute with the existing string parameter and
another parameter (a object array) for receiving fetch value. But
after execution i have the problem to dinamically assign the value in object

array
to the real into variables (in the example vh1,vh2,vh3).

Thanks in advance for suggestions and help.

Piermaria
"Patrice" wrote:

> You could likely use System.Reflection.
>
> Also, having the whole scenario could help to raise a whole new solution > than using "indirection" (i.e. having a variable that contains the name of
> the variable you want to access).
>
> Patrice
>
> --
>
> "Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le

message de
> news:D3**********************************@microsof t.com...
> > Does exists a function GetVariableValueFromName (o something
similar) to
> get
> > a variable value from a string that contains variable name ?
> > Example:
> > Dim Target as string
> > Dim Source as string = "aaa"
> > Dim sSourceName as string = "Source" 'This is the name of the

variable > > Target = GetVariableValueFromName(sSourceName)
> > ' -- now Target has the value "aaa"
> >
> > Thanks
> >
> > Piermaria
> >
> >
>
>
>


Jul 21 '05 #7

P: n/a
GP
Hi Piermaria,

There are many problems in supporting SQLWindows bind and into variables
(and expressions). We have developed our PPJ Framework as part our Porting
Project effort to port SQLWindows applications to .NET (C#) and we support
most Sql.* statements including bind and into variables and expressions. See
www.iceteagroup.com for more info.

The major problems are: scope, bind expressions, and bind controls. In
SQLWindows you can have sql statements like this: SqlPrepareAndExecute(h,
"select name from company into :m_company[getNext()].name"). The m_company
array can exist in any scope since your code might have called
SqlVarSetup(h) anywhere. The getNext() function (or a nIndex variable) can
also live anywhere, including a form, the global scope, or even
locals/parameters (which are impossible to access using reflection).
Additionally the bind variable can also be a control or a table column. To
make matter a bit more complicated, as you know, the scope can be changed
while fetching rows but calling SqlVarSetup() before the next
SqlFetchNext(). Sql statements can also be built dynamically by the
application (which is the most common case) and therefore it's very hard to
detect the variables involved. In order to support SQLWindows original code
we use a mini interpreter with a lot of reflection optimization to preserve
performance. It really required a lot of work.

The only other alternative is to re-engineer your application and use
ADO.NET parameters. Another problem you might face is that ADO.NET throws
exceptions (not normalized either, but specific to the database) while your
SQLWindows application uses When SQLError constructs which have no equal in
the OOP world. We replicated them either as try/catch blocks (which changes
the logic of the application) or as delegate error handlers (which preserves
the original logic but makes the code look a bit awkward).

--
Best regards,
Gianluca Pivato
--
Ice Tea Group, LLC
www.iceteagroup.com
"Piermaria" <Pi*******@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
Thanks for your answer.
I agree to cut the into clause of the sql statement.
But i don't understand how build the SqlPrepareAndExecute function.
It must have a variable number of paramters vh1,vh2,vh3,vh4, ... depending
from the number of fields extracting by the select. I could have a ParamArray paramater but in .Net this is only byval and not byref. What do you think
about this ?
About multiple rows: for now we can ignore this problem because most of all the select return only one row.

Piermaria

"Patrice" wrote:
AFAIK you'll have anyway to drop (perhaps programmatically) the into clause that will not be recognized by the DBMS.

I would do something like :

SqlPrepareAndExecute(Statement,vh1,vh2,vh3)

The routine will just perform the select and will affect the first column to vh1 (without any concern with the name just using the position), second to vh2, etc allowing to transport the binding outside of the SQL Statement....
If not acceptable, have a look at System.Reflection that will allow what you need but I would really drop the tight coupling between SQL code and
application variables...

Also I would check how Gupata SqlWindows handles multiple rows ? Does it
have some kind of mechanism for this ?

Good luck.

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de news:53**********************************@microsof t.com...
First, thanks a lot for your suggestion.
I try to explain better my problem:

I need to convert in vb.net (asp.net) Gupta SqlWindows application. This application uses some thousand of Sql statements stored in an external

file.
In SqlWindows i have this function :

SqlPrepareAndExecute("select field1,field2, field3 from TABLE1, TABLE2,
....
where .... into :vh1,:vh2,:vh3")

So i can pass to SqlPrepareAndExecute a string (read from external
file) with the Sql Command (with bind and into variables written as substring inside the string). In the example vh1,vh2,vh3 are variables declared in the
caller function of SqlPrepareAndExecute. When SqlPrepareAnd Execute
finish vh1,vh2 and vh3 contain the fetch values retrieved by the select.

Now in vb.net i dont't want to change all the Sql statements. I think to build a function SqlPrepareAndExecute with the existing string parameter and
another parameter (a object array) for receiving fetch value. But
after execution i have the problem to dinamically assign the value in object

array
to the real into variables (in the example vh1,vh2,vh3).

Thanks in advance for suggestions and help.

Piermaria
"Patrice" wrote:

> You could likely use System.Reflection.
>
> Also, having the whole scenario could help to raise a whole new solution > than using "indirection" (i.e. having a variable that contains the name of
> the variable you want to access).
>
> Patrice
>
> --
>
> "Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le

message de
> news:D3**********************************@microsof t.com...
> > Does exists a function GetVariableValueFromName (o something
similar) to
> get
> > a variable value from a string that contains variable name ?
> > Example:
> > Dim Target as string
> > Dim Source as string = "aaa"
> > Dim sSourceName as string = "Source" 'This is the name of the

variable > > Target = GetVariableValueFromName(sSourceName)
> > ' -- now Target has the value "aaa"
> >
> > Thanks
> >
> > Piermaria
> >
> >
>
>
>


Jul 21 '05 #8

P: n/a
Gianluca,
could you contact me at: NO***************@compet-e.it (cu NO and SPAM) in
private form to talk about your product ?

Thanks
Piermaria

"GP" wrote:
Hi Piermaria,

There are many problems in supporting SQLWindows bind and into variables
(and expressions). We have developed our PPJ Framework as part our Porting
Project effort to port SQLWindows applications to .NET (C#) and we support
most Sql.* statements including bind and into variables and expressions. See
www.iceteagroup.com for more info.

The major problems are: scope, bind expressions, and bind controls. In
SQLWindows you can have sql statements like this: SqlPrepareAndExecute(h,
"select name from company into :m_company[getNext()].name"). The m_company
array can exist in any scope since your code might have called
SqlVarSetup(h) anywhere. The getNext() function (or a nIndex variable) can
also live anywhere, including a form, the global scope, or even
locals/parameters (which are impossible to access using reflection).
Additionally the bind variable can also be a control or a table column. To
make matter a bit more complicated, as you know, the scope can be changed
while fetching rows but calling SqlVarSetup() before the next
SqlFetchNext(). Sql statements can also be built dynamically by the
application (which is the most common case) and therefore it's very hard to
detect the variables involved. In order to support SQLWindows original code
we use a mini interpreter with a lot of reflection optimization to preserve
performance. It really required a lot of work.

The only other alternative is to re-engineer your application and use
ADO.NET parameters. Another problem you might face is that ADO.NET throws
exceptions (not normalized either, but specific to the database) while your
SQLWindows application uses When SQLError constructs which have no equal in
the OOP world. We replicated them either as try/catch blocks (which changes
the logic of the application) or as delegate error handlers (which preserves
the original logic but makes the code look a bit awkward).

--
Best regards,
Gianluca Pivato
--
Ice Tea Group, LLC
www.iceteagroup.com
"Piermaria" <Pi*******@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
Thanks for your answer.
I agree to cut the into clause of the sql statement.
But i don't understand how build the SqlPrepareAndExecute function.
It must have a variable number of paramters vh1,vh2,vh3,vh4, ... depending
from the number of fields extracting by the select. I could have a

ParamArray
paramater but in .Net this is only byval and not byref. What do you think
about this ?
About multiple rows: for now we can ignore this problem because most of

all
the select return only one row.

Piermaria

"Patrice" wrote:
AFAIK you'll have anyway to drop (perhaps programmatically) the into clause that will not be recognized by the DBMS.

I would do something like :

SqlPrepareAndExecute(Statement,vh1,vh2,vh3)

The routine will just perform the select and will affect the first column to vh1 (without any concern with the name just using the position), second to vh2, etc allowing to transport the binding outside of the SQL Statement....
If not acceptable, have a look at System.Reflection that will allow what you need but I would really drop the tight coupling between SQL code and
application variables...

Also I would check how Gupata SqlWindows handles multiple rows ? Does it
have some kind of mechanism for this ?

Good luck.

Patrice

--

"Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le message de news:53**********************************@microsof t.com...
> First, thanks a lot for your suggestion.
> I try to explain better my problem:
>
> I need to convert in vb.net (asp.net) Gupta SqlWindows application. This > application uses some thousand of Sql statements stored in an external
file.
> In SqlWindows i have this function :
>
> SqlPrepareAndExecute("select field1,field2, field3 from TABLE1, TABLE2, ....
> where .... into :vh1,:vh2,:vh3")
>
> So i can pass to SqlPrepareAndExecute a string (read from external file) > with the Sql Command (with bind and into variables written as substring > inside the string). In the example vh1,vh2,vh3 are variables declared in the
> caller function of SqlPrepareAndExecute. When SqlPrepareAnd Execute finish > vh1,vh2 and vh3 contain the fetch values retrieved by the select.
>
> Now in vb.net i dont't want to change all the Sql statements. I think to > build a function SqlPrepareAndExecute with the existing string parameter and
> another parameter (a object array) for receiving fetch value. But after > execution i have the problem to dinamically assign the value in object
array
> to the real into variables (in the example vh1,vh2,vh3).
>
> Thanks in advance for suggestions and help.
>
> Piermaria
>
>
> "Patrice" wrote:
>
> > You could likely use System.Reflection.
> >
> > Also, having the whole scenario could help to raise a whole new solution > > than using "indirection" (i.e. having a variable that contains the name of
> > the variable you want to access).
> >
> > Patrice
> >
> > --
> >
> > "Piermaria" <Pi*******@discussions.microsoft.com> a écrit dans le
message de
> > news:D3**********************************@microsof t.com...
> > > Does exists a function GetVariableValueFromName (o something similar) to
> > get
> > > a variable value from a string that contains variable name ?
> > > Example:
> > > Dim Target as string
> > > Dim Source as string = "aaa"
> > > Dim sSourceName as string = "Source" 'This is the name of the variable > > > Target = GetVariableValueFromName(sSourceName)
> > > ' -- now Target has the value "aaa"
> > >
> > > Thanks
> > >
> > > Piermaria
> > >
> > >
> >
> >
> >


Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.