Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

Passing Variables

How to I pass the variable that is required to use the Open_G300_COM sub?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendG300DataUp.Click
        Open_G300_COM()
    End Sub


 Public Sub Open_G300_COM(ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs)
        Dim activeport As String
        Dim serialresponse As String
        Dim intmaxrows As Integer
        Dim Total_Bytes As String = "34"
        Dim Int_Rank As Integer = 0
        Dim GageID As String
        Dim UpdatePoint As String = "TP"
        Dim intloop As Integer
        Dim GageDescription As String
        Dim USL As String
        Dim LSL As String

        If Me.gridGages.ActiveSheet.Cells(e.Row, GridColumns.GageType).Text = "G-300" Then
            activeport = gridGages.ActiveSheet.ActiveCell.Text
            If serialPort.IsOpen Then
                serialPort.Close()
            End If
            serialPort.BaudRate = "57600"
            serialPort.PortName = "COM" & activeport
            serialPort.Parity = IO.Ports.Parity.None
            serialPort.DataBits = 8
            serialPort.StopBits = 1
            serialPort.RtsEnable = True
            serialPort.Open()
            System.Threading.Thread.Sleep(150)
            'Send Setup Mode to Wireless Base Device to Start the Listning
            serialPort.Write("<RS")
            'Loops through the Grid Row and sends each Point Parameter back up to the
            For intloop = 0 To gridGages.ActiveSheet.RowCount - 1
                GageID = gridGages.ActiveSheet.Cells(intloop, 1).Text
                GageDescription = gridGages.ActiveSheet.Cells(intloop, 0).Text
                If GageDescription.Length > 16 Then
                    Dim AddSpace As Integer = 0
                    AddSpace = 16 - GageDescription.Length
                ElseIf GageDescription.Length < 16 Then
                    GageDescription = GageDescription.PadRight(16, " ")
                End If

                USL = gridGages.ActiveSheet.Cells(intloop, 10).Text
                LSL = gridGages.ActiveSheet.Cells(intloop, 11).Text

                If USL.Contains(".") Then
                    USL = USL.Replace(".", "").PadLeft(4, "0")
                End If
                If LSL.Contains(".") Then
                    LSL = LSL.Replace(".", "").PadLeft(4, "0")
                End If
                System.Threading.Thread.Sleep(200)
                serialPort.Write("<@:L" & GageID & Total_Bytes & "<" & UpdatePoint & "," & "0" & Int_Rank & "," & GageDescription & "," & USL & "," & LSL & ">")
                System.Threading.Thread.Sleep(150)
                serialresponse = serialPort.ReadExisting
                Int_Rank = +1
            Next
        End If
        serialPort.Write("<RN")
        serialPort.Close()
    End Sub
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

It looks like e is not being used anywhere in that sub so I would suggest you try passing Nothing

Open_G300_COM(Nothing)
SOLUTION
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmdolcet

ASKER

I do get an error after I pass nothing. I get an Null Reference Error. I have attached the actual screen

Thanks
>I have attached the actual screen

No you have not.

Which line generates the error as I don't see e being used anywhere.
Code Cruiser, I am going to try this again please see attached

Also it happens on this line:

If Me.gridGages.ActiveSheet.Cells(e.Row, GridColumns.GageType).Text = "G-300" Then
Error-1.png
Do you get an error when pass it as Open_G300_COM()?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes that is my question how can I pass this by ref or by val in the code above?
Check out this link:
http://www.gcpowertools.com/help/spreadnet6/WF/FarPoint.Win.Spread~FarPoint.Win.Spread.FpSpread~ButtonClicked_EV.html

I think that it should be:

Public Sub Open_G300_COM(ByVal sender as object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs)
Ok but what is passed into the:

 Open_G300_COM()


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendG300DataUp.Click
        Open_G300_COM()
    End Sub
Add 'Handles' to the method for the data and remove the Button1_Click event.

Public Sub Open_G300_COM(ByVal sender as object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles btnSendG300DataUp.Click
OK Sorry but you lost me on that one. When I add the handles onto the following:

Public Sub Open_G300_COM(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles btnSendG300DataUp.Click

on the click property it says it cannot handle event Public Click(sender as object, e as system.EventArgs because they do not have the same signature.
Sorry, I think that it should have been ButtonClicked and not Clicked

Public Sub Open_G300_COM(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles btnSendG300DataUp.ButtonClicked

http://www.gcpowertools.com/help/spreadnet6/WF/FarPoint.Win.Spread~FarPoint.Win.Spread.FpSpread~ButtonClicked_EV.html
@imiller1979
He is trying to manually call that method.

@cmdolcet

I have not used that component so don't have much information about it. You would have to do some digging.
I am like @codeCruiser and haven't used this component.

If you can't assign the method to the ButtonClick event as I described above, you may be able to do something like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
       Dim btnSender as button = DirectCast(sender, button)
       Dim a as New FarPoint.Win.Spread.EditorNotifyEventArgs

 Open_G300_COM(btnSender, a))

    End Sub


Public Sub Open_G300_COM(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs)
OK here's what I did to get it to work:

 I passed the FarPoint.Win.Spread.FpSpread by Ref) .

  Public Sub Open_G300_COM(ByRef gridGages As FarPoint.Win.Spread.FpSpread)

Then in my button click event I did the following:

 Private Sub btnSendG300DataUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendG300DataUp.Click
        Open_G300_COM(Me.gridGages)
    End Sub


I think that both of you help me realize my issues so I will be splitting the points.

Thanks
I've requested that this question be closed as follows:

Accepted answer: 0 points for cmdolcet's comment #a38423197

for the following reason:

After look over other code examples I need to pass it byRef and then I could use the control
YOu are not splitting the points are you?