borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (banner)Next Topic (Error Trapping for NETWORK Printer!) New Topic New Poll Post Reply
AndreaVB Forum : VB General : please tell me why my customer form gets hung up
Poster Message
kabba
Level: Trainee

Registered: 24-02-2006
Posts: 2

icon please tell me why my customer form gets hung up

heres the code:

Option Explicit

Dim hhkLowLevelKybd As Long
Dim timeVariable As Long

Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function ClipCursorByNum Lib "user32" Alias "ClipCursor" (ByVal num As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

' Clip mouse Declarations

Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Const SPI_SCREENSAVERRUNNING = 97
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1

Public LastTimeofUserInput As Long
Public XY As Long
Public guestToggle As Integer
Public Logouttimer As Integer


Private Sub Background_Click()
addLog "Memberscreen started at " & Now
    Splash
    showMember
    Me.Status.Alignment = 0
End Sub

Private Sub Splash()
    Dim tempMouseVar
    XY = XY + 1
    If Background.Visible = True Then Background.Visible = False
    LastTimeofUserInput = 0
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
    Splash
    showMember
   ' Me.Status.Alignment = 0
End Sub

Private Sub Form_Load()
    If App.PrevInstance = True Then
        MsgBox "There is an instance already running. Cant run one more"
        Unload Me
    Else
        addLog "Start Client at " & Now
        Me.Status.Caption = "Press Any Key To Continue"
        Me.Show
        guestToggle = 1
        frmLogin.createIcon
        frmLogin.Visible = False
'       main.Show
        Me.WindowState = 2
        Frame1.Left = (Screen.Width - Frame1.Width) / 2
        Frame1.Top = (Screen.Height - Frame1.Height) / 2
'       Me.Left = (Screen.Width - Me.Width) / 2
'       Me.Top = (Screen.Height - Me.Height) / 2
        hideAll
        Show
        Background.Top = 0
        Background.Left = 0
        Banner.Picture = LoadPicture(App.Path & "\Banner.jpg")
        Background.Picture = LoadPicture(App.Path & "\Splash.jpg")
'        FormLock
'        Lock_Inputs
        Connect_to_Server
        Me.SetFocus
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    FormUnlock
End Sub


Private Sub Guest_Member_Click()
    hideMember
    showGuest
End Sub

Private Sub Member1_Click()
    hideGuest
    showMember
End Sub

Private Sub showGuest()
    Banner.Visible = True
    HostName.Visible = True
    tac.Visible = True
    terms.Visible = True
    guest.Visible = True
    fname.Visible = True
    fNameText.Visible = True
    lname.Visible = True
    lNameText.Visible = True
    age.Visible = True
    ageText.Visible = True
    ageYears.Visible = True
    gender.Visible = True
    Option1.Visible = True
    Option2.Visible = True
    telephone.Visible = True
    telText.Visible = True
    login1.Visible = True
    reset1.Visible = True
    member1.Visible = True
    Check2.Visible = True
    Label2.Visible = True
    gTime.Visible = True
    Status.Visible = True
    Status.Caption = "Enter your details for Guest Login"
    guestprice.Visible = True
    gTime.Visible = True
    tac.Height = 3855
    terms.Height = 3375
End Sub

Private Sub hideGuest()
    Banner.Visible = False
    HostName.Visible = False
    tac.Visible = False
    terms.Visible = False
    guest.Visible = False
    gTime.Visible = False
    fname.Visible = False
    fNameText.Visible = False
    lname.Visible = False
    lNameText.Visible = False
    age.Visible = False
    ageText.Visible = False
    ageYears.Visible = False
    gender.Visible = False
    Option1.Visible = False
    Option2.Visible = False
    telephone.Visible = False
    telText.Visible = False
    login1.Visible = True
    reset1.Visible = True
    member1.Visible = False
    Check2.Visible = False
    Label2.Visible = False
    gTime.Visible = False
    Status.Visible = False
    Status.Caption = ""
    guestprice.Visible = False
End Sub

Private Sub showMember()
    Banner.Visible = True
    HostName.Visible = True
    tac.Visible = True
    terms.Visible = True
    user.Visible = True
    uname.Visible = True
    Text1.Visible = True
    password.Visible = True
    Text2.Visible = True
    Option3.Visible = True
    Option4.Visible = True
    Login.Visible = True
    Reset.Visible = True
    Guest_Member.Visible = True
    Check1.Visible = True
    mTime.Visible = True
    Label1.Visible = True
    Status.Visible = True
    Status.Caption = "Enter your Username and Password to login"
    tac.Height = 6735
    terms.Height = 6255

End Sub

Private Sub hideMember()
    Banner.Visible = False
    HostName.Visible = False
    tac.Visible = False
    terms.Visible = False
    user.Visible = False
    uname.Visible = False
    Text1.Visible = False
    password.Visible = False
    Text2.Visible = False
    Option3.Visible = False
    Option4.Visible = False
    Login.Visible = False
    Reset.Visible = False
    Guest_Member.Visible = False
    Check1.Visible = False
    Label1.Visible = False
    mTime.Visible = False
    Status.Visible = False
    Status.Caption = ""
End Sub

Public Sub hideAll()
    hideMember
    hideGuest
    Me.Background.Visible = True
    Me.Status.Visible = True
    Me.Status.ForeColor = &H800000
    Me.Status.Alignment = 1
    Me.Status.Caption = "Press Any Key To Continue"
    Me.guestToggle = 1
End Sub

Private Sub Option3_Click()
Me.Option4.Value = False
End Sub

Private Sub Option4_Click()
Me.Option3.Value = False
End Sub

Private Sub Option6_Click()
Me.Option5.Value = False
End Sub

Private Sub Option5_Click()
Me.Option6.Value = False
End Sub

Private Sub Text1_GotFocus()
    If (Text1.Text = "Type Your Username Here") Then Text1.Text = ""
End Sub

Private Sub Text2_GotFocus()
    If (Text2.Text = "Type YourPassword Here") Then Text2.Text = ""
End Sub

Private Sub fNameText_gotFocus()
    If (fNameText.Text = "Type Your First Name Here") Then fNameText.Text = ""
End Sub

Private Sub lNameText_GotFocus()
    If (lNameText.Text = "Type Your Last Name Here") Then lNameText.Text = ""
End Sub

Private Sub Login_Click()
    Dim message As String
    Status.ForeColor = &HC0&
    If ((Text1.Text = "administrator") And (Text2.Text = "infomedia")) Then
        frmLogin.removeIcon
        addLog "Stop Client Program  at " & Now
        End
    End If
    Status.Caption = "User Logging In....."
    If (Text1.Text = "" Or Text2.Text = "" Or Text1.Text = "Type Your Username Here" _
                                           Or Text2.Text = "TypeYourPassword Here") Then
        memberLogin.Status.Caption = "You have Entered an Invalid Username or Password"
    Else
        message = "Login;" & Text1.Text & ";" & Text2.Text
        If (Me.Option3.Value = True) Then
            message = message & ";" & "Internet" & "."
        Else
            message = message & ";" & "Gaming" & "."
        End If
        If (main.clientSocket.State = sckConnected) Then
            main.clientSocket.SendData message
            Me.Timer1.Enabled = True
        End If
    End If
End Sub

Private Sub login1_Click()
    Dim message As String
    Me.Timer1.Enabled = False
    Status.ForeColor = &HC0&
    Status.Caption = "Guest Logging In..... Awaiting Authentication from Server"
    If Not (fNameText = "" Or fNameText.Text = "Type Your First Name Here") Then
        message = "Guest;" & fNameText.Text & ";"
        If Not (lNameText = "" Or lNameText.Text = "Type Your Last Name Here") Then
            message = message & lNameText.Text & ";"
            If Not (ageText = "") Then
                message = message & ageText.Text & ";"
                If Not (Option1.Value = False And Option2.Value = False) Then
                    If (Option1.Value = True) Then message = message & "male" & ";"
                    If (Option2.Value = True) Then message = message & "female" & ";"
                    If Not (telText = "") Then
                        message = message & telText.Text & ";"
                        If (Me.Option3.Value = True) Then
                            message = message & "Internet" & "."
                        Else
                            message = message & "Gaming" & "."
                        End If
                        If (main.clientSocket.State = sckConnected) Then
                            main.clientSocket.SendData message
                            Me.Timer1.Enabled = True
                        End If
                    Else
                        memberLogin.Status.Caption = "You have Entered an invalid Telephone Number"
                    End If
                Else
                    memberLogin.Status.Caption = "You have not Selected your Gender"
                End If
            Else
                memberLogin.Status.Caption = "You have Entered an invalid Age"
            End If
        Else
            memberLogin.Status.Caption = "You have Entered an invalid Last Name"
        End If
    Else
        memberLogin.Status.Caption = "You have Entered an invalid First Name"
    End If
End Sub

Private Sub Option1_Click()
    Me.Option2.Value = True
End Sub

Private Sub Option2_Click()
    Me.Option1.Value = True
End Sub

Public Sub Reset_Click()
    Text1.Text = "Type Your Username Here"
    Text2.Text = "TypeYourPassword Here"
    fNameText.Text = "Type Your First Name Here"
    lNameText.Text = "Type Your Last Name Here"
    ageText = ""
    Option1.Value = 0
    Option2.Value = 0
    telText = ""
    Check1.Value = 0
    Check2.Value = 0
End Sub

Private Sub reset1_Click()
    Reset_Click
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 13) Then Login_Click
    If (KeyAscii = 27) Then Reset_Click
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 13) Then Login_Click
    If (KeyAscii = 27) Then Reset_Click
