Error 91 while declaring connection string vb6 ADODC - vb6

What I am doing wrong?
Public Function getRecords(query As String) As Adodc
With Adodc1
.RecordSource = query
.Refresh
End With
getRecords = Adodc1
End Function
Getting an error in line getRecords = Adodc1 where it shows nothing or Error 91.
The Code is written in a form consisting Adodc1 Control for ADODC object.

Got Solution by Rob :
set getRecords = Adodc1

Related

VB6 Subscript Out fo Range - but this is an odd one because a mirror function is working fine

Thanks for reading.
I have built a VB6 DLL (VB_InterFace just for a name) that talks to a C# DLL (C#_Driver just for a name) that talks to a Bluetooth Device.
The Demo VB6 test app (VB_Demo just for a name) I created as stage one works fine, does what it is supposed to. It calls the VB_Interface and Opens and Closes the BTDevice. Additional functions also work fine.
However on placing the operational code from VB_Interface into another DLL that is the live operations DLL, Open works fine, but Close is throwing an error. "Variable not defined" when returning from the C#_Driver.
I just can't see why, the code is the same, the process is only marginally different. By this I mean ;
In the VB_Demo I have two buttons "Open" "Close" and when I click on these I get the feedback that I expect from the BTDevice.
Private Sub btnOpenPort_Click()
'MsgBox steps(0)
ReDim steps(5)
Dim rc As HF4000_ResultCodes
'rc = driver.OpenSerial(cmbPorts.Text)
If driver.OpenSerial(cmbPorts.Text) = True Then
Private Sub btnClosePort_Click()
Dim rc As HF4000_ResultCodes
If driver.CloseSerial("COM4") = True Then
However in the live DLL it just executes the same functions internally without being initiated by a button click.
' See IScanDevice documentation.
' #see IScanDevice#OpenDevice
Private Function IScanDevice_OpenDevice() As Scanning.Scan_ResultCodes
(truncated slightly)
50 If driver.OpenSerial("COM4") = True Then
rc = READY
MsgBox "Connected to the device successfully."
' See IScanDevice documentation.
' #see IScanDevice#CloseDevice
Private Function IScanDevice_CloseDevice() As Scanning.Scan_ResultCodes
(truncated slightly)
50 If driver.CloseSerial("COM4") = True Then
60 rc = READY
70 IScanDevice_CloseDevice = Scan_Success
clsDriver.cls
Public Event OnStateChanged(newState As String)
Public Event OnDataUpdated()
Dim WithEvents CSharpInteropServiceEvents As CSharpInteropService.LibraryInvoke
Dim load As New LibraryInvoke
Private Sub Class_Initialize()
Set CSharpInteropServiceEvents = load
End Sub
Private Sub CSharpInteropServiceEvents_MessageEvent(ByVal newState As String)
If newState = "OpenForm1" Then
' FormDummy2.Show ' Not required
End If
If State <> newState Then
State = newState
RaiseEvent OnStateChanged(State)
GetDriverData
End If
End Sub
Private Function BluetoothTestInvoke(load, functionName, param)
BluetoothTestInvoke = load.GenericInvoke("BluetoothTest.dll", "BluetoothTest.Class1", functionName, param)
End Function
Function OpenSerial(portNumber) ' "COM4"
Dim param(0) As Variant
Dim retorno As Variant
param(0) = portNumber
retorno = BluetoothTestInvoke(load, "OpenSerial", param)
OpenSerial = retorno(0) <<<<<<< Works fine returns TRUE
End Function
Function CloseSerial(portNumber) ' "COM4"
Dim param(0) As Variant
Dim retorno As Variant
param(0) = portNumber
retorno = BluetoothTestInvoke(load, "CloseSerial", param)
CloseSerial = retorno(0) <<<<<<<<< "Error Subscript Out of Range"
End Function
What I have discovered is this - and I guess this is the reason why the Close is not working. The question is why is this situation occurring ...
When driver.OpenSerial executes, it hits > Function OpenSerial
Within Function OpenSerial it executes BluetoothTestInvoke where "load" is "CSharpInteropService.LibraryInvoke"
From there it moves to - Sub CSharpInteropServiceEvents_MessageEvent
.. and everything is fine.
However when I then execute driver.CloseSerial after that, it hits > Function CloseSerial
Within Function OpenSerial it executes BluetoothTestInvoke where "load" is "CSharpInteropService.LibraryInvoke"
Now here it "should" move to - Sub CSharpInteropServiceEvents_MessageEvent
However No, it just drops to the next line which is CloseSerial = retorno(0)
and this is where I get the "Subscript out of range" error for retorno(0)
For some reason in the CloseSerial it is not invoking "load"
BluetoothTestInvoke(load, "CloseSerial", param)
Thoughts and suggestions much appreciated.
UPDATE
Quite right, one should never assume anything.
On the tips I started digging deeper into the C# Library. It turns out the "param" value that is the Bluetooth port is passed into the CloseSerial call, and from there is is passed around within the external C# library dll. At one stage it is reset so the port number that should be handled is lost, thus it doesn't close but specifically the "expected" data was not returned to the calling app.
param(0) = portNumber
retorno = BluetoothTestInvoke(load, "CloseSerial", param) << param was being reset in the external library.

ASP Len() function returns Type Mismatch error

Below is my server side asp code of my classic ASP application:
Function isValidPACSSession()
...
Dim sessionID : sessionID = Request.QueryString("forSessionID")
isValidPACSSession = SessionID2PACSUserID(sessionID)
...
End Function
Function SessionID2PACSUserID(sSessionID)
if (Not IsNull(sSessionID) AND Len(sSessionID) > 0) then
...it fails here at the Len function.
else
...
end if
End Function
Len() function throws "Type Mismatch" error for this partcular instance, wheras other calls made to SessionID2PACSUserID() by other components are just fine. Please help.
looks like you're just trying to check if a value is present, why not do something like:
dim sessionLength : sessionLength = 0
if (Not IsNull(sSessionID) AND sSessionID <> "") then
sessionLength = Len( sSessionID )
I also agree with the above statement of the VS debugger not working very well with classic asp
found a solution.. Actually i had a local variable by the name "len" on the calle web page which was causing the len() to fail. Changed len variable name to nLength and Len() now works fine.

VB.net anonymous type has incorrect property casing from AJAX call

We have noticed that sometimes from the results of an AJAX call to a controller action that the case of the JSON result is incorrect. The returned case will actually change if we rebuild our solution and try the exact same call. In the following case, the key's case has been correct for over a year until now when it has decided to start randomly changing depending on some seemingly random circumstances.
As you can see in the picture above, the key for the JSON result is lowercase "success". However when I view the results in Chrome's console, it is an uppercase "Success". This is causing our JavaScript to fail since it is checking for the lowercase version.
What is causing this? And more importantly, how do we stop this?
vb.net is case-insensitive as opposed to C# which is case-sensitive. This means that the compiler will generate only one class (from the first instance) for each of the following anonymous types:
Dim a = New With {.success = True} 'Compiler generate a class based on this type
Dim b = New With {.Success = True} 'Same type as `a`
Dim c = New With {.sUcCeSs = True} 'Same type as `a`
Debug.WriteLine(a.GetType().Name)
Debug.WriteLine(b.GetType().Name)
Debug.WriteLine(c.GetType().Name)
VB$AnonymousType_0'1
VB$AnonymousType_0'1
VB$AnonymousType_0'1
Here's how the complied code looks like when compiled back to vb.net:
<DebuggerDisplay("success={success}"), CompilerGenerated> _
Friend NotInheritable Class VB$AnonymousType_0(Of T0)
' Methods
<DebuggerNonUserCode> _
Public Sub New(ByVal success As T0)
Me.$success = success
End Sub
<DebuggerNonUserCode> _
Public Overrides Function ToString() As String
Dim builder As New StringBuilder
builder.Append("{ ")
builder.AppendFormat("{0} = {1} ", "success", Me.$success)
builder.Append("}")
Return builder.ToString
End Function
Public Property success As T0
<DebuggerNonUserCode> _
Get
Return Me.$success
End Get
<DebuggerNonUserCode> _
Set(ByVal Value As T0)
Me.$success = Value
End Set
End Property
Private $success As T0
End Class

Advise on this . My code has some blocker.i am getting the error 'object required'

I am using the functions below.In the first one i have parsed the node of xml and its value using MSXML. similar func fr other xml.i want to use two nodevalues and highlight it.i tried something.but i am getting error in the line highlighted(**) as 'Object Required'.your quick reply will help me more.
Public Sub DisplayNode1(ByRef Nodes1 As MSXML2.IXMLDOMNodeList, _
ByVal Indent1 As Integer)
some lines
RichTextBox2.Text = Space$(Indent) & xNode1.ParentNode.nodeName & _
":" & xNode1.NodeValue
difference
some lines
Public Sub difference()
Dim a As IXMLDOMText
Dim b As IXMLDOMText
a.NodeValue = xNode.innertext 'i get erroe in line
b.NodeValue = xNode1.innertext
If StrComp(a, b) > 0 Then
a = vbRed
b = vbRed
End If
please help me soon.
There is a lot that is potentially wrong with this.
xnode isn't declared anywhere in your code sample
Neither a, b, or xnode are explicitly set anywhere in your code sample
Unless xnode is a form/module/global level variable then it will be out of scope in the Difference procedure
It's not shown but I'm guessing that you don't have Option Explicit set in your code or by default
You'll need to address these points first before you can get anywhere with this code.

SQL server reporting Validate parameter is in correct format

On my reporting application which is developed using SSRS 2005, I have a parameter of type string which accepts time. the time should be in the format "HH:mm:ss" How can I check if the input string is of correct format?
I tried to do the following
IsDate(TimeValue(parametr!stime.Value))
This returns true as long as the value is within range. But if the value is 24:00:00 or a wrong value then an exception is thrown.
I also tried to create a function in the report code as follows:
Public Function CheckNum(sNum as String) as Boolean
Dim msg as String
msg = ""
Try
If IsDate(TimeValue(sNum))=1 Then
Return True
Else
msg="Parameter must be a number"
End If
Catch ex as Exception
Return False
End Try
If msg <> "" Then
MsgBox(msg, 16, "Parameter Validation Error")
Err.Raise(6,Report) 'Raise an overflow
End If
End Function
And when I input a value 24:00:00 I still get an error
" The conversion of a char type to datetime data type resulted in an out of range date time value"
How can I handle the exception so that I don't the error?
EDIT:
public Function CheckNum(sNum as String) as Boolean
Dim REGEX_TIME = "^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$"
If System.Text.RegularExpressions.Regex.IsMatch(sNum, REGEX_TIME) Then
Return True
Else
Return False
End If
End Function
Then I assigned a parameter(validateTime) value as =Code.CheckNum(Parameters!sTime.Value)
But the value of the parameter is always true. When I specify a value greater than 23, I still see the error. Please see the image
Instead of using IsDate function, use VB.NET regular expressions. SSRS allows full use of .NET functions.
See an example of time regex.
A good tutorial on regex.
Example Code Console Application
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim REGEX_TIME = "^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$"
Dim InputList As List(Of String) = New List(Of String)
InputList.Add("25:00:21")
InputList.Add("22:00:21")
InputList.Add("AA:00:21")
InputList.Add("17:21:02")
For Each input As String In InputList
If Regex.IsMatch(input, REGEX_TIME) Then
Console.WriteLine("TIME " + input + " IS OK")
Else
Console.WriteLine("TIME " + input + " IS NOT OK")
End If
Next
End Sub
End Module
Output is :
TIME 25:00:21 IS NOT OK
TIME 22:00:21 IS OK
TIME AA:00:21 IS NOT OK
TIME 17:21:02 IS OK
I think, you can capture a InvalidCastException.

Resources