从另一个内部调用一个SUB的问题。 [英] Problem calling one SUB from within another.

查看:71
本文介绍了从另一个内部调用一个SUB的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。我正在使用VB express 2005,我无法从另一个内部调用一个子函数。你能帮帮忙吗?


我为按钮点击编写了一个事件程序。现在我想在文本框的ENTER事件中调用该子。

我试过简单地将子名称复制到ENTER子集但它不能工作,我收到错误消息表达式预期"以及ByVal下的下划线参数的一部分。


导入MySql.Data.MySqlClient

导入System.Data


公共类frmLogin

Dim conn As MySqlConnection


Private Sub Button_cancel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理Button_cancel.Click

Application.Exit()''杀死应用程序/进程

End Sub


Private Sub Button_login_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理Button_login.Click

''示例连接字符串:server = localhost; user id = mike;密码= 12345; database = in_out

conn = New MySqlConnection

Dim Ser,Use,Pas As String

Ser = TextBox_server.Text& " ;;"

使用= TextBox_username.Text& ""

Pas = TextBox_password.Text& " ;;"

''

conn.ConnectionString =" server =" &安培; Ser& user id =" &安培;使用& "密码= QUOT; &安培;帕斯& " database = nfenlon_TestDB01"

''

尝试

conn.Open()

MessageBox.Show( 连接成功打开)

conn.Close()

捕获myerror作为MySqlException

MessageBox.Show("错误连接到数据库:"& myerror.Message)

最后

conn.Dispose()

结束尝试

' '

End Sub


Private Sub frmLogin_Load(ByVal sender As Object,ByVal e As System.EventArgs)Handles Me.Load

TextBox_server.Focus()

End Sub


Private Sub TextBox_password_Enter(ByVal sender As Object,ByVal e As System.EventArgs)处理TextBox_password.Enter

Button_login_Click(byval sender As Object,byval e As System.EventArgs)Handles Button_login.Click

End Su b

结束类

解决方案


大家好。我正在使用VB express 2005,我无法从另一个内部调用一个子函数。你能帮帮忙吗?


我为按钮点击编写了一个事件程序。现在我想在文本框的ENTER事件中调用该子。

我试过简单地将子名称复制到ENTER子集但它不能工作,我收到错误消息表达式预期"以及ByVal下的下划线参数的一部分。


导入MySql.Data.MySqlClient

导入System.Data


公共类frmLogin

Dim conn As MySqlConnection


Private Sub Button_cancel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理Button_cancel.Click

Application.Exit()''杀死应用程序/进程

End Sub


Private Sub Button_login_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理Button_login.Click

''示例连接字符串:server = localhost; user id = mike;密码= 12345; database = in_out

conn = New MySqlConnection

Dim Ser,Use,Pas As String

Ser = TextBox_server.Text& " ;;"

使用= TextBox_username.Text& ""

Pas = TextBox_password.Text& " ;;"

''

conn.ConnectionString =" server =" &安培; Ser& user id =" &安培;使用& "密码= QUOT; &安培;帕斯& " database = nfenlon_TestDB01"

''

尝试

conn.Open()

MessageBox.Show( 连接成功打开)

conn.Close()

捕获myerror作为MySqlException

MessageBox.Show("错误连接到数据库:"& myerror.Message)

最后

conn.Dispose()

结束尝试

' '

End Sub


Private Sub frmLogin_Load(ByVal sender As Object,ByVal e As System.EventArgs)Handles Me.Load

TextBox_server.Focus()

End Sub


Private Sub TextBox_password_Enter(ByVal sender As Object,ByVal e As System.EventArgs)处理TextBox_password.Enter

Button_login_Click(byval sender As Object,byval e As System.EventArgs)Handles Button_login.Click

End Su b

结束班



我没有费心阅读你所有的代码,但如果你想当用户进入文本框时,转到按钮单击事件中的代码,您也可以让click事件处理程序处理enter事件。


ok。大。我到底怎么做???



ok。大。我到底怎么做?



请注意,处理程序方法都有关键字handle在他们的最后。您可以提供要以其处理的以逗号分隔的事件列表。现在,我不确定你是否能够做到这一点,因为Enter和click可能有不同的签名。如果是这种情况,您可以直接从enter处理程序调用click事件,提供Nothing作为参数,或者两个事件都可以调用公共函数。


Hi guys. I''m using VB express 2005 and im having trouble calling one sub function from inside another. Can you help?

I have written an event procedure for a button click. Now i want to call that sub in the ENTER event of a textbox.
I have tried simply copying the name of the sub into the ENTER sub but it wont work, i get the error message "expression expected" and an underline under the "ByVal" part of the argument.


Imports MySql.Data.MySqlClient
Imports System.Data

Public Class frmLogin
Dim conn As MySqlConnection

Private Sub Button_cancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_cancel.Click
Application.Exit() ''kills the application/process
End Sub

Private Sub Button_login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_login.Click
''an example connection string: server=localhost; user id=mike; password=12345; database=in_out
conn = New MySqlConnection
Dim Ser, Use, Pas As String
Ser = TextBox_server.Text & ";"
Use = TextBox_username.Text & ";"
Pas = TextBox_password.Text & ";"
''
conn.ConnectionString = "server=" & Ser & "user id=" & Use & "password=" & Pas & "database=nfenlon_TestDB01"
''
Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
''
End Sub

Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox_server.Focus()
End Sub

Private Sub TextBox_password_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox_password.Enter
Button_login_Click(byval sender As Object, byval e As System.EventArgs) Handles Button_login.Click
End Sub
End Class

解决方案

Hi guys. I''m using VB express 2005 and im having trouble calling one sub function from inside another. Can you help?

I have written an event procedure for a button click. Now i want to call that sub in the ENTER event of a textbox.
I have tried simply copying the name of the sub into the ENTER sub but it wont work, i get the error message "expression expected" and an underline under the "ByVal" part of the argument.


Imports MySql.Data.MySqlClient
Imports System.Data

Public Class frmLogin
Dim conn As MySqlConnection

Private Sub Button_cancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_cancel.Click
Application.Exit() ''kills the application/process
End Sub

Private Sub Button_login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_login.Click
''an example connection string: server=localhost; user id=mike; password=12345; database=in_out
conn = New MySqlConnection
Dim Ser, Use, Pas As String
Ser = TextBox_server.Text & ";"
Use = TextBox_username.Text & ";"
Pas = TextBox_password.Text & ";"
''
conn.ConnectionString = "server=" & Ser & "user id=" & Use & "password=" & Pas & "database=nfenlon_TestDB01"
''
Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
''
End Sub

Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox_server.Focus()
End Sub

Private Sub TextBox_password_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox_password.Enter
Button_login_Click(byval sender As Object, byval e As System.EventArgs) Handles Button_login.Click
End Sub
End Class

I didn''t bother reading all of you''re code, but if you''re trying to go to the code in the button click event when the user enters the text box, you could just have the click event handler handle the enter event as well.


ok. great. how exactly do i do that???


ok. great. how exactly do i do that???

Notice that the handler methods all have the keyword "handles" at the end of them. You can supply a comma-separated list of events that you want it to handle. Now, I''m not sure if you''re going to be able to do that, since it''s likely that Enter and click probably have different signatures. If that''s the case, you can either call the click event directly from the enter handler, supplying Nothing as the arguments, or else both events can call a common function.


这篇关于从另一个内部调用一个SUB的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