End Sub

Private Sub Timer1_Timer()
    If (Background.Visible = True) And Not (Me.Status.Caption = "Press Any Key To Continue") Then
        Me.Status.Caption = "Press Any Key To Continue"
    End If
    If (userLoggedIn.Visible = False) Then AlwaysOnTop Me
End Sub

Public Sub FormUnlock()
'    Enable Alt-Tab, Alt-Esc, Ctrl-Esc etc
    If hhkLowLevelKybd <> 0 Then UnhookWindowsHookEx hhkLowLevelKybd
'    Free the mouse
    ClipCursorByNum 0&
'    Tell the system no screen saver is running.
    SystemParametersInfo SPI_SCREENSAVERRUNNING, False, 0, 0
    NotOnTop Me
    ShowCursor True
End Sub

Public Sub FormLock()
    Dim window As RECT
'    Disable Alt-Tab, Alt-Esc, Ctrl-Esc etc
    hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
    hhkLowLevelKybd = 0
'    Restrict the mouse to this window.
'    GetWindowRect hwnd, window
'    ClipCursor window
'    Tell the system a screen saver is running.
    SystemParametersInfo SPI_SCREENSAVERRUNNING, True, 0, 0
    AlwaysOnTop Me
'    ShowCursor False
End Sub

Public Sub Lock_Inputs()

    Text1.Enabled = False
    Text2.Enabled = False
    Login.Enabled = False
    Reset.Enabled = False
    Guest_Member.Enabled = False
    Check1.Enabled = False
    mTime.Enabled = False
    
    fNameText.Enabled = False
    lNameText.Enabled = False
    ageText.Enabled = False
    telText.Enabled = False
    Option1.Enabled = False
    Option2.Enabled = False
    Check2.Enabled = False
    gTime.Enabled = False

