Error: "Reference to a non-shared member requires an object reference" - vb.net

I am building a small app that is pulling script from within an object. I'm down to the portion where my code is pulling back the field from the object that has the script and I'm getting this error.
"reference to a non-shared member requires an object reference"
I'm not sure what to change or how to get around this. Does anyone out there have any suggestions?
Here is the code that i have so far. It's a simple app that has a combobox that you choose the company from and on button click it will get the script and show it in the textbox.
Here is my code:
Imports System.IO
Public Class Form1
Public M3System As MILLSYSTEMLib.System
Public M3Script As MILLCOMPANYLib.CScripting
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'On Error Resume Next
Try
Dim Approved As Integer
' Create a Millennium system obects
M3System = CreateObject("MillSystem.System")
M3System.Load("Millennium")
'run login script
Dim User As Object = M3System.Login()
' See if login worked
If User Is Nothing Then
'MsgBox("Login failed!")
Approved = 0
Else
'MsgBox("Login successful")
'if approved=1 then the user is able to access M3
Approved = 1
End If
'populate combo box
For Each Company In M3System.Companies
cb_COID.Items.Add(Company.Field("co").ToString)
Next
Catch ex As Exception
Me.Close()
End Try
End Sub
Public Sub btn_LoadScript_Click(sender As Object, e As EventArgs) Handles btn_LoadScript.Click
Dim CoCode As String = cb_COID.SelectedItem
Dim script As String = M3Script.vbscript
If IsNothing(cb_COID) Then
MessageBox.Show("Select a Company Code")
End If
For Each CoCode In M3Script.co
tb_Script.Text = script
Next
End Sub

I'm guessing that the line you are failing on is Dim script As String = M3Script.vbscript
If that is the case, it's because you are declaring the M3Script, but you are not creating an instance of it.
Try setting the object somewhere by adding M3Script = new MILLCOMPANYLib.CScripting to your code, or however you would load it (perhaps M3Script = CreateObject("MillSystem.Script")?)

Related

Bound datatgridview not saving changes to tableadapter, and thus not to database

