windows Shell Script not working with VB editor - wsh

Can anyone tell me why this code:
Set wshNetwork = WScript.CreateObject("WScript.Network")
strcomputerName = wshNetwork.ComputerName
MsgBox strcomputerName
Pcname = Mywb.Cells(4, 3).Value
If strcomputerName = Pcname Then
MsgBox "Hi Vivek!!"
End If
works in a vbs file but when it's put in as code in a VB Editor I get Runtime Time Error 424 - Object required?
What library do I need to reference?
am using Ms Excel 2010.
I have tried adding below libraries in reference:
MS scripting runtime
MS script control
and Windows script host object model
None of these seem to work for me.

Late binding with Excel 2010 using an object variable
Tools-->Reference-->Microsoft 14.0 Object Library
Dim strComputerName As String
Dim objWS As Object
Set objWS = CreateObject("Wscript.Network")
strComputerName = objWS.ComputerName
MsgBox strComputerName
Set objWS = Nothing

Related

How to declare an object in the "Mastering delphi" book

Im learning delphi through books and am encountering a problem in this chapter: http://etutorials.org/Programming/mastering+delphi+7/Part+IV+Delphi+the+Internet+and+a+.NET+Preview/Chapter+19+Internet+Programming+Sockets+and+Indy/Building+Socket+Applications/#toc
It is this peace of code that gives me trouble because i dont know where to write it.
object IdTCPServer1: TIdTCPServer
CommandHandlers = <
item
Command = 'test'
Name = 'TIdCommandHandler0'
ParseParams = False
ReplyNormal.NumericCode = 100
ReplyNormal.Text.Strings = (
'Hello from your Indy Server')
ReplyNormal.TextCode = '100'
end
That is part of a DFM file of a form with a non-visual component called TIdTCPServer on it. Just place such a component on your form and use the property editor to set the properties to the given values. For example, you have to add a command handler (using the CommandHandlers property) and set its Command property to "test".
That is part of the DFM file, which you don't edit directly. I just placed a TIdTCPServer on a form and the DFM shows:
object IdTCPServer1: TIdTCPServer
Bindings = <>
DefaultPort = 0
Left = 80
Top = 112
end
You can see this for yourself if you right click on your form and choose 'View as Text' (or if you inspect the .DFM files in an editor if you have your configuration set to save them as text.
When you start filling in more (non-default) properties of the TIdTCPServer, Delphi will store these in the DFM as well. I don't see a CommandHandlers property in my Delphi version (XE2, Indy 10.5.8.0), but yours has one (in the example).
[Edited to add] I see from your comment on another answer that you do not have a CommandHandlers property for TIdTCPServer either, this may indicate that the book author used a different Indy version than you do. You can see your version by right-clicking on any Indy component on the form.
CommandHandlers are indeed old. Googling "tidtcpserver commandhandlers" leads to e.g. "The CommandHandlers collection was moved to a new TIdCmdTCPServer component in Indy 10." That makes me suspect you have Indy 10 and the book references 9. You'll have to find Indy 10 examples for what you want to do. That should not be too difficult.

Windev Quickbooks SDK OpenConnection2

I've been trying to find a way to connect my Windev application using the Quickbooks SDK.
I wish to connect to my local QB instance using the qbXML API.
I've been able to get a reference to the library using :
myconnection = new object Automation "QBXMLRP2.RequestProcessor"
However, when it comes to the OpenConnection2 method, I only get errors. Either "missing parameter" or "invalid parameter". I am aware that I should pass a "localQBD" type to the function, but I have not found out how to reference it. The following represents my invalid script.
myconnection>>OpenConnection2("","My Test App", localQBD)
How can I achieve a connection to QB through Windev?
After much searching, I have found that I was on the right path using the automation variable type.
However, I have yet to find how to reference the constants provided by the library. Instead, I declare them beforehand like so
CONSTANT
omSingleUser = 0
omMultiUser = 1
omDontCare = 2
qbStopOnError = 0
qbContinueOnError = 1
ctLocalQBD = 1
ctLocalQBDLaunchUI = 3
FIN
Which gives us this working example
myconnection = new object Automation "QBXMLRP2.RequestProcessor"
ticket = myconnection>>BeginSession("",::omDontCare)
XMLresponse = myconnection>>ProcessRequest(ticket,XMLrequest)
myconnection>>EndSession(ticket)
myconnection>>CloseConnection()
delete myconnection
A huge thanks goes to Frank Cazabon for showing me the proper constant values.
I have a complete external WinDev component that accesses QB and a helper program that can generate the WinDev calls in the correct order with the correct spelling and provides an OSR for all the QuickBooks fields and modules.
I have a similar product for the Clarion language and am in the final stages of the WinDev version. Contact me if you are interested. qbsnap at wybatap.com

Crystal Reports XI PrintToPrinter "Missing parameter values"

I'm working on an issue with a Crystal report (Crystal XI running in a VB app) where a sporadic "Missing parameter values" error is received when trying to print the report directly. Here's a summary of the issue:
User runs the report via the report menu (everything works fine)
User clicks 'Print Preview' (everything works fine)
User clicks 'Print' (supposed to send the document directly to the printer, but sometimes get missing parameter error)
Here is what I had for code to start:
crystalReportViewer.MdiParent = parent
crystalReportViewer.Show()
Dim report As ReportDocument = CType(crystalReportViewer.ReportSource, ReportDocument)
report.PrintToPrinter(1, False, 0, 0)
crystalReportViewer.Close()
crystalReportViewer.Dispose()
Based on what I've been googling, I came up with this code:
crystalReportViewer.MdiParent = parent
crystalReportViewer.Show()
Dim report As ReportDocument = CType(crystalReportViewer.ReportSource, ReportDocument)
'here are my attempts to get it to work
Dim pf As ParameterFields = report.ParameterFields
report.PrintOptions.PrinterName = "Microsoft XPS Document Writer"
report.PrintToPrinter(1, False, 0, 0)
crystalReportViewer.Close()
crystalReportViewer.Dispose()
I'm about out of ideas on how to solve this issue. Has anyone else run across this?
Start Code: You problably have some empty parameter in your report.
After Search Code: You have this line:
Dim pf As ParameterFields = report.ParameterFields
You have a parameter, and you are not setting any value.
For both, use:
//[C#]
report.setParameterValue(parameterName, parameterValue);
It's very simple. Make sure that all of your parameters inside the report are filled and thrown data before using "printtoprinter". I have solved it with that.
As far as I can tell, this looks like an issue in Crystal. I couldn't find a fix, so I'm just using a workaround until a fix is available (report is generated and then printed manually).
First you need to add PrintDialog from toolBox
then add the following code button_click_event
ReportName.PrintOptions.PrinterName = PrintDialog1.PrinterSettings.PrinterName
ReportName.PrintOptions.PaperOrientation = CrystalDecisions.[Shared].PaperOrientation.Landscape
ReportName.PrintOptions.PrinterName = "Microsoft XPS Document Writer"
ReportName.PrintToPrinter(PrintDialog1.PrinterSettings.Copies, True, 1, 99)
This would send printing directly to "Microsoft XPS Document Writer". vote if you found this helpful

Delphi TClientDataSet "Trying to modify read-only field" error in SQL Server 2008, OK in 2000

Embarcadero® Delphi® 2010 Version 14.0.3593.25826
We are attempting to move a database from SQL Server 2000 to SQL Server 2008. I have a TClientDataSet that is loaded with a SELECT that includes a computed column, i.e., "SELECT Comp_Col = Column1 + ' ' + Column2...".
Running against an SQL Server 2000 database, I can modify the value of the column in the TClientDataSet using the following code:
ClientDataSet1.Edit();
ClientDataSet1.FieldByName('Comp_Col').ReadOnly := false;
ClientDataSet1.FieldByName('Comp_Col').Value := 'MODIFIED';
ClientDataSet1.FieldByName('Comp_Col'').ReadOnly := true;
ClientDataSet1.Post(); // <-- EXCEPTION in 2008
Running against an SQL Server 2008 database, though, I get a "Trying to modify read-only field" error when executing .Post().
I have tried also setting .ProviderFlags = '[]' for the column (in addition to .ReadOnly = false) in the above code, but still get the error. I have also tried setting .ReadOnly = false and .ProviderFlags = '[]' at design-time via the IDE, but this does not help either.
Anybody know how to set a computed column in a TClientDataSet when running against an SQL Server 2008 database?
Thanks!
* UPDATE: ANSWERED *
I discovered the problem--or at least a workaround...
I WAS setting .ReadOnly = false for the column in the TClientDataSet object. This worked with SQL Server 2000 but not with SQL Server 2008.
If I set .ReadOnly = false in for the column instead in the TADOQuery object that is serving as the provider, then I am able to set the value of the computed column in the TClientDataSet object at run-time.
Not ideal for me since this was implemented in a generic function for TClientDataSet objects (that didn't anything about the provider), but it will have to do for now.
I discovered the problem--or at least a workaround . . .
I WAS setting .ReadOnly = false for the column in the TClientDataSet object. This worked with SQL Server 2000 but not with SQL Server 2008.
If I set .ReadOnly = false for the column instead in the TADOQuery object that is serving as the provider, then I am able to set the value of the computed column in the TClientDataSet object at run-time.
Not ideal for me since this was implemented in a generic function for TClientDataSet objects (that didn't anything about the provider), but it will have to do for now.
My experience shows that the creation of ClientDataSet fields by calling TClientDataSet.CreaeteDataSet initially without ReadOnly flags solves the problem. After opening ClientDataSet fields' ReadOnly flags can be returned to their seats for the proper functioning of data-aware controls.

Multiple-step OLE DB operation generated errors [duplicate]

Dim NorthWindOledbConnection As String = "Provider=SQLOLEDB;DataSOurce=SARAN-PC\SQLEXPRESS;Integrated Security=ssp1;InitialCatalog=Sara"
Dim rs As New ADODB.Recordset()
rs.Open("select * from SecUserPassword", NorthWindOledbConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
i tried to run this above code in visual studio 2008 - it shows the following error:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done"
Firstly, don't use ADO in VB.NET. Use ADO.NET.
Other than that, create a proper Connection object instead of passing around a string.
And fix your connection string. It's SSPI, not SSP1. And it's Data Source, not DataSOurce. And it's Initial Catalog, not InitialCatalog.
You are using a very very very old way to access a Database that has been used with Visual Basic 6 and older.
Check to use ADO.NET instead of old ADO. For example you can use this code that is "similar" to the code you are using (but is not the best way to access the data on VS2008)
OleDbConnection con= New OleDbConnection( **Your Connection String** )
con.Open()
Dim command As OleDbCommand = New OleDbCommand("select * from SecUserPassword", con)
sqlCommand .CommandType = CommandType.Text
Dim reader As OleDbDataReader = TheCommand.ExecuteReader()
While reader.Read()
System.Console.Write(reader(** Your Table Field Name** ).ToString())
End While
con.Close()
To view how to create a correct connection String see the site http://www.connectionstrings.com/
If you want to access to an SQL Server database also you can use the SQLClient namespace instead the OleDb. For example System.Data.SqlClient.SqlConnection instead the OleDbConnection to provide better performance for SQL Server
The link below is an article that gives a great breakdown of the 6 scenarios this error message can occur:
Scenario 1 - Error occurs when trying to insert data into a database
Scenario 2 - Error occurs when trying to open an ADO connection
Scenario 3 - Error occurs inserting data into Access, where a fieldname has a space
Scenario 4 - Error occurs inserting data into Access, when using adLockBatchOptimistic
Scenario 5 - Error occurs inserting data into Access, when using Jet.OLEDB.3.51 or ODBC driver (not Jet.OLEDB.4.0)
Scenario 6 - Error occurs when using a Command object and Parameters
http://www.adopenstatic.com/faq/80040e21.asp
Hope it may help others that may be facing the same issue.

Resources