End Sub

Public Sub Unlock_Inputs()

    Text1.Enabled = True
    Text2.Enabled = True
    Login.Enabled = True
    Reset.Enabled = True
    Guest_Member.Enabled = True
    Check1.Enabled = True
    mTime.Enabled = True
    
    fNameText.Enabled = True
    lNameText.Enabled = True
    ageText.Enabled = True
    Option1.Enabled = True
    Option2.Enabled = True
    telText.Enabled = True
    login1.Enabled = True
    reset1.Enabled = True
    Check2.Enabled = True
    gTime.Enabled = True

End Sub



PLEASE HELP!        


also sending an attachment of CAFE CLIENT which has all the mentioned modules

____________________________
live life kingsize!

24-02-2006 at 06:01 AM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: please tell me why my customer form gets hung up

Hello: Your question is not clear, and I suggest you next time to spend a little more seconds to type some more info. It'd be largely more useful than posting the whole code module. (...did you notice how many times I said the word "more"?...   )

I assume you meant your form doesn't disappear when closing it. You don't say how you close the form, and I found no Unload Me instruction into the code you posted. Instead, you call some hook functions which are not in your code module: where are they? Post their code, as you call one of them functions in Form_Unload event, and it'd be useful to know what it does and how.

Plain talking, help us to help you.

