这是我的第一个VB代码,所以要善良:)
我无法从名为station_num
的类获取名为Pinger
的变量到类StationsIdentifier
我收到了错误"' station_num'没有宣布。由于其保护级别,它可能无法访问"
这是代码:
Public Class Pinger
Public Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtStation.KeyPress
If Asc(e.KeyChar) = 13 Then '/ When ENTER key is pressed
Dim temp, pinger_file_name As String ' save names for variable
Dim station_num As String
station_num = txtStation.Text ' set station number from text specified in text box
temp = Environment.GetEnvironmentVariable("temp") ' get TEMP variable from system
pinger_file_name = temp + "\Pinger.txt" ' set TEMP FILE NAME with full path
If System.IO.File.Exists(pinger_file_name) = True Then ' check if file exist
System.IO.File.Delete(pinger_file_name) ' delete file
End If
'System.Threading.Thread.Sleep(100000) ' sleep
Dim oWrite As System.IO.StreamWriter
oWrite = IO.File.CreateText(pinger_file_name)
oWrite.WriteLine(station_num)
oWrite.Close()
Call StationsIdentifier.FindStation()
End If
End Sub
Public Sub PingButton_Click(sender As Object, e As EventArgs) Handles PingButton.Click
Dim temp, pinger_file_name As String ' save names for variable
Dim station_num As String
station_num = txtStation.Text ' set station number from text specified in text box
temp = Environment.GetEnvironmentVariable("temp") ' get TEMP variable from system
pinger_file_name = temp + "\Pinger.txt" ' set TEMP FILE NAME with full path
If System.IO.File.Exists(pinger_file_name) = True Then ' check if file exist
System.IO.File.Delete(pinger_file_name) ' delete file
End If
'System.Threading.Thread.Sleep(100000) ' sleep
Dim oWrite As System.IO.StreamWriter
oWrite = IO.File.CreateText(pinger_file_name)
oWrite.WriteLine(station_num)
oWrite.Close()
Call StationsIdentifier.FindStation()
End Sub
End Class
Public Class StationsIdentifier
Shared Sub FindStation()
MsgBox("station number is:" + station_num)
End Sub
End Class
答案 0 :(得分:0)
在StationIdentifier
类Shared Sub FindStation
中,您尝试访问变量station_num
,但该变量未在该函数或该类中声明。
我认为你的意思是将station_num
传递给find函数......
Shared Sub FindStation(ByVal station_num As String)
' Do stuff to find the station here
End Sub