locked
Appendtext not working RRS feed

  • Question

  • Private Sub startHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startHO.Click
            Me.MS.Location = New Point(msLocX, msLocY)
            Me.isPause = False
            progressBarHO.Increment(progressBarHO.Step + 3)
    
            While MS.Location.X < (cPoint.Location.X - MS.Width)
                Me.MS.Location = New Point(MS.Location.X + 2, MS.Location.Y)
    
                My.Application.DoEvents()
                System.Threading.Thread.Sleep(100)
    
            End While
    
            Me.statusHO.AppendText("MS is at Cross Over Point " & vbCr & vbLf & vbCr & vbLf)
            progressBarHO.Increment(progressBarHO.Step + 3)
    
            While MS.Location.X < (thresHold.Location.X - MS.Width)
                MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1)
    
                Application.DoEvents()
                System.Threading.Thread.Sleep(100)
            End While
    
            Me.statusHO.AppendText("MS just reached Threshold Point " & vbCr & vbLf & vbCr & vbLf)
            progressBarHO.Increment(progressBarHO.Step + 3)
    
            Dim isStarted As Boolean = False
    
            While MS.Location.X < Hys.Location.X - MS.Width
                MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1)
                If Not isStarted Then
    '''Here i got some logical error i think so
           New Start = New Thread(New ThreadStart(AddressOf StartHandovering)) ' If i use this statment it says on New syntax error
    
    New Thread(New ThreadStart(StartHandovering)).Start() 'it also undlines new and says on New syntax error
    
         Dim ThreadStart As New Threading.Thread(AddressOf StartHandovering.start) ' If i use this code it undelines StartHandoverind and says expression does not produce a value
    
    
                    isStarted = True
                End If
                Application.DoEvents()
                System.Threading.Thread.Sleep(100)
            End While
    
            Me.statusHO.AppendText("MS just reached Hysteris Point" & vbCr & vbLf & vbCr & vbLf)
            progressBarHO.Increment(progressBarHO.Step + 6)
            While MS.Location.X < (Hys.Location.X + Hys.Location.X / 10)
                MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1)
                Application.DoEvents()
    
                System.Threading.Thread.Sleep(100)
    
                progressBarHO.Increment(progressBarHO.Step)
    
            End While
            If Me.progressBarHO.Value = progressBarHO.Maximum Then
                HOProgress.Text = "Handover Sucessfully Completed"
            Else
                progressBarHO.Increment(progressBarHO.Maximum)
                HOProgress.Text = "Handover Sucessfully Completed"
            End If
    
        End Sub
    
    Public Sub StartHandovering()
    
            Dim sw As New Stopwatch()
    
            sw.Reset() 'Stops time interval measurement and resets the elapsed time to zero.
            sw.Start() 'Starts, or resumes, measuring elapsed time for an interval.
            BS.ProcessRequest(Request.MOB_SCN_REQ, bsType.Serving)
            sw.[Stop]() 'Stops measuring elapsed time for an interval.
    
            AddStatus("T1 - " & Request.MOB_SCN_REQ.ToString(), sw.Elapsed.TotalMilliseconds)
            System.Threading.Thread.Sleep(50)
    
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.SYNC, bsType.Neigboring)
            sw.[Stop]()
            Me.AddStatus("T2 - " & Request.SYNC.ToString(), sw.Elapsed.TotalMilliseconds)
            System.Threading.Thread.Sleep(50)
    
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.MOB_MSHO_REQ, bsType.Serving)
            sw.[Stop]()
            'AddStatus(Request.MOB_MSHO_REQ.ToString(), sw.ElapsedTicks);
    
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.RNG_REQ_CB, bsType.Target)
            sw.[Stop]()
            Me.AddStatus("T3 - " & Request.RNG_REQ_CB.ToString(), sw.Elapsed.TotalMilliseconds)
            System.Threading.Thread.Sleep(50)
    
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.RNG_REQ_CF, bsType.Target)
            sw.[Stop]()
            Me.AddStatus("T4 - " & Request.RNG_REQ_CF.ToString(), sw.Elapsed.TotalMilliseconds)
            System.Threading.Thread.Sleep(50)
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.CAP_NEGO, bsType.Serving)
            sw.[Stop]()
            Me.AddStatus("T5 - " & Request.CAP_NEGO.ToString(), sw.Elapsed.TotalMilliseconds)
            System.Threading.Thread.Sleep(50)
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.AUTH_KEY_EXG, bsType.Serving)
            sw.[Stop]()
            Me.AddStatus("T6 - " & Request.AUTH_KEY_EXG.ToString(), sw.Elapsed.TotalMilliseconds)
            System.Threading.Thread.Sleep(50)
    
            sw.Reset()
            sw.Start()
            BS.ProcessRequest(Request.REG_REQ, bsType.Target)
            sw.[Stop]()
            Me.AddStatus("T7 - " & Request.REG_REQ.ToString(), sw.Elapsed.TotalMilliseconds)
            'manResEvent[0].Set();
            System.Threading.Thread.Sleep(50)
        End Sub
    This code works fine in showing cross over point reached and other points.But i dont know what error in code i am doing at the point i put comment.as its not showing T1 up to t7.not showing delay. Public Sub StartHandovering() on wards its not working i think.i put breakpoint in it.But nothing happens.
    Please guide me in this single line of code which i am doing wrong logically. IF NOT isStarted THEN.....?its not working.
    Hope anyone can help me
    Thanks
    Naina Ronak
    Tuesday, June 2, 2009 1:30 PM

Answers

  • Thanks for your kind reply, I was able to solve the above problem
    the code is supposed to be like this

     

    If Not isStarted Then
    
    Dim newThread As New Thread(AddressOf StartHandovering)
    
    newThread.Start()
    
    isStarted = True
    
    End If

    Now my problem is another error after i fix above error, when option strict is on error is :-

    " Option Strict On disallows implicit conversions from 'String' to 'Double'.

    If i put option strict off then i get this error:-

    System.InvalidCastException was unhandled
      Message="Conversion from string "MOB_NBR_ADV ----- Delay: " to type 'Double' is not valid."
      Source="Microsoft.VisualBasic"....

    'here is the code of handover.vb 

    Option Explicit On ' Force explicit variable declaration. Option Strict On Imports System Imports System.Text Imports System.Data Imports System.Drawing Imports System.Threading Imports System.Environment Imports System.Diagnostics Imports System.Windows.Forms Imports System.ComponentModel Imports System.Windows.Forms.Timer Imports System.Collections.Generic Imports Handover.HO Public Class Handover Dim manResEvent As Object Dim isPause As Boolean = False Dim swTimer As New Stopwatch() Dim msLocX As Integer = 486 Dim msLocY As Integer = 327 Dim program As Object Private Sub Handover_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WindowState = FormWindowState.Maximized Me.MS.Location = New Point(msLocX, msLocY) End Sub Private Sub cellTopology_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cellTopology.Click End Sub Private Sub sBS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sBS.Click End Sub Private Sub tBS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tBS.Click End Sub Private Sub MS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MS.Click End Sub Private Sub cPoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cPoint.Click End Sub Private Sub startHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startHO.Click Me.MS.Location = New Point(msLocX, msLocY)'MS is an image type moblie station which i want to move from one cell to other Me.isPause = False progressBarHO.Increment(progressBarHO.Step + 3) While MS.Location.X < (cPoint.Location.X - MS.Width) Me.MS.Location = New Point(MS.Location.X + 2, MS.Location.Y) My.Application.DoEvents() System.Threading.Thread.Sleep(100) End While Me.statusHO.AppendText("MS is at Cross Over Point " & vbCr & vbLf & vbCr & vbLf) progressBarHO.Increment(progressBarHO.Step + 3) While MS.Location.X < (thresHold.Location.X - MS.Width) MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1) Application.DoEvents() System.Threading.Thread.Sleep(100) End While Me.statusHO.AppendText("MS just reached Threshold Point " & vbCr & vbLf & vbCr & vbLf) progressBarHO.Increment(progressBarHO.Step + 3) Dim isStarted As Boolean = False While MS.Location.X < Hys.Location.X - MS.Width MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1) If Not isStarted Then Dim newThread As New Thread(AddressOf StartHandovering) newThread.Start() isStarted = True End If Application.DoEvents() System.Threading.Thread.Sleep(100) End While Me.statusHO.AppendText("MS just reached Hysteris Point" & vbCr & vbLf & vbCr & vbLf) progressBarHO.Increment(progressBarHO.Step + 6) While MS.Location.X < (Hys.Location.X + Hys.Location.X / 10) MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1) Application.DoEvents() System.Threading.Thread.Sleep(100) progressBarHO.Increment(progressBarHO.Step) End While If Me.progressBarHO.Value = progressBarHO.Maximum Then HOProgress.Text = "Handover Sucessfully Completed" Else progressBarHO.Increment(progressBarHO.Maximum) HOProgress.Text = "Handover Sucessfully Completed" End If End Sub Private Sub pauseHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pauseHO.Click If isPause Then isPause = False Me.pauseHO.Text = "Pause" timerBS.Enabled = True Else Me.pauseHO.Text = "Continue" isPause = True timerBS.Enabled = False End If While isPause System.Threading.Thread.Sleep(100) Application.DoEvents() End While End Sub Public Sub StartHandovering() Dim sw As New Stopwatch() sw.Reset() 'Stops time interval measurement and resets the elapsed time to zero. sw.Start() 'Starts, or resumes, measuring elapsed time for an interval. BS.ProcessRequest(Request.MOB_SCN_REQ, bsType.Serving) sw.[Stop]() 'Stops measuring elapsed time for an interval. AddStatus("T1 - " & Request.MOB_SCN_REQ.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.SYNC, bsType.Neigboring) sw.[Stop]() Me.AddStatus("T2- " & Request.SYNC.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.MOB_MSHO_REQ, bsType.Serving) sw.[Stop]() 'AddStatus(Request.MOB_MSHO_REQ.ToString(), sw.ElapsedTicks); sw.Reset() sw.Start() BS.ProcessRequest(Request.RNG_REQ_CB, bsType.Target) sw.[Stop]() Me.AddStatus("T3 - " & Request.RNG_REQ_CB.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.RNG_REQ_CF, bsType.Target) sw.[Stop]() Me.AddStatus("T4 - " & Request.RNG_REQ_CF.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.CAP_NEGO, bsType.Serving) sw.[Stop]() Me.AddStatus("T5 - " & Request.CAP_NEGO.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.AUTH_KEY_EXG, bsType.Serving) sw.[Stop]() Me.AddStatus("T5 - " & Request.AUTH_KEY_EXG.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.REG_REQ, bsType.Target) sw.[Stop]() Me.AddStatus("T7 - " & Request.REG_REQ.ToString(), sw.Elapsed.TotalMilliseconds) 'manResEvent[0].Set(); System.Threading.Thread.Sleep(50) End Sub Private Sub timerBS_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerBS.Tick swTimer.Reset() 'Reset timer on form shown swTimer.Start() 'Start timer on form shown BS.ProcessRequest(Request.MOB_NBR_ADV, bsType.Serving) swTimer.Stop() Me.AddStatus(Request.MOB_NBR_ADV.ToString(), swTimer.Elapsed.TotalMilliseconds) End Sub Private Sub AddStatus(ByVal message As String, ByVal delay As Double) statusHO.AppendText((message & " ----- Delay: ") + Math.Round(delay, 4) * 10000 & " ms " & vbCr & vbLf & vbCr & vbLf)'Here i get this error End Sub Private Sub statusHO_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles statusHO.TextChanged End Sub Private Sub resetStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetStatus.Click Me.statusHO.Text = "" HOProgress.Text = "Handover Progress" Me.progressBarHO.Value = progressBarHO.Minimum End Sub Private Sub stopHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopHO.Click If Me.stopHO.Text = "Stop." Then Me.timerBS.Enabled = False Me.stopHO.Text = "Click to start again" Else Me.timerBS.Enabled = True Me.stopHO.Text = "Stop" End If End Sub Private Sub closeWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeWindow.Click Me.Close() End Sub Private Sub progressBarHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles progressBarHO.Click End Sub Private Sub HOProgress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HOProgress.Click End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub End Class

    I also tried all conversions and parse iformat . but then i get error while option strict is on "Input strin not in correct format"
    I want the results somehow in this way in the text box "statusHO":

    MOB_NBR_ADV    -----   Delay: 31174 ms

    MS just reached Threshold Point
    MS is at Cross Over Point

    T1 - MOB_SCN_REQ    -----   Delay: 2857 ms

    T2 - SYNC    -----   Delay: 3103 ms

    T3 - RNG_REQ_CB    -----   Delay: 234602 ms

    MS just reached crossover point

    T4 - RNG_REQ_CF    -----   Delay: 284 ms

    T5 - CAP_NEGO    -----   Delay: 3011 ms

    T6 - AUTH_KEY_EXG    -----   Delay: 7875 ms

    T7 - REG_REQ    -----   Delay: 3084 ms

    MOB_NBR_ADV    -----   Delay: 83 ms

    MOB_NBR_ADV    -----   Delay: 120 ms

    Below is the code of another " constants.vb"

    'Here is the code of constants.vb
    Imports System Imports System.Collections.Generic Imports System.Text Namespace HO Class Constants Public Const SCANNING_TIMEOUT As Integer = 20 Public Const AUTHENTICATION_TIMEOUT As Integer = 10 'Public Const MOB_SCN_REQ_TIMEOUT As Integer = 3 'Public Const SYNC_TIMEOUT As Integer = 2 'Public Const RNG_REQ_CB_TIMEOUT As Integer = 10 'Public Const RNG_REQ_CF_TIMEOUT As Integer = 4 'Public Const CAP_NEGO_TIMEOUT As Integer = 4 'Public Const AUTH_KEY_EXG_TIMEOUT As Integer = 6 'Public Const REG_REQ_TIMEOUT As Integer = 5 'public const int Public Const MOB_SCN_REQ_TIMEOUT As Integer = 0 Public Const SYNC_TIMEOUT As Integer = 0 Public Const RNG_REQ_CB_TIMEOUT As Integer = 0 Public Const RNG_REQ_CF_TIMEOUT As Integer = 0 Public Const CAP_NEGO_TIMEOUT As Integer = 0 Public Const AUTH_KEY_EXG_TIMEOUT As Integer = 0 Public Const REG_REQ_TIMEOUT As Integer = 0 Public Const program As Integer = 0 End Class Public Enum Request MOB_NBR_ADV MOB_SCN_REQ HO_Indication RNG_REQ RNG_REQ_CF RNG_REQ_CB MOB_MSHO_REQ HO_Notification MOB_HO_IND CAP_NEGO SBC_REQ REG_REQ SYNC AUTH_KEY_EXG End Enum Public Enum Response Processed UnProcessed HO_Response RNG_RSP RNG_RSP_CF RNG_RSP_CB HO_Notification_RSP MS_INFO_RSP SBC_RSP MOB_HO_RSP MOB_SCN_RSP REG_RSP End Enum Public Enum bsType Serving Target Neigboring End Enum Public Structure BaseStation Public Stations As BSInfo() Public Sub New(ByVal stations__1 As Integer) Dim BaseStations As New List(Of BSInfo)() Dim s As Integer = 1 If s < stations__1 Then s = stations__1 End If For i As Integer = 1 To s Dim bInfo As New BSInfo() bInfo.ID = i BaseStations.Add(bInfo) Next Stations = BaseStations.ToArray() End Sub End Structure Public Structure MobileStation Public ID As Integer Public bsServing As BSInfo Public NeighborBS As BSInfo() Public TargetBS As BSInfo() Public Sub New(ByVal msID As Integer, ByVal sBS As BSInfo) ID = msID bsServing = sBS NeighborBS = Nothing TargetBS = Nothing End Sub End Structure Public Structure BSInfo Public ID As Integer End Structure End Namespace

    Another page BS.vb

    'Code of BS.vb
    Option Explicit On
    Option Strict On
    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Threading
    Namespace HO
        Class BS
            Public Shared Function ProcessRequest(ByVal req As Request, ByVal BS As bsType) As Object
                If BS = bsType.Serving Then
                    If req = Request.MOB_NBR_ADV Then
                        Return NeighborAdvertisement()
                    ElseIf req = Request.MOB_SCN_REQ Then
                        Return HOIndication()
                    ElseIf req = Request.MOB_MSHO_REQ Then
                        Return HONotification()
                    ElseIf req = Request.MOB_HO_IND Then
                        Return RangingRequest(3, 6, req)
                    ElseIf req = Request.CAP_NEGO Then
                        Return CapabilityNegotiation()
                    ElseIf req = Request.AUTH_KEY_EXG Then
                        Authenticate()
                        Subscribe()
                        KeyExchange()
                        Authorize()
    
                        Return True
                    End If
                ElseIf BS = bsType.Neigboring Then
                    If req = Request.RNG_REQ Then
                        Return RangingRequest(3, 6, req)
                    ElseIf req = Request.SYNC Then
                        Return Synchronize()
                    End If
                ElseIf BS = bsType.Target Then
                    If req = Request.REG_REQ Then
                        Return Register()
                    ElseIf req = Request.RNG_REQ_CB Then
                        Return RangingRequest(1000, 1200, req)
                    ElseIf req = Request.RNG_REQ_CF Then
                        Return RangingRequest(1, 1, req)
                    End If
                End If
    
                Return Response.UnProcessed
            End Function
    
            Private Shared Function NeighborAdvertisement() As Boolean
                Dim bss As New List(Of BSInfo)()
                For Each bs As BSInfo In Program.baseStation.Stations
                    If Program.mobileStation.bsServing.ID <> bs.ID Then
                        bss.Add(bs)
                    End If
                Next
    
                Program.mobileStation.NeighborBS = bss.ToArray()
                Program.mobileStation.TargetBS = bss.ToArray()
    
                Return True
            End Function
    
            Private Shared Function Synchronize() As Boolean
                System.Threading.Thread.Sleep(Constants.SYNC_TIMEOUT)
                Return True
            End Function
    
            Private Shared Function HOIndication() As Single
                System.Threading.Thread.Sleep(Constants.MOB_SCN_REQ_TIMEOUT)
                Return Constants.SCANNING_TIMEOUT
            End Function
    
            Private Shared Function CapabilityNegotiation() As Boolean
                System.Threading.Thread.Sleep(Constants.CAP_NEGO_TIMEOUT)
                Return True
            End Function
    
            Private Shared Function RangingRequest(ByVal minValue As Integer, ByVal maxValue As Integer, ByVal req As Request) As Boolean
                Dim n As Integer = New Random().[Next](minValue, maxValue)
    
                For i As Integer = 0 To n - 1
                    Continue For
                Next
    
                If req = Request.RNG_REQ_CB Then
                    System.Threading.Thread.Sleep(Constants.RNG_REQ_CB_TIMEOUT)
                ElseIf req = Request.RNG_REQ_CF Then
                    System.Threading.Thread.Sleep(Constants.RNG_REQ_CF_TIMEOUT)
                End If
    
                Return True
            End Function
    
            Private Shared Function HONotification() As Boolean
                Return True
            End Function
    
            Private Shared Function Authenticate() As Boolean
                Return True
            End Function
    
            Private Shared Function Subscribe() As Boolean
                Return True
            End Function
    
            Private Shared Function KeyExchange() As Boolean
                Return True
            End Function
    
            Private Shared Function Authorize() As Boolean
                System.Threading.Thread.Sleep(Constants.AUTH_KEY_EXG_TIMEOUT)
                Return True
            End Function
    
            Private Shared Function Register() As Boolean
                System.Threading.Thread.Sleep(Constants.REG_REQ_TIMEOUT)
                Return True
            End Function
        End Class
    End Namespace
    

    Another Page Program.vb

    'Code of Program.vb
    Imports System
    Imports System.Collections.Generic
    Imports System.Windows.Forms
    Namespace HO
        Module Program
            Sub New()
            End Sub
    
            Public baseStation As New BaseStation(2)
    
            Public mobileStation As New MobileStation(1, BaseStation.Stations(0))
    
    
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
            <STAThread()> _
            Private Sub Main()
    
                Application.EnableVisualStyles()
                Application.SetCompatibleTextRenderingDefault(False)
                Application.Run(New Handover())
            End Sub
        End Module
    End Namespace

    Its complete code, Hope its helpful to correct the error.
    Thanks
    With Regards,
    Naina Ronak

    Thursday, June 4, 2009 11:13 AM

All replies

  • Hi NainaRonak,

    Since your code is not completed, we don't know some variable type, like "MS", statusHO", etc. It is difficult to say why you are getting the problem, I suggest you post completed code, which can help us to find the problem.


    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Thursday, June 4, 2009 3:21 AM
  • Thanks for your kind reply, I was able to solve the above problem
    the code is supposed to be like this

     

    If Not isStarted Then
    
    Dim newThread As New Thread(AddressOf StartHandovering)
    
    newThread.Start()
    
    isStarted = True
    
    End If

    Now my problem is another error after i fix above error, when option strict is on error is :-

    " Option Strict On disallows implicit conversions from 'String' to 'Double'.

    If i put option strict off then i get this error:-

    System.InvalidCastException was unhandled
      Message="Conversion from string "MOB_NBR_ADV ----- Delay: " to type 'Double' is not valid."
      Source="Microsoft.VisualBasic"....

    'here is the code of handover.vb 

    Option Explicit On ' Force explicit variable declaration. Option Strict On Imports System Imports System.Text Imports System.Data Imports System.Drawing Imports System.Threading Imports System.Environment Imports System.Diagnostics Imports System.Windows.Forms Imports System.ComponentModel Imports System.Windows.Forms.Timer Imports System.Collections.Generic Imports Handover.HO Public Class Handover Dim manResEvent As Object Dim isPause As Boolean = False Dim swTimer As New Stopwatch() Dim msLocX As Integer = 486 Dim msLocY As Integer = 327 Dim program As Object Private Sub Handover_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WindowState = FormWindowState.Maximized Me.MS.Location = New Point(msLocX, msLocY) End Sub Private Sub cellTopology_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cellTopology.Click End Sub Private Sub sBS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sBS.Click End Sub Private Sub tBS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tBS.Click End Sub Private Sub MS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MS.Click End Sub Private Sub cPoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cPoint.Click End Sub Private Sub startHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startHO.Click Me.MS.Location = New Point(msLocX, msLocY)'MS is an image type moblie station which i want to move from one cell to other Me.isPause = False progressBarHO.Increment(progressBarHO.Step + 3) While MS.Location.X < (cPoint.Location.X - MS.Width) Me.MS.Location = New Point(MS.Location.X + 2, MS.Location.Y) My.Application.DoEvents() System.Threading.Thread.Sleep(100) End While Me.statusHO.AppendText("MS is at Cross Over Point " & vbCr & vbLf & vbCr & vbLf) progressBarHO.Increment(progressBarHO.Step + 3) While MS.Location.X < (thresHold.Location.X - MS.Width) MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1) Application.DoEvents() System.Threading.Thread.Sleep(100) End While Me.statusHO.AppendText("MS just reached Threshold Point " & vbCr & vbLf & vbCr & vbLf) progressBarHO.Increment(progressBarHO.Step + 3) Dim isStarted As Boolean = False While MS.Location.X < Hys.Location.X - MS.Width MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1) If Not isStarted Then Dim newThread As New Thread(AddressOf StartHandovering) newThread.Start() isStarted = True End If Application.DoEvents() System.Threading.Thread.Sleep(100) End While Me.statusHO.AppendText("MS just reached Hysteris Point" & vbCr & vbLf & vbCr & vbLf) progressBarHO.Increment(progressBarHO.Step + 6) While MS.Location.X < (Hys.Location.X + Hys.Location.X / 10) MS.Location = New Point(MS.Location.X + 2, MS.Location.Y - 1) Application.DoEvents() System.Threading.Thread.Sleep(100) progressBarHO.Increment(progressBarHO.Step) End While If Me.progressBarHO.Value = progressBarHO.Maximum Then HOProgress.Text = "Handover Sucessfully Completed" Else progressBarHO.Increment(progressBarHO.Maximum) HOProgress.Text = "Handover Sucessfully Completed" End If End Sub Private Sub pauseHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pauseHO.Click If isPause Then isPause = False Me.pauseHO.Text = "Pause" timerBS.Enabled = True Else Me.pauseHO.Text = "Continue" isPause = True timerBS.Enabled = False End If While isPause System.Threading.Thread.Sleep(100) Application.DoEvents() End While End Sub Public Sub StartHandovering() Dim sw As New Stopwatch() sw.Reset() 'Stops time interval measurement and resets the elapsed time to zero. sw.Start() 'Starts, or resumes, measuring elapsed time for an interval. BS.ProcessRequest(Request.MOB_SCN_REQ, bsType.Serving) sw.[Stop]() 'Stops measuring elapsed time for an interval. AddStatus("T1 - " & Request.MOB_SCN_REQ.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.SYNC, bsType.Neigboring) sw.[Stop]() Me.AddStatus("T2- " & Request.SYNC.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.MOB_MSHO_REQ, bsType.Serving) sw.[Stop]() 'AddStatus(Request.MOB_MSHO_REQ.ToString(), sw.ElapsedTicks); sw.Reset() sw.Start() BS.ProcessRequest(Request.RNG_REQ_CB, bsType.Target) sw.[Stop]() Me.AddStatus("T3 - " & Request.RNG_REQ_CB.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.RNG_REQ_CF, bsType.Target) sw.[Stop]() Me.AddStatus("T4 - " & Request.RNG_REQ_CF.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.CAP_NEGO, bsType.Serving) sw.[Stop]() Me.AddStatus("T5 - " & Request.CAP_NEGO.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.AUTH_KEY_EXG, bsType.Serving) sw.[Stop]() Me.AddStatus("T5 - " & Request.AUTH_KEY_EXG.ToString(), sw.Elapsed.TotalMilliseconds) System.Threading.Thread.Sleep(50) sw.Reset() sw.Start() BS.ProcessRequest(Request.REG_REQ, bsType.Target) sw.[Stop]() Me.AddStatus("T7 - " & Request.REG_REQ.ToString(), sw.Elapsed.TotalMilliseconds) 'manResEvent[0].Set(); System.Threading.Thread.Sleep(50) End Sub Private Sub timerBS_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerBS.Tick swTimer.Reset() 'Reset timer on form shown swTimer.Start() 'Start timer on form shown BS.ProcessRequest(Request.MOB_NBR_ADV, bsType.Serving) swTimer.Stop() Me.AddStatus(Request.MOB_NBR_ADV.ToString(), swTimer.Elapsed.TotalMilliseconds) End Sub Private Sub AddStatus(ByVal message As String, ByVal delay As Double) statusHO.AppendText((message & " ----- Delay: ") + Math.Round(delay, 4) * 10000 & " ms " & vbCr & vbLf & vbCr & vbLf)'Here i get this error End Sub Private Sub statusHO_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles statusHO.TextChanged End Sub Private Sub resetStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetStatus.Click Me.statusHO.Text = "" HOProgress.Text = "Handover Progress" Me.progressBarHO.Value = progressBarHO.Minimum End Sub Private Sub stopHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopHO.Click If Me.stopHO.Text = "Stop." Then Me.timerBS.Enabled = False Me.stopHO.Text = "Click to start again" Else Me.timerBS.Enabled = True Me.stopHO.Text = "Stop" End If End Sub Private Sub closeWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeWindow.Click Me.Close() End Sub Private Sub progressBarHO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles progressBarHO.Click End Sub Private Sub HOProgress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HOProgress.Click End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub End Class

    I also tried all conversions and parse iformat . but then i get error while option strict is on "Input strin not in correct format"
    I want the results somehow in this way in the text box "statusHO":

    MOB_NBR_ADV    -----   Delay: 31174 ms

    MS just reached Threshold Point
    MS is at Cross Over Point

    T1 - MOB_SCN_REQ    -----   Delay: 2857 ms

    T2 - SYNC    -----   Delay: 3103 ms

    T3 - RNG_REQ_CB    -----   Delay: 234602 ms

    MS just reached crossover point

    T4 - RNG_REQ_CF    -----   Delay: 284 ms

    T5 - CAP_NEGO    -----   Delay: 3011 ms

    T6 - AUTH_KEY_EXG    -----   Delay: 7875 ms

    T7 - REG_REQ    -----   Delay: 3084 ms

    MOB_NBR_ADV    -----   Delay: 83 ms

    MOB_NBR_ADV    -----   Delay: 120 ms

    Below is the code of another " constants.vb"

    'Here is the code of constants.vb
    Imports System Imports System.Collections.Generic Imports System.Text Namespace HO Class Constants Public Const SCANNING_TIMEOUT As Integer = 20 Public Const AUTHENTICATION_TIMEOUT As Integer = 10 'Public Const MOB_SCN_REQ_TIMEOUT As Integer = 3 'Public Const SYNC_TIMEOUT As Integer = 2 'Public Const RNG_REQ_CB_TIMEOUT As Integer = 10 'Public Const RNG_REQ_CF_TIMEOUT As Integer = 4 'Public Const CAP_NEGO_TIMEOUT As Integer = 4 'Public Const AUTH_KEY_EXG_TIMEOUT As Integer = 6 'Public Const REG_REQ_TIMEOUT As Integer = 5 'public const int Public Const MOB_SCN_REQ_TIMEOUT As Integer = 0 Public Const SYNC_TIMEOUT As Integer = 0 Public Const RNG_REQ_CB_TIMEOUT As Integer = 0 Public Const RNG_REQ_CF_TIMEOUT As Integer = 0 Public Const CAP_NEGO_TIMEOUT As Integer = 0 Public Const AUTH_KEY_EXG_TIMEOUT As Integer = 0 Public Const REG_REQ_TIMEOUT As Integer = 0 Public Const program As Integer = 0 End Class Public Enum Request MOB_NBR_ADV MOB_SCN_REQ HO_Indication RNG_REQ RNG_REQ_CF RNG_REQ_CB MOB_MSHO_REQ HO_Notification MOB_HO_IND CAP_NEGO SBC_REQ REG_REQ SYNC AUTH_KEY_EXG End Enum Public Enum Response Processed UnProcessed HO_Response RNG_RSP RNG_RSP_CF RNG_RSP_CB HO_Notification_RSP MS_INFO_RSP SBC_RSP MOB_HO_RSP MOB_SCN_RSP REG_RSP End Enum Public Enum bsType Serving Target Neigboring End Enum Public Structure BaseStation Public Stations As BSInfo() Public Sub New(ByVal stations__1 As Integer) Dim BaseStations As New List(Of BSInfo)() Dim s As Integer = 1 If s < stations__1 Then s = stations__1 End If For i As Integer = 1 To s Dim bInfo As New BSInfo() bInfo.ID = i BaseStations.Add(bInfo) Next Stations = BaseStations.ToArray() End Sub End Structure Public Structure MobileStation Public ID As Integer Public bsServing As BSInfo Public NeighborBS As BSInfo() Public TargetBS As BSInfo() Public Sub New(ByVal msID As Integer, ByVal sBS As BSInfo) ID = msID bsServing = sBS NeighborBS = Nothing TargetBS = Nothing End Sub End Structure Public Structure BSInfo Public ID As Integer End Structure End Namespace

    Another page BS.vb

    'Code of BS.vb
    Option Explicit On
    Option Strict On
    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Threading
    Namespace HO
        Class BS
            Public Shared Function ProcessRequest(ByVal req As Request, ByVal BS As bsType) As Object
                If BS = bsType.Serving Then
                    If req = Request.MOB_NBR_ADV Then
                        Return NeighborAdvertisement()
                    ElseIf req = Request.MOB_SCN_REQ Then
                        Return HOIndication()
                    ElseIf req = Request.MOB_MSHO_REQ Then
                        Return HONotification()
                    ElseIf req = Request.MOB_HO_IND Then
                        Return RangingRequest(3, 6, req)
                    ElseIf req = Request.CAP_NEGO Then
                        Return CapabilityNegotiation()
                    ElseIf req = Request.AUTH_KEY_EXG Then
                        Authenticate()
                        Subscribe()
                        KeyExchange()
                        Authorize()
    
                        Return True
                    End If
                ElseIf BS = bsType.Neigboring Then
                    If req = Request.RNG_REQ Then
                        Return RangingRequest(3, 6, req)
                    ElseIf req = Request.SYNC Then
                        Return Synchronize()
                    End If
                ElseIf BS = bsType.Target Then
                    If req = Request.REG_REQ Then
                        Return Register()
                    ElseIf req = Request.RNG_REQ_CB Then
                        Return RangingRequest(1000, 1200, req)
                    ElseIf req = Request.RNG_REQ_CF Then
                        Return RangingRequest(1, 1, req)
                    End If
                End If
    
                Return Response.UnProcessed
            End Function
    
            Private Shared Function NeighborAdvertisement() As Boolean
                Dim bss As New List(Of BSInfo)()
                For Each bs As BSInfo In Program.baseStation.Stations
                    If Program.mobileStation.bsServing.ID <> bs.ID Then
                        bss.Add(bs)
                    End If
                Next
    
                Program.mobileStation.NeighborBS = bss.ToArray()
                Program.mobileStation.TargetBS = bss.ToArray()
    
                Return True
            End Function
    
            Private Shared Function Synchronize() As Boolean
                System.Threading.Thread.Sleep(Constants.SYNC_TIMEOUT)
                Return True
            End Function
    
            Private Shared Function HOIndication() As Single
                System.Threading.Thread.Sleep(Constants.MOB_SCN_REQ_TIMEOUT)
                Return Constants.SCANNING_TIMEOUT
            End Function
    
            Private Shared Function CapabilityNegotiation() As Boolean
                System.Threading.Thread.Sleep(Constants.CAP_NEGO_TIMEOUT)
                Return True
            End Function
    
            Private Shared Function RangingRequest(ByVal minValue As Integer, ByVal maxValue As Integer, ByVal req As Request) As Boolean
                Dim n As Integer = New Random().[Next](minValue, maxValue)
    
                For i As Integer = 0 To n - 1
                    Continue For
                Next
    
                If req = Request.RNG_REQ_CB Then
                    System.Threading.Thread.Sleep(Constants.RNG_REQ_CB_TIMEOUT)
                ElseIf req = Request.RNG_REQ_CF Then
                    System.Threading.Thread.Sleep(Constants.RNG_REQ_CF_TIMEOUT)
                End If
    
                Return True
            End Function
    
            Private Shared Function HONotification() As Boolean
                Return True
            End Function
    
            Private Shared Function Authenticate() As Boolean
                Return True
            End Function
    
            Private Shared Function Subscribe() As Boolean
                Return True
            End Function
    
            Private Shared Function KeyExchange() As Boolean
                Return True
            End Function
    
            Private Shared Function Authorize() As Boolean
                System.Threading.Thread.Sleep(Constants.AUTH_KEY_EXG_TIMEOUT)
                Return True
            End Function
    
            Private Shared Function Register() As Boolean
                System.Threading.Thread.Sleep(Constants.REG_REQ_TIMEOUT)
                Return True
            End Function
        End Class
    End Namespace
    

    Another Page Program.vb

    'Code of Program.vb
    Imports System
    Imports System.Collections.Generic
    Imports System.Windows.Forms
    Namespace HO
        Module Program
            Sub New()
            End Sub
    
            Public baseStation As New BaseStation(2)
    
            Public mobileStation As New MobileStation(1, BaseStation.Stations(0))
    
    
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
            <STAThread()> _
            Private Sub Main()
    
                Application.EnableVisualStyles()
                Application.SetCompatibleTextRenderingDefault(False)
                Application.Run(New Handover())
            End Sub
        End Module
    End Namespace

    Its complete code, Hope its helpful to correct the error.
    Thanks
    With Regards,
    Naina Ronak

    Thursday, June 4, 2009 11:13 AM
  • Luckily i was able to slove the above problem.
    Correct code is

    statusHO.AppendText(message &

    "Delay: " & +Math.Round(delay, 4) * 10000 & " ms " & vbCr & vbLf & vbCr & vbLf)
    i was missing one side '&'

    Now my another problem is Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on.


    System.InvalidOperationException was unhandled
      Message="Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on."
      Source="System.Windows.Forms"
      StackTrace:
           at System.Windows.Forms.Control.get_Handle()
           at System.Windows.Forms.TextBoxBase.GetSelectionStartAndLength(Int32& start, Int32& length)
           at System.Windows.Forms.TextBoxBase.AppendText(String text)
           at Handover.Handover.AddStatus(String message, Double delay) in E:\Thesis\Handover\Handover\Handover.vb:line 252
           at Handover.Handover.StartHandovering() in E:\Thesis\Handover\Handover\Handover.vb:line 133
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    During debugging i get this error. But if i run exe file(application) directly from debug folder it works fine and displays the results as well.
    Please note 'statusHO' is text box where i appendtext and display results.

    Regarding this error i have gone through all material especial this

    Visual Basic Developer Center
    > Visual Basic Forums > Visual Basic General > Cross-thread operation not valid
     which got extensive disscussion on cross threads,But i couldnt understand it .Only i get regarding using

    System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls =

    False

     

     

     

    i tried to use it it works fine then. but as it is mentioned its not a good practice to use it. So what should i do? is it ok if i use this as i am not able to use correct practice. Mine application is not for enterprise purpose. its just my class project, and it works fine even if i put application working in background. System works ok.  I dont know how to correct this error.As i dont have that much knowlege of threads.
    So please guide me how to fix this in correct way otherwise i am force to go for bad programming practice
    Thanks
    Regards,
    Naina Ronak

    Thursday, June 4, 2009 10:55 PM
  • Average radio layer latency

    (∑ (i=0)^(HO_success)▒〖(T2,i-T1,i)〗)⁄(HO_success)
    (summation is i=0 upto HO_success,with T2,i-T1,i)divided by HO success  

    This value measures the delay between the time instance T

    1,i that an MS transmits a serving BS its commitment to HO and the time instance T2,i that the MS achieves the success of the PHY layer synchronization (i.e., frequency and DL timing synchronization) due to handover occurrence i. 

    Please tell me how to code this as in above code i want to find the Average radio layer latency. How to use this formula in loop

    1,i that an MS transmits a serving BS its commitment to HO and the time instance T2,i that the MS achieves the success of the PHY layer synchronization (i.e., frequency and DL timing synchronization) due to handover occurrence i. 

    Please tell me how to code this as in above code i want to find the Average radio layer latency. How to use this formula in loop

    Friday, June 5, 2009 8:04 AM