Structure passing problem
-
I'm moving from VB6 to VS 2008. And need help with a data structure problem. In a Public code module in my VS 2008 project, I defined a structure: Public structure db_connection dim connection_string as string End structure Then defined a variable as the structure type: Public db_con as db_connection When I pass the db_con variable to a sub: sub db_create_cs(dbc as db_connection) dbc.connection_string = "some values" end sub I expected the db_con.connection_string value to equal "some values" after the call. Regards.
-
I'm moving from VB6 to VS 2008. And need help with a data structure problem. In a Public code module in my VS 2008 project, I defined a structure: Public structure db_connection dim connection_string as string End structure Then defined a variable as the structure type: Public db_con as db_connection When I pass the db_con variable to a sub: sub db_create_cs(dbc as db_connection) dbc.connection_string = "some values" end sub I expected the db_con.connection_string value to equal "some values" after the call. Regards.
Check to see if in your declaration,
sub db_create_cs(dbc as db_connection)
the parameter is ByRef as opposed to ByVal. Also, you might want to re-structure your program to define db_create_cs as a function rather than a sub. (my 2 cents) Hope this helps. :thumbsup:
-
I'm moving from VB6 to VS 2008. And need help with a data structure problem. In a Public code module in my VS 2008 project, I defined a structure: Public structure db_connection dim connection_string as string End structure Then defined a variable as the structure type: Public db_con as db_connection When I pass the db_con variable to a sub: sub db_create_cs(dbc as db_connection) dbc.connection_string = "some values" end sub I expected the db_con.connection_string value to equal "some values" after the call. Regards.
If you don't specify "ByRef" or "ByVal", then the parameter is "ByVal" by default. You want:
Sub db_create_cs(ByRef dbc As db_connection)
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
-
Check to see if in your declaration,
sub db_create_cs(dbc as db_connection)
the parameter is ByRef as opposed to ByVal. Also, you might want to re-structure your program to define db_create_cs as a function rather than a sub. (my 2 cents) Hope this helps. :thumbsup:
ByRef cured the problem. I was going down fast. thanks In the actual program it is a function. I slimmed down the code for my question. Thanks for the comment though, and help.
-
If you don't specify "ByRef" or "ByVal", then the parameter is "ByVal" by default. You want:
Sub db_create_cs(ByRef dbc As db_connection)
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
I thought I checked that. It fixed the problem. Thanks for the help. I sense a series of adjustments going from VB6 to VS 2008 is ahead.
-
I thought I checked that. It fixed the problem. Thanks for the help. I sense a series of adjustments going from VB6 to VS 2008 is ahead.
The problem is that for VB6, the default was "ByRef", but for VB.NET, the default is "ByVal".
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com