What am I doing wrong now?

Started by stanl, November 08, 2022, 07:17:10 AM

Previous topic - Next topic

stanl

Code (WINBATCH) Select


ObjectClrOption("useany", "System.Data")
Oledb =  ObjectClrNew("System.Data.Oledb")
Provider = ObjectClrNew("System.Data.Oledb.Oledbenumerator")
Providers = Provider.GetElements()
output="Source_Name,Description":@CRLF
ForEach e in Providers
   output = output:e.Sources_Name:",":e.Sources_Description:@CRLF
Next


Message("Provider Output",output)


Exit



td

"System.Data.Oledb" is a namespace and not a class so you cannot nor need to create it using ObjectClrNew and you don't have the correct capitalization for "System.Data.OleDb.OleDbEnumerator". Class names are case sensitive.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Quote from: td on November 08, 2022, 07:37:51 AM
"System.Data.Oledb" is a namespace and not a class so you cannot nor need to create it using ObjectClrNew and you don't have the correct capitalization for "System.Data.OleDb.OleDbEnumerator". Class names are case sensitive.


I had tried it as namespace and would get a .dll not found error. But good old PS comes up with a one liner [and capitalization not an issue]. Problem is I have to write this in WB :-\



(New-Object system.data.oledb.oledbenumerator).GetElements() | select SOURCES_NAME, SOURCES_DESCRIPTION

td

The suggested changes are necessary and in testing, they do not produce a DLL not found error.

Again, if you think PS is the be-all to end-all and line count is the best metric for judging software solutions, you are likely posting to the wrong form. This is not a PS forum. It is a forum for WinBatch users and the WIL scripting language.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

This is but one way to do it using WIL CLR hosting. A more elegant solution using WIL CLR hosting would require more digging than I care to spend time on right now.

Code (winbatch) Select
;;; DotNet_Junk.wbt

ObjectClrOption("useany", "System.Data")
Provider = ObjectClrNew("System.Data.OleDb.OleDbEnumerator")
Providers = Provider.GetElements()

output="Source_Name,Description":@CRLF
Rows = Providers.Rows
ForEach Row in Rows
   aTmp = Row.ItemArray
   for i=0 to 3 by 2
      output := aTmp[i]:@lf
   next
Next

Message("Provider Output",output)

Exit


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

Thank you. Sorry if I upset you. It was not my intention to promote PS. I've seen multiple thread on Stack Overflow or other boards where a user might post vbscript code on a C# thread because they just needed help with the translation.


But for more context: I compiled an exe in 2012 which used Ace Provider 12.0 to work with Adox/Access/Excel data. I was contacted that the user had several PC's and one had been updated to Office 365. That is 64-bit so script fails, yet other PC's still have Office 2013 so still works. So the ask was to determine if Ace 12.0 was installed and if not assume Ace 16.0 - which would probably imply a re-compile as WB 64-bit.  I'm not sure if I can really help in the situation, since it would be a freebie, so first step was to determine if ACE was installed and if so which version.

td

Quote from: stanl on November 09, 2022, 04:02:09 AM
Thank you. Sorry if I upset you. It was not my intention to promote PS. I've seen multiple thread on Stack Overflow or other boards where a user might post vbscript code on a C# thread because they just needed help with the translation.

Can only guess about your motivation and being "upset" is not the cause of my response. However, this is a moderated forum and there is a difference between posting source for a language that is not a forum's targeted language and making statements that are clearly intended to provoke. As far as "Stack Overflow" is concerned it can choose how it moderates its forums but so can ILC LLC.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade