mysql - Passing parameters by value -


to all, learning visual basic , working on windows application. have 2 text box methods (usernametextbox, passwordtextbox). in user enter data , hit submit button (button1_click). method call connect. want able do, have user type-in username , password. passed value, not reference connect() when invoked inside button method.

kind of authentication page. have values in connect(firstname:="johndoe", password:="password") - testing mysql server , demonstration of trying attempt.

imports mysql.data.mysqlclient public class securepasswordlist     dim conn new mysqlconnection     public sub connect(byval firstname string, byval password string)         dim databasename string = "mysql"         dim server string = "10.1.0.0"         if not conn nothing conn.close()         conn.connectionstring = string.format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, firstname, password, databasename)         try             conn.open()         catch ex exception             msgbox(ex.message)         end try         conn.close()     end sub     private sub button1_click(sender object, e eventargs) handles button1.click         connect(firstname:="johndoe", password:="password")     end sub      private sub securepasswordlist_load(sender object, e eventargs) handles mybase.load      end sub      private sub usernametextbox_textchanged(sender object, e eventargs) handles usernametextbox.textchanged         dim firstname string         firstname = usernametextbox.text     end sub      private sub passwordtextbox_textchanged(sender object, e eventargs) handles passwordtextbox.textchanged         dim password string         password = passwordtextbox.text     end sub end class 

change

private sub button1_click(sender object, e eventargs) handles button1.click     connect(firstname:="johndoe", password:="password") end sub 

to

private sub button1_click(sender object, e eventargs) handles button1.click     connect(firstname, password) end sub 

but should ensure firstname , password initialized , held class variables. move

dim firstname string dim firstname string 

to in class, not event handling functions (click etc). this:

public class securepasswordlist     dim conn new mysqlconnection     dim firstname string     dim firstname string 

but can redo code (as want text controls):

imports mysql.data.mysqlclient public class securepasswordlist     dim conn new mysqlconnection     public sub connect(byval firstname string, byval password string)         dim databasename string = "mysql"         dim server string = "10.1.0.0"         if not conn nothing conn.close()         conn.connectionstring = string.format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, firstname, password, databasename)         try             conn.open()         catch ex exception             msgbox(ex.message)         end try         conn.close()     end sub     private sub button1_click(sender object, e eventargs) handles button1.click         connect(usernametextbox.text, passwordtextbox.text)     end sub  end class 

i dont think passing value or reference issue here. want connect function modify strings passed it? doubt it. in case value or reference fine. strings passed copied instance reference, in effect passed value unless use byref in function declaration will. every class (int, string, etc) passed differently in vb default. need check each type know if specify byval or byref. string creates copy of string if use byval, accessed using pointer newly created string. depends how deep want dig too


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -