Minggu, 29 Januari 2012

jawaban kuis no 3

kasus
server

      listing program
Dim ClientIndex As Byte
Dim cRequest As Integer
Dim cData As String
Dim i As Integer
Dim iGD As Integer

Sub MulaiServer()
        WS(0).LocalPort = 3000
        WS(0).Listen
        cRequest = 1
        ClientIndex = 1
End Sub

Private Sub Form_Load()
        MulaiServer
        GD.Rows = 41
        For i = 1 To 40
            GD.Col = 0
            GD.Row = i
            GD.Text = i
        Next i
        iGD = 1
End Sub


Private Sub Timer1_Timer()
    For i = 1 To GD.Rows - 1
        GD.Row = i
        GD.Col = 4
        If GD.Text = "START" Then
            GD.Col = 3
            GD.Text = Time
        End If
    Next i
End Sub

Private Sub WS_ConnectionRequest(index As Integer, ByVal requestID As Long)
        Load WS(cRequest)
        WS(cRequest).Close
        WS(cRequest).Accept requestID
        cRequest = cRequest + 1 '
End Sub

Private Sub WS_DataArrival(index As Integer, ByVal bytesTotal As Long)
        WS(index).GetData cData, vbString, bytesTotal
        Call CekData(index)
       
End Sub

Sub CekData(index)
    On Error Resume Next
        Dim kata() As String
        kata = Split(cData, "-")
        Select Case kata(0)
        Case "START"
                        GD.Row = iGD
                        GD.Col = 1
                        GD.Text = kata(1) 'WS(index).RemoteHostIP
                        GD.Col = 2
                        GD.Text = Time
                        GD.Col = 4
                        GD.Text = "START"
                        GD.Col = 5
                        GD.Text = kata(2)
                        iGD = iGD + 1
        Case "STOP"
            For i = 1 To GD.Rows - 1
                GD.Row = i
                GD.Col = 1
                If GD.Text = kata(1) Then
                    GD.Col = 4
                    GD.Text = "STOP"
                End If
            Next i
        End Select
End Sub
       
Private Sub WS_Error(index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
        WS(index).Close
End Sub

client

listing program
Dim IPServer As String
Dim xKirim As String
Dim xData1() As String
Dim xData2() As String
Dim IPS As String
Dim USER As String
Dim cRequest As Integer
Public jam As Currency



Private Sub biaya_Change()

End Sub



Private Sub start_Click()
    ws(index).SendData "START-" & USER & "-EFRIAWAN"
    Timer1.Enabled = False
End Sub

Private Sub stop_click()
    ws(index).SendData "STOP-" & USER
    pakai.Value = selesai.Value - mulai.Value
    Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer()
    mulai.Value = Format(Now, "HH:MM:SS")
   

End Sub

Private Sub Timer2_Timer()
    ws(index).SendData "PAKAI-" & pakai.Value & "/" & 3000
    selesai.Value = Format(Now, "HH:MM:SS")
   
   
End Sub








Private Sub Form_Load()
    Me.Caption = "CLIENT IP :" & ws(index).LocalIP
    biaya = ""
    Pemakaian = ""
    IPS = "127.0.0.1"
    USER = ws(index).LocalIP
    ws(index).Connect IPS, 3000
End Sub



Private Sub WS_DataArrival(index As Integer, ByVal bytesTotal As Long)
    ws(index).GetData xKirim, vbString, bytesTotal
    Call CheckData
End Sub
Sub CheckData()
    xData1 = Split(xKirim, "-")
    xData2 = Split(xData1(1), "/")
   
    Select Case xData1(0)
        Case "PAKAI"
            pakai.Value = xData2(0)
            biaya.Text = xData2(1)
            Pemakaian.Text = xData2(1) / 60
           
        End Select
End Sub