____________________________
Real Programmer can count up to 1024 on his fingers

24-02-2006 at 08:23 AM
View Profile Send Email to User Show All Posts | Quote Reply
kabba
Level: Trainee

Registered: 24-02-2006
Posts: 2
icon Re: please tell me why my customer form gets hung up

Thanks Yronium, for yer reply... sorry for not being clear or to the point with my post...

the problem that im having is that......the splash form after loading gets hung up....
notice that my splash form is the same member login form...that loads on during runtime....

the modules that i have used in my project are

1)modDisableLowLevelKeys

Option Explicit

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B

Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20

Public Type KBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    time As Long
    dwExtraInfo As Long
End Type

Dim p As KBDLLHOOKSTRUCT

Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Dim fEatKeystroke As Boolean
   If (nCode = HC_ACTION) Then
      If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
         CopyMemory p, ByVal lParam, Len(p)
         fEatKeystroke = _
            ((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
            ((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
            ((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0))
        End If
    End If
    If fEatKeystroke Then
        LowLevelKeyboardProc = -1
    Else
        LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
    End If
End Function
--------------------------------------------------------------------------

2)modGetHostNetworkInfo

Option Explicit

Public Const MAX_WSADescription As Long = 256
Public Const MAX_WSASYSStatus As Long = 128
Public Const ERROR_SUCCESS       As Long = 0
Public Const WS_VERSION_REQD     As Long = &H101
Public Const WS_VERSION_MAJOR    As Long = WS_VERSION_REQD \ &H100 And &HFF&
Public Const WS_VERSION_MINOR    As Long = WS_VERSION_REQD And &HFF&
Public Const MIN_SOCKETS_REQD    As Long = 1
Public Const SOCKET_ERROR        As Long = -1

Public Type HOSTENT
   hName      As Long
   hAliases   As Long
   hAddrType  As Integer
   hLen       As Integer
   hAddrList  As Long
End Type

Public Type WSADATA
   wVersion      As Integer
   wHighVersion  As Integer
   szDescription(0 To MAX_WSADescription)   As Byte
   szSystemStatus(0 To MAX_WSASYSStatus)    As Byte
   wMaxSockets   As Integer
   wMaxUDPDG     As Integer
   dwVendorInfo  As Long
End Type

Public Declare Function WSAGetLastError Lib "wsock32" () As Long

Public Declare Function WSAStartup Lib "wsock32" _
  (ByVal wVersionRequired As Long, _
   lpWSADATA As WSADATA) As Long
  
Public Declare Function WSACleanup Lib "wsock32" () As Long

Public Declare Function gethostname Lib "wsock32" _
  (ByVal szHost As String, _
   ByVal dwHostLen As Long) As Long
  
Public Declare Function gethostbyname Lib "wsock32" _
  (ByVal szHost As String) As Long
  
Public Declare Sub CopyMemory Lib "kernel32" _
   Alias "RtlMoveMemory" _
  (hpvDest As Any, _
   ByVal hpvSource As Long, _
   ByVal cbCopy As Long)


Public Function GetIPAddress() As String

   Dim sHostName    As String * 256
   Dim lpHost    As Long
   Dim HOST      As HOSTENT
   Dim dwIPAddr  As Long
   Dim tmpIPAddr() As Byte
   Dim i         As Integer
   Dim sIPAddr  As String
  
   If Not SocketsInitialize() Then
      GetIPAddress = ""
      Exit Function
   End If
    
  'gethostname returns the name of the local host into
  'the buffer specified by the name parameter. The host
  'name is returned as a null-terminated string. The
  'form of the host name is dependent on the Windows
  'Sockets provider - it can be a simple host name, or
  'it can be a fully qualified domain name. However, it
  'is guaranteed that the name returned will be successfully
  'parsed by gethostbyname and WSAAsyncGetHostByName.

  'In actual application, if no local host name has been
  'configured, gethostname must succeed and return a token
  'host name that gethostbyname or WSAAsyncGetHostByName
  'can resolve.
   If gethostname(sHostName, 256) = SOCKET_ERROR Then
      GetIPAddress = ""
      MsgBox "Windows Sockets error " & str$(WSAGetLastError()) & _
              " has occurred. Unable to successfully get Host Name."
      SocketsCleanup
      Exit Function
   End If
  
  'gethostbyname returns a pointer to a HOSTENT structure
  '- a structure allocated by Windows Sockets. The HOSTENT
  'structure contains the results of a successful search
  'for the host specified in the name parameter.

  'The application must never attempt to modify this
  'structure or to free any of its components. Furthermore,
  'only one copy of this structure is allocated per thread,
  'so the application should copy any information it needs
  'before issuing any other Windows Sockets function calls.

  'gethostbyname function cannot resolve IP address strings
  'passed to it. Such a request is treated exactly as if an
  'unknown host name were passed. Use inet_addr to convert
  'an IP address string the string to an actual IP address,
  'then use another function, gethostbyaddr, to obtain the
  'contents of the HOSTENT structure.
   sHostName = Trim$(sHostName)
   lpHost = gethostbyname(sHostName)
    
   If lpHost = 0 Then
      GetIPAddress = ""
      MsgBox "Windows Sockets are not responding. " & _
              "Unable to successfully get Host Name."
      SocketsCleanup
      Exit Function
   End If
    
  'to extract the returned IP address, we have to copy
  'the HOST structure and its members
   CopyMemory HOST, lpHost, Len(HOST)
   CopyMemory dwIPAddr, HOST.hAddrList, 4
  
  'create an array to hold the result
   ReDim tmpIPAddr(1 To HOST.hLen)
   CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen
  
  'and with the array, build the actual address,
  'appending a period between members
   For i = 1 To HOST.hLen
      sIPAddr = sIPAddr & tmpIPAddr(i) & "."
   Next
  
  'the routine adds a period to the end of the
  'string, so remove it here
   GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
  
   SocketsCleanup
    
End Function


Public Function GetIPHostName() As String

    Dim sHostName As String * 256
    
    If Not SocketsInitialize() Then
        GetIPHostName = ""
        Exit Function
    End If
    
    If gethostname(sHostName, 256) = SOCKET_ERROR Then
        GetIPHostName = ""
        MsgBox "Windows Sockets error " & str$(WSAGetLastError()) & _
                " has occurred.  Unable to successfully get Host Name."
        SocketsCleanup
        Exit Function
    End If
    
    GetIPHostName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
    SocketsCleanup

End Function


Public Function HiByte(ByVal wParam As Integer) As Byte
  
  'note: VB4-32 users should declare this function As Integer
   HiByte = (wParam And &HFF00&) \ (&H100)

End Function


Public Function LoByte(ByVal wParam As Integer) As Byte

  'note: VB4-32 users should declare this function As Integer
   LoByte = wParam And &HFF&

End Function


Public Sub SocketsCleanup()

    If WSACleanup() <> ERROR_SUCCESS Then
        MsgBox "Socket error occurred in Cleanup."
    End If
    
End Sub

Public Function SocketsInitialize() As Boolean

   Dim WSAD As WSADATA
   Dim sLoByte As String
   Dim sHiByte As String
  
   If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
      MsgBox "The 32-bit Windows Socket is not responding."
      SocketsInitialize = False
      Exit Function
   End If
  
  
   If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
        MsgBox "This application requires a minimum of " & _
                CStr(MIN_SOCKETS_REQD) & " supported sockets."
        
        SocketsInitialize = False
        Exit Function
    End If
  
  
   If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or _
     (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And _
      HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
      
      sHiByte = CStr(HiByte(WSAD.wVersion))
      sLoByte = CStr(LoByte(WSAD.wVersion))
      
      MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
             " is not supported by 32-bit Windows Sockets."
      
      SocketsInitialize = False
      Exit Function
      
   End If
    
    
  'must be OK, so lets do it
   SocketsInitialize = True
        
End Function
'--end block--'

-------------------------------------------------------------------------

3)modMain

Type Client

    socket As Integer
    machineID As String
    memberID As String
    service As String
    startTimeServer As Date
    startTime As Date
    timeUsed As Long
    Logout As Boolean

End Type

Public clientInfo As Client
Public grafixCard As Boolean

Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const flags = SWP_NOMOVE Or SWP_NOSIZE
Public RemoteHostName As String

'0 = Not Connected   1 = Connected
Public connectionStatus As Boolean

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
                                                   ByVal hWndInsertAfter As Long, _
                                                   ByVal X As Long, ByVal Y As Long, _
                                                   ByVal cx As Long, ByVal cy As Long, _
                                                   ByVal wFlags As Long) As Long

Public Sub AlwaysOnTop(FormName As Form)
    Call SetWindowPos(FormName.hwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, flags)
End Sub

Public Sub NotOnTop(FormName As Form)
    Call SetWindowPos(FormName.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, flags)
End Sub

Public Function Connect_to_Server()
    
'main.Show

    memberLogin.HostName.Caption = "Hostname = " & main.clientSocket.LocalHostName
    clientInfo.machineID = ""
    
    readRemoteHost
    
    If main.clientSocket.State = sckConnected Then
        MsgBox "Client already connected to Server", vbOKOnly
    Else
        If main.clientSocket.State <> sckClosed Then
            main.clientSocket.Close
        End If
        main.clientSocket.RemoteHost = RemoteHostName
        main.clientSocket.RemotePort = 8000
        main.clientSocket.Connect
    End If
    SendClientInfo
    
End Function

Public Function StatusUpdate()
    
    main.Text1.Text = "Socket State = " & main.clientSocket.State
    
End Function

Public Function SendClientInfo()

    If (main.clientSocket.State = sckConnected) Then
        sentData = "ClientName;" & main.clientSocket.LocalHostName & "."
        main.Text2.Text = sentData & vbCrLf
        main.clientSocket.SendData sentData
        addLog "Send Client Info"
    End If

End Function

Public Sub readRemoteHost()
    
    Dim sFileName, sLine As String
    sFileName = App.Path
    If Right$(sFileName, 1) <> "\" Then sFileName = sFileName & "\"
    sFileName = sFileName & "client.ini"
    Open sFileName For Input As #1
    Do While Not EOF(1)
        Line Input #1, sLine
    Loop
    Close #1
    RemoteHostName = sLine

End Sub

Public Sub addLog(str As String)
    Dim sFileName
    sFileName = App.Path
    If Right$(sFileName, 1) <> "\" Then sFileName = sFileName & "\"
    sFileName = sFileName & "client.log"
    Open sFileName For Append As #1
    Print #1, str
    Close #1
End Sub








____________________________
live life kingsize!

25-02-2006 at 02:44 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : please tell me why my customer form gets hung up
Previous Topic (banner)Next Topic (Error Trapping for NETWORK Printer!) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder