473,385 Members | 1,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

GetVariableValueFromName

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
8 1550
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Piermaria | last post by:
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 =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.