modul:
Module modulDefault
Public ConfigFilePath As String = "\config.ini"
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName As String, ByVal KeyName As String, ByVal keydefault As String, ByVal FileName As String)
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName As String, ByVal KeyName As String, ByVal keydefault As String, ByVal ReturnedString As String, ByVal RSSize As Integer, ByVal FileName As String) As Integer
Public Sub WriteINI(ByVal INISection As String, ByVal INIKey As String, ByVal INIValue As String, ByVal INIFile As String)
Call WritePrivateProfileString(INISection, INIKey, INIValue, INIFile)
End Sub
Public Function ReadINI(ByVal INISection As String, ByVal INIKey As String, ByVal INIFile As String) As String
Dim StringBuffer As String
Dim StringBufferSize As Long
StringBuffer = Space$(255)
StringBufferSize = Len(StringBuffer)
StringBufferSize = GetPrivateProfileString(INISection, INIKey, "", StringBuffer, StringBufferSize, INIFile)
If StringBufferSize > 0 Then
ReadINI = Left$(StringBuffer, StringBufferSize)
Else
ReadINI = ""
End If
End Function
End Module
formulář, ze kterého to volám:
Public Class formLoad
Private Sub Me_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = frmTitle
Dim tcpListener As Net.Sockets.TcpListener 'dokáže poslouchat příchozí TCP připojení
Dim Port As Integer = ReadINI("SERVER", "port", ConfigFilePath) 'budeme používat tento port
tcpListener = New Net.Sockets.TcpListener(System.Net.IPAddress.Any, Port) 'vytvoříme TCP Listener
...
End Sub
End Class
teď to hlásí špatnou konverzi na řádku, kde deklaruji proměnnou Port: Conversion from string "" to type 'Integer' is not valid. u proměnné port jsem zkoušel měnil typ i na ostatní, ale nejde, podle mne když to bude číslo, tak to má být Integer ne?
|