Allora :
Le variabili usate nella sub si trovano in un modulo in cui, per semplicità visiva, metto tutte le variabili che è necessario resettare per azzerare il programma, cmq in questo modulo per il momento, ci sono solo queste variabili:
codice:
Module ModVars
Public UserName, PassWord, IDuT As String
End Module
qui la dichiarazione, mentre invece la valorizzazione avviene in una classe che si occupa di reperire informazioni da una pagina web con il metodo dei socket...
codice:
Public Class WebClient
Private Connesso As Boolean
Private client As System.Net.Sockets.TcpClient
Private Const BYTES_TO_READ As Integer = 255
Private readBuffer(BYTES_TO_READ) As Byte
Public Sub Connect()
client = New System.Net.Sockets.TcpClient("www.indirizzodelsito.com", 80)
client.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf doRead, Nothing)
End Sub
Public Function Action(ByVal Act As String) As String
Dim Richiesta, Oggetto As String
Dim Op As String = ""
Select Case Act
Case "ConnOn"
Connect()
Op = "ok"
Case "ConnOff"
client.Close()
Op = "ok"
Case "LogIn"
Oggetto = "CheckUser.asp?Utente=" & UserName & "&Password=" & PassWord
Richiesta = "GET /" & Oggetto & " HTTP/1.1" & vbCrLf & "Accept: */*" & vbCrLf & "Accept-Language: en-us" & vbCrLf & "Accept-Encoding: " & vbCrLf & "User-Agent: User agent scelto in modo da far identificare l'applicazione al server" & vbCrLf & "Host: " & "www.indirizzodelsito.com" & vbCrLf & "Connection: Keep-Alive" & vbCrLf & vbCrLf
SendMessage(Richiesta)
Case "LogOut"
Op = "no"
End Select
If Op = "" Then Op = "Doh'!"
Action = Op
End Function
Private Sub SendMessage(ByVal msg As String)
Dim sw As IO.StreamWriter
Try
sw = New IO.StreamWriter(client.GetStream)
sw.Write(msg)
sw.Flush()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub doRead(ByVal ar As System.IAsyncResult)
Dim totalRead As Integer
Try
Catch ex As Exception
End Try
totalRead = client.GetStream.EndRead(ar)
If totalRead > 0 Then
Dim receivedString As String = System.Text.Encoding.UTF8.GetString(readBuffer, 0, totalRead)
messageReceived(receivedString)
End If
Try
Catch ex As Exception
End Try
client.GetStream.BeginRead(readBuffer, 0, BYTES_TO_READ, AddressOf doRead, Nothing)
End Sub
Private Sub messageReceived(ByVal message As String)
Dim TmpVar()
Try
If InStr(message, "[Trace]") > 0 Then ' Qui viene effettuato un
TmpVar = Strings.Split(message, "[Trace]") ' semplice parsing della risposta
IDuT = Replace(Trim(TmpVar(1)), "ID#", "") ' assegnando il Valore alla variabile
' fino qui tutto ok
MainFrm.Logged() ' a questo punto passa il controllo
' al form principale
End If
Catch ex As Exception
Debug.Print(ex.Message) 'nessun errore o messaggio
End Try
End Sub
End Class
Seguendo il flusso si arriva alla sub Logged() del MainFrm che è dove mi si verifica il problema, riesco ad avere in quella sub risposte dall'immediata o inserendo messagebox
il flusso prosegue senza errori, ma non posso cambiare le proprieta dei componenti sul form, non solo la visibilità, ma anche posizione, colori, text.... niente di niente...
Spero riusciate ad aiutarmi a capire dove sbaglio... nel frattempo vi ringrazio ancora per l'attenzione...