I have a datagridview bound to a table that seems to work fine, but will not save changes to the database. I am using the same code as I used in another project, which did save changes, so I am flummoxed. Also, I have debugged and the save code is being called, just not working. The code in the form calls a separate class with business logic.
Code in the form below:
Private Sub frmAdminAssign_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Below is generated by Visual Studio when I select my data source for my datagridview
Credit_adminTableAdapter.Fill(DataSet1.credit_admin) ' Foreign key relationship to table being updated (lookup table).
LoanTableAdapter.Fill(DataSet1.loan) ' Table being updated
admin_assign = New AdminAssign()
admin_assign.FilterUnassigned(dgvAssign, LoanTableAdapter)
End Sub
Private Sub dgvAssign_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAssign.CellEndEdit
admin_assign.SaveAssignmentChanges(DataSet1, LoanTableAdapter)
End Sub
Below is code in business logic class called from above:
Public Sub SaveAssignmentChanges(ByRef data_set As DataSet1, ByRef loan_table_adapter As DataSet1TableAdapters.loanTableAdapter)
' Saves changes to DB.
Dim cmdBuilder As SqlCommandBuilder
cmdBuilder = New SqlCommandBuilder(loan_table_adapter.Adapter)
loan_table_adapter.Adapter.UpdateCommand = cmdBuilder.GetUpdateCommand(True)
Try
loan_table_adapter.Adapter.Update(data_set)
Catch unknown_ex As Exception
Dim error_title As String = "Database Save Error"
Dim unknown_error As String = $"There was an error saving to the database.{vbNewLine}Error: {unknown_ex.ToString}"
MessageBox.Show(unknown_error, error_title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub
The data from the datagridview is not saving to the tableadapter, which I found out by adding the lines below in the start of the second procedure:
Dim x As String = loan_table_adapter.GetData()(0)("note_number") ' Unchanged, check was right row
Dim y As String = loan_table_adapter.GetData()(0)("credit_admin_id") ' Changed in datagridview but still null (get null error)
I figured it out, it was related to a filter routine that is not above where I passed a tableadapter byref when I should have passed a datatable byval. So, related to one of jmcilhinney's byref vs byval comments above. See problem code below:
Public Sub FilterUnassigned(ByRef dgv_assigned As DataGridView, loan_table_adapter As DataSet1TableAdapters.loanTableAdapter)
' Should have passed in DataSet1.loan DataTable ByVal and used it below:
Dim unassigned_loans As DataView = loan_table_adapter.GetData().DefaultView()
unassigned_loans.RowFilter = "request_date Is Not Null AND numerated_assigned_user Is Null"
dgv_assigned.DataSource = unassigned_loans
End Sub
Also, skipping the SQLCommandBuilder commands and my code still works. So, all I need is one line as per jmcilhinney instead of 4 (excl error handling) as per below:
Try
loan_table_adapter.Update(data_set)
Catch unknown_ex As Exception
Dim error_title As String = "Database Save Error"
Dim unknown_error As String = $"There was an error saving to the database. Please contact Kevin Strickler to resolve.{vbNewLine}Error: {unknown_ex.ToString}"
MessageBox.Show(unknown_error, error_title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try

Argument 'Prompt' cannot be converted to type 'String' with Entity Framwork

This is my first time I'm trying to use Entity Framework.
I made a database with one table (Paths) and two attributes (PathID, PathName). In vb-net I just want the user to choose a folder with a FolderBrowserDialog and have the path of that folder saved in the column "PathName". When running, I get the error "Argument 'Prompt' cannot be converted to type 'String'"
The code is simple and straight forward so I can't figure out what I'm doing wrong.
Public Class AddPaths
Dim Db_EF As New vs_check_work_Entities
Dim tbl_path As New Paths
Private Sub AddPaths_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btn_AddPath_Click(sender As Object, e As EventArgs) Handles btn_AddPath.Click
Try
Dim FldrBrser As New FolderBrowserDialog
If FldrBrser.ShowDialog = DialogResult.OK Then
TxtBoxPath.Text = FldrBrser.SelectedPath
With tbl_path
.PathName = FldrBrser.SelectedPath
End With
Db_EF.Paths.Add(tbl_path)
Db_EF.SaveChanges()
End If
Catch ex As Exception
MsgBox(ex.Message)
'MsgBox(ex.InnerException)
End Try
End Sub
Private Sub PathsBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles PathsBindingNavigatorSaveItem.Click
Db_EF.SaveChanges()
End Sub
End Class
The error happens at
Db_EF.Paths.Add(tbl_path)
I also tried to test with just adding a string to the table:
With tbl_path
.PathName = "hello world"
End With
Db_EF.Paths.Add(tbl_path)
Db_EF.SaveChanges()
I Get the same error.
May need to see your Entity model. However, I think that you have a database property called Prompt on your table. It may be that Prompt is defined as something other than a string but the database expects an nvarchar (or varchar).
My whole EF project wasn't set up correctly. I think I did code first. Now I tried starting with Designer and all works well. Don't know what the problem was but it works now.

BC30456 VB subroutine is not a member of class file

I have already asked DevExpress this question which they have told me I have problem with my code that involves deleting a row from a DevExpress Gridview. Basically, I have a VB code-behind routine:
Protected Sub ASPxGridViewUnscheduledReviews_RowDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs) Handles ASPxGridViewUnscheduledReviews.RowDeleting
'Dim aspxGridView As ASPxGridView = sender
Dim StatusID As Integer = CType(e.Keys("AcrStatusID"), Integer)
'delete row from ACRStatus table where AcrStatusID = StatusID
Try
lblMessage.Text = String.Empty
'Dim bl As New CYCIS_BL.Reviews
CYCIS_DL.Reviews.**UnscheduledReviewDelete(StatusID)**
Response.Redirect("ACR_RemoveUnSchReview.aspx")
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
where UnscheduledReviewDelete(StatusID) calls a Public Shared Sub from a Data Layer Reviews.vb class, which in turn executes an SQL stored procedure to delete the selected record.
The subroutine in Reviews is:
Public Shared Sub UnscheduledReviewDelete(ByVal StatusID As Integer)
Using dbManager As New DBManager(DataProviderEnums.SqlServer, SQLConnectionHelper.CONN_STRING)
Try
With dbManager
.Open()
.CreateParameters(1)
.AddParameters(0, "#StatusID", StatusID)
.ExecuteNonQuery(CommandType.StoredProcedure, "UnscheduledReviewDelete")
End With
Catch ex As Exception
Throw
End Try
End Using
End Sub
I have saved and built and rebuilt the class file and solution several times. and yet every time I build the solution the compiler throws this same error and the dynamic metadata of Reviews class shows every routine and function except for the one above. Why is it not recognizing the subroutine as part of the Reviews class?

Is there a way to get the input from a Load event handler (entered via inputBox) to be used Globally in the program?

I am creating a form that will prompt the user to enter a file name upon loading the file. The issue I encounter is that my variable I use to store the input is not recognized in another one of my procedures. The code here shows my current set up.
Imports System.IO
Public Class frmEmployee
Sub frmEmployee_load(ByVal sender As Object, e As System.EventArgs)
Dim strFileName = InputBox("Please name the file you would like to save the data to: ")
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtEmail.Clear()
txtExtension.Clear()
txtFirst.Clear()
txtLast.Clear()
txtMiddle.Clear()
txtNumber.Clear()
txtPhone.Clear()
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim inputFile As New StreamWriter(strFileName)
If File.Exists(strFileName) = True Then
inputFile = File.CreateText(strFileName)
inputFile.Write(txtEmail.Text)
inputFile.Write(txtExtension.Text)
inputFile.Write(txtFirst.Text)
inputFile.Write(txtLast.Text)
inputFile.Write(txtMiddle.Text)
inputFile.Write(txtNumber.Text)
inputFile.Write(txtPhone.Text)
inputFile.Write(cmbDepart.Text)
Else
MessageBox.Show("" & strFileName & "Cannot be created or found.")
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
The load event handler is where I want the user to input the name of the file.
Change the scope of your variable to outside of your load method...
Public Class frmEmployee
Private strFileName As String
Sub frmEmployee_load(ByVal sender As Object, e As System.EventArgs)
strFileName = InputBox("Please name the file you would like to save the data to: ")
End Sub
You could use My.Settings and load the file string there and save it. All forms can now access that. When you close the the app set it to String.Empty if you want it to be.
You also could be taking advantage of a class object for the fields you are capturing then using either BinaryFormatter or XmlSerializer to store the data. Better databinding, creation and reconstruction using an object.
My.Settings.Filename = Inputbox("Filename?")
My.Settings.Save()
The problem with the approach you have there is that your variabl strFileName is scoped to the class frmEmployee.
You need to set up a genuinely global variable (at the application startup) an then use that. So you will need a Sub Main as an entry point to your application See here, and just before that create a public variable to hole the file name.
So you might have something like this for your application startup:
Public fileNametoUse as string
Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1)
End Sub
Then in you load sub for frmEmployee you would have:
fileNametoUse = InputBox("Please name the file you would like to save the data to: ")

