[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

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
0
cmdolcet
Asked:
cmdolcet
  • 7
  • 6
  • 5
2 Solutions
 
CodeCruiserCommented:
It looks like e is not being used anywhere in that sub so I would suggest you try passing Nothing

Open_G300_COM(Nothing)
0
 
Jerry MillerCommented:
Are you getting any errors? Normally the 'EventArgs' are not necessary to pass. For example, I have a sub and the GridViewRowEventArgs are not passed in anything that I am doing.

Protected Sub gvFilters_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
0
 
cmdolcetAuthor Commented:
I do get an error after I pass nothing. I get an Null Reference Error. I have attached the actual screen

Thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CodeCruiserCommented:
>I have attached the actual screen

No you have not.

Which line generates the error as I don't see e being used anywhere.
0
 
cmdolcetAuthor Commented:
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
0
 
Jerry MillerCommented:
Do you get an error when pass it as Open_G300_COM()?
0
 
CodeCruiserCommented:
Ah I missed that. So the code picks up info from active sheet. You can either pass it a row reference (something like ActiveSheet.ActiveRow etc) or change the function so it does not rely on that.

>Do you get an error when pass it as Open_G300_COM()?

Yes he will get a compile error because that's not an optional parameter.
0
 
cmdolcetAuthor Commented:
Yes that is my question how can I pass this by ref or by val in the code above?
0
 
Jerry MillerCommented:
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)
0
 
cmdolcetAuthor Commented:
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
0
 
Jerry MillerCommented:
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
0
 
cmdolcetAuthor Commented:
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.
0
 
Jerry MillerCommented:
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
0
 
CodeCruiserCommented:
@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.
0
 
Jerry MillerCommented:
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)
0
 
cmdolcetAuthor Commented:
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
0
 
cmdolcetAuthor Commented:
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
0
 
CodeCruiserCommented:
YOu are not splitting the points are you?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now