.net - System.TypeInitializationException FORM access to Class -


i'm working on project need call class create , manage excel file. undefined reasons can't call function form. return exception : system.typeinitializationexception. i've check class don't see wrong.

the form want call excel_management class :

imports system.diagnostics imports system.windows.forms  public class proc_form  private excel_manage = new excel_management public shared ok boolean = new boolean   if my.settings.check_directory = false             if folderbrowserdialog1.showdialog = dialogresult.ok                 my.settings.path = folderbrowserdialog1.selectedpath                 my.settings.check_directory = true                 'my.settings.save()                 msgbox(my.settings.path)                 excel_manage.check_excel()         end if 

the excel_management class :

imports microsoft.office.interop imports microsoft.office.interop.excel imports system.windows.forms imports system.text.regularexpressions imports system.string  public class excel_management     public shared appexcel excel.application = new excel.application     public shared wsexcel excel.worksheet = new excel.worksheet     public shared wbexcel excel.workbook = new excel.workbook     public shared file_name string = "name" & datetime.now.tostring("yyyy") & ".xls"     public shared sheet_name string = "s " & datepart(dateinterval.weekofyear, now())     public shared check_test boolean = false     public shared excel_check new proc_form     public shared misvalue object = system.reflection.missing.value     public shared message, title, defaultvalue string     public shared myvalue object = new object     public shared integer = 1     public shared match match = regex.match(myvalue, "[^a-z0-9]")  shared sub check_excel()         if appexcel nothing             msgbox("no excel detected !")             return         else             create_excel()         end if     end sub 

can see issue code not allowing me access excel class?

thank in advance.

i think issue can't create new excel.workbook way doing since it's interface.

try instead:

public shared wbexcel excel.workbook = appexcel.workbooks.add(system.reflection.missing.value) 

from here: strange error on excel workbook input, or 1 of other solutions question.

also, regex.match can't match on object. don't know myvalue is, 1 option depending on might be:

regex.match(myvalue.tostring, "[^a-z0-9]") 

finally, these errors readily apparent if debugger in visual studio break on them. go "debug" menu > "exceptions..." , put checkmark next "common language runtime exceptions" in "thrown" column. should debug other errors.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -