It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

IMPT Project NEED help!!!urgent!!

Moderator: dafunkymunky

IMPT Project NEED help!!!urgent!!

Postby wen88 on Wed Mar 05, 2008 3:42 am

Hey guys!!i need help in my project.....

My teacher ask me to create a program to interact between the client and the quiz-master, using VB .NET and also SQL. I dont know a damn thing about it.....and he said after creating the program....a Micro.P board need to be connected to the computer.

He said....its about a quiz game....wants us to create a quiz and the winner with the quickest person answering the question within a time limit.

so Guys can help me with the this...coz...i really don't know where to start frm....

thanks!!!
wen88
 
Posts: 3
Joined: Wed Mar 05, 2008 3:23 am

Postby wen88 on Tue Mar 11, 2008 7:40 am

Code: Select all
Imports System.Net.Sockets

Public Class Form1
    Const portNo As Integer = 5000
    Dim client As TcpClient
    Dim data() As Byte

    Private Sub btnSend_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnSend.Click
        Dim ans As String = ""
        Dim message As String = ""
        If (c1.Checked = False And c2.Checked = False And C3.Checked = False) Then
            MsgBox("Please input answer")
        Else
            If c1.Checked Then
                ans = 1
            ElseIf c2.Checked Then
                ans = 2
            ElseIf C3.Checked Then
                ans = 3
            End If
            message = ans
            SendMessage(message)
            c1.Checked = False
            c2.Checked = False
            C3.Checked = False
            ans = ""
        End If
    End Sub

    Public Sub SendMessage(ByVal message As String)
        Try
            Dim ns As NetworkStream = client.GetStream
            Dim data As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(message)
            'send the text
            ns.Write(data, 0, data.Length)
            ns.Flush()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
        Try
            Dim bytesRead As Integer
            bytesRead = client.GetStream.EndRead(ar)
            If bytesRead < 1 Then
                Exit Sub
            Else
                Dim para() As Object = _
                   {System.Text.Encoding.ASCII.GetString( _
                   data, 0, bytesRead)}
                Me.Invoke(New delUpdateHistory( _
                   AddressOf Me.UpdateHistory), para)
            End If
            client.GetStream.BeginRead( _
               data, 0, CInt(client.ReceiveBufferSize), _
               AddressOf ReceiveMessage, Nothing)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub btnSignIn_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnSignIn.Click
        Dim txt As String
        If IDtxt.Text = "" Then
            MsgBox("Please input ID")
        Else
            If btnSignIn.Text = "Sign In" Then
                Try
                    'connect to server
                    client = New TcpClient
                    client.Connect("172.16.202.51", portNo)
                    'client.Connect("127.0.0.1", portNo)
                    ReDim data(client.ReceiveBufferSize)
                    txt = IDtxt.Text
                    SendMessage(txt)
                    'read from server
                    client.GetStream.BeginRead( _
                       data, 0, CInt(client.ReceiveBufferSize), _
                       AddressOf ReceiveMessage, Nothing)
                    btnSignIn.Text = "Sign Out"
                    btnSend.Enabled = True
                    IDtxt.Enabled = False
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try
            Else
                'disconnect from server
                Disconnect()
                btnSignIn.Text = "Sign In"
                btnSend.Enabled = False
                IDtxt.Enabled = True
            End If
        End If
    End Sub

    Public Sub Disconnect()
        'Disconnect from server
        If btnSignIn.Text = "Sign In" Then

        Else
            Try
                client.GetStream.Close()
                client.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub

    'delegate and subroutine to update the TextBox control
    Public Delegate Sub delUpdateHistory(ByVal str As String)
    Public Sub UpdateHistory(ByVal str As String)
        QuestBx.AppendText(str)
    End Sub

    Private Sub Form1_FormClosing( _
       ByVal sender As Object, _
       ByVal e As System.Windows.Forms.FormClosingEventArgs) _
       Handles Me.FormClosing
        Disconnect()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class



how to make it better??
as in make it with image or modify it.....
wen88
 
Posts: 3
Joined: Wed Mar 05, 2008 3:23 am


Who is online

Users browsing this forum: No registered users and 4 guests