How to ignore windows events when in a child form called from that event handler?

My specific question is: How to ignore windows events when in a child form called from that event handler?
Some context: My application captures a fingerprint, and puts up the next form (secondForm) when a print is recognized against the database. I want to ignore any prints they put in while their secondForm is up. The trouble is that when people press the print multiple times, or while their secondForm is up, then the events are queued until after the secondForm closes, so I get multiple calls to the event handler for that person.. I've tried so many ways around this, including calling the routine that open secondForm as a delegate(is that even appropriate), putting a global boolean in the event handler, etc. If I disable fingerprint capture during the oncomplete eventhandler, my form never shows up.
Am I missing something obvious to you here? Much gratitude for any ideas...
Imports DPFP.Capture ' DigitalPersona fingerprint reader library
' Simple example to capture a fingerprint from DigitalPersona fingerprint reader.
Public Class SimpleFP
Implements DPFP.Capture.EventHandler
Private mIgnore As Boolean
Public eventHandlerComplete As DPFP.Capture.EventHandler
Public WithEvents mCapture As DPFP.Capture.Capture
Private Sub WaitForFPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
' set up finger print capture
mCapture = New DPFP.Capture.Capture
mCapture.EventHandler = Me
mCapture.StartCapture()
Catch ex As Exception
MsgBox("Problem starting fingerprint reader: " & ex.Message)
End Try
End Sub
Public Sub FPOnComplete(ByVal Capture As Object, ByVal sernum As String, ByVal sample As DPFP.Sample) _
Implements DPFP.Capture.EventHandler.OnComplete
'mCapture.StopCapture()
'This is what I want to do, but when I leave this in, my secondForm won't stay up
Dim s As String = displaySecondScreen(sample)
showStatus(s)
'mCapture.StartCapture()
'This is what I want to do, but when I leave this in, my secondForm won't stay up
End Sub
' Put up second form. This is called from the fingerprint OnComplete event handler.
Private Function displaySecondScreen(ByVal sample As DPFP.Sample) As String
Dim status As String = "OK"
Try
Dim x As DPFP.FeatureSet
x = extractFeatures(sample)
' This is where I match the fp in my code, but I removed here to simplify
If True Then
Dim frm As New frmSecondForm
frm.ShowDialog(Me)
frm.Dispose()
Else
' No fingerprint match - normal case
status = "Fingerprint not recognized"
End If
Catch ex As Exception
status = "Exception during fingerprint verification: " & ex.Message
End Try
Return status
End Function
' Made rudimentary for this example, but I thought some person new to dpfp may be able to use this
Private Function extractFeatures(ByVal sample As DPFP.Sample) As DPFP.FeatureSet
Dim extractor As New DPFP.Processing.FeatureExtraction()
Dim feedback As New DPFP.Capture.CaptureFeedback()
Dim features As New DPFP.FeatureSet()
extractor.CreateFeatureSet(sample, DPFP.Processing.DataPurpose.Verification, feedback, features)
If feedback = DPFP.Capture.CaptureFeedback.Good Then
End If
Return features
End Function
Private Sub debugOut(ByVal s As String)
Console.WriteLine(s)
End Sub
' Display status on first form
Delegate Sub showStatusCallback(ByVal s As String)
Private Sub showStatus(ByVal s As String)
If lblStatus.InvokeRequired Then
Dim d As New showStatusCallback(AddressOf showStatus)
Me.Invoke(d, New Object() {s})
Else
lblStatus.Text = s
End If
End Sub
' ... followed by other implements dpfp eventhandlers not in use....
' ....
End Class