Variable not define - vb6

Hi i need help on this error that i am getting on my code. variable not define and after i define the variable it throws another errors says Method or data member not found and it always highlights the DataEnvironment1.commands. am using a calendar to access my reports. what is likely to be the problem please any help.
Here is my code:
Private Sub cmdOK_Click()
On Error GoTo e
frmDate = txtdate1.Text
endDate = txtdate2.Text
DataEnvironment1.Commands("InpatientMaintenanceMaster").Parameters(0) = txtdate1
DataEnvironment1.Commands("InpatientMaintenanceMaster").Parameters(1) = txtdate2
With RptInpatientMaster
.Sections("Section2").Controls("lblDate1").Caption = txtdate1.Text
.Sections("Section2").Controls("lblDate2").Caption = txtdate2.Text
.Show
End With
DataEnvironment1.rsInpatientMaintenanceMaster.Close
Unload Me
Exit Sub
e:
If Err.Number <> 3704 Then
MsgBox Err.Description, vbCritical
End If
End Sub

Please remove this line:
DataEnvironment1.Commands("InpatientMaintenanceMaster").Parameters(0) = txtdate1
And instead replace it with this, and then tell us which line is shown as your error:
Dim dataEnv As Object
Set dataEnv = DataEnvironment1
Dim cmd As Object
Set cmd = dataEnv.Commands("InpatientMaintenanceMaster")
Dim dateString As String
dateString = txtdate1.Text 'assuming this is truly a textbox control?
cmd.Parameters(0) = dateString 'should really be using frmDate instead
By splitting this out, it should narrow down exactly what you are missing.

Related

To convert string to double in UFT/QTP

I am trying to convert string to double in UFT but It shows the output without decimal point. below is the code for reference.
vStr = "1000000.589765"
msgbox Typename(vStr)
strV1=CDBL(formatNumber(vStr,4))
msgbox Typename(strV1)
print strV1
Output: 1000000589765
Note that without formatNumber, its not working.
Yet another implementation using DotNetFactory. Just an another thought. I am not denying to use CDbl. But worth to give a shot.
'Test Code
Dim strConvertedCode
strConvertedCode = ConvertDataType("1000000.589765","Double")
If strConvertedCode <> null Then
Msgbox strConvertedCode
End If
Public Function ConvertDataType(ByVal SourceData,ByVal ConversionDataType)
'Initialization of variables
Dim objDotNetFactory
Dim strConvertedData : strConvertedData = null
Dim strSystemNamespace
'Determine the destination data type
Select Case UCase(ConversionDataType)
Case "DOUBLE"
strSystemNamespace = "System.Double"
'Implement further for your data types
'Reference https://msdn.microsoft.com/en-us/library/ms228360(v=vs.90).aspx
Case Default
Set objDotNetFactory = DotNetFactory.CreateInstance("System.Int32")
End Select
Set objDotNetFactory = DotNetFactory.CreateInstance(strSystemNamespace)
'Check the dot net factory instance is successful
If Not IsObject(objDotNetFactory) Then
Reporter.ReportEvent micWarning,"Data type convertor","Conversion from String to " & ConversionDataType & " failed, Since DotNetFactory instance was not created."
ConvertDataType = strConvertedData
Exit Function
End If
strConvertedData = objDotNetFactory.Parse(SourceData)
ConvertDataType = strConvertedData
End Function

Microsoft VBScript runtime error

I have written my code in VBScript.I'm getting error in a particular part of my code shown below.
[ActiveX Script Task] Error: User script threw an exception: Error Code: 0
Error Source= Microsoft VBScript runtime error
Error Description: Object required: 'REGroupSBUOps'
Error on Line 85
'Declaring and connection string statements
strREGroupSBUOps ="sp_CPVarianceOpsReport6"
Set REGroupSBUOps = oDBCon.Execute(strREGroupSBUOps)
Dim arr()
ReDim arr(6)
Dim i
arr(0) = "REGroupSBUOps"
arr(1) = "DandBSBUOps"
arr(2) = "Tristate/Central/EastSBUOps"
arr(3) = "WestSBUOps"
arr(4) = "EastSBUOps"
arr(5) = "UKSBUOps"
If Not (arr(i).EOF) Then ' <--error on this line
'followed by other statements
Put the code inside your For loop into a sub, along with the actual execution of the stored procedures. Pass the stored procedure calls and the names from your array as a parameters to the sub. Replace all occurrences of arr(i) with the name of the variable that takes the records returned by the stored procedure call (rs in my example below).
Sub ExportData(sp, name)
Set rs = oDBCon.Execute(sp)
If Not rs.EOF Then
sFileName1 = "\\CTSC00579895801\ime\MailReports\" & name & ".xls"
Set oFSOExcelFile = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
...
objExcel.Quit
Set objExcel = Nothing
End If
End Sub
ExportData "sp_CPVarianceOpsReport 1" "Tristate_Central_EastSBUOps"
ExportData "sp_CPVarianceOpsReport 2" "UKSBUOps"
...
As further optimization you may want to create the Excel and FileSystemObject objects as global singletons and just handle the files inside the sub instead of creating and destroying those instances over and over again.

How to fix Wscript.CreateObject returning empty when prefix is specified?

I'm trying to process event handlers for ADODB.Command object. When I specify a prefix, Wscript.CreateObject exits the function without issuing any error message. When the prefix is removed from Wscript.CreateObject, the ADODB.Command object is created.
Additionally when setting On Error Resume Next, Wscript.CreateObject returns and empty object.
Can someone please tell me what I'm doing wrong ?
Code:
DIM tsqlcmd
On Error Goto 0
SET tsqlcmd = WScript.CreateObject("ADODB.Command", "ehdlr_tsqlcmd_")
.....
Private Sub ehdlr_tsqlcmd_ExecuteComplete( RecordsAffected, pError, adStatus, pCommand, pRecordset, pConnection)
' place any code you desire here, for example
If adStatus = STATUS_adStatusOK Then
MsgBox( "tsqlcmd_ExecuteComplete Records affected = " & RecordAffected)
Else
MsgBox( "tsqlcmd_ExecuteComplete ExecuteComplete Status = " & adStatus)
End If
End Sub

Operation is not valid, because of the current state of the object

I have an Infopath 2010 form with a button and the following event code:
Public Sub txtGetCC_Changing(ByVal sender As Object, ByVal e As XmlChangingEventArgs)
' Ensure that the constraint you are enforcing is compatible
' with the default value you set for this XML node.
Dim myNav As XPathNavigator = Me.MainDataSource.CreateNavigator
If myNav.SelectSingleNode("//my:txtGetCC", Me.NamespaceManager).ToString.Length > 0 Then
Dim myIterator As XPathNodeIterator = myNav.Select("/my:myFields/my:group11/my:group12", Me.NamespaceManager)
Dim CCnummer As String = ""
Dim CCsource As DataSource = Me.DataSources("CostCenters")
Dim email As String = ""
While myIterator.MoveNext
CCnummer = myIterator.Current.SelectSingleNode("my:cbRTcc", Me.NamespaceManager).Value
Dim myNavigator As XPathNavigator = Me.DataSources("CostCenters").CreateNavigator
Dim rows As XPathNodeIterator = myNavigator.Select("/dfs:myFields/dfs:dataFields/d:CostCenters", Me.NamespaceManager)
email = ""
While (rows.MoveNext)
Dim ccnumber As String = rows.Current.SelectSingleNode("#CCnumber", Me.NamespaceManager).Value
If ccnumber = CCnummer Then
email = rows.Current.SelectSingleNode("#Email", Me.NamespaceManager).Value
Exit While
End If
End While
myIterator.Current.SelectSingleNode("//my:txtCCowner", Me.NamespaceManager).SetValue(email)
End While
End If
End Sub
The line just before the last END WHILE is not working.
I want to update the column txtCCowner in the repeating table to be updated with the email address found in the external datasource.
Everything works except this line.
The error message I get is: Operation is not valid, because of the current state of the object.
Why do I get this error, what am I doing wrong?
Any help is greatly appreciated.
rg.
Eric

Outlook add a task

I need some help please. I have managed to create a task in outlook using VB and SendItem. My problem is the code I'm using is creating two tasks and not just the one I want.
I have tried removing the .Save as I thought this was the cause but it still adds two tasks. I have added breakpoints to the code to ensure its not cycling round twice for some obscure reason and it just executes once.
Would appreciate someone telling me the obvious please
Code snippet:
`If bNotFount = False Then
Set Ns = Application.GetNamespace("MAPI")
Set ItemT = GetCurrentItem()
Set taskFolder = Ns.GetDefaultFolder(olFolderTasks)
Set olTask = Ns.GetDefaultFolder(olFolderTasks).Items.Add(olTaskItem)
With olTask
.Subject = ItemT.Subject
.Attachments.Add ItemT
.Body = ItemT.Body
.DueDate = Now + 1
.Move taskFolder
.Save
.Display 'show the task to add notes
End With
End If'
You don't need to move it to the default task folder because you saving it there anyway.
Just remove .Move taskFolder line.
I updated your code:
Private Sub Application_ItemSend(Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
Dim ns As Outlook.NameSpace
Dim taskFldr As Outlook.Folder
Dim olTask As Outlook.TaskItem
' If bNotFount = False Then
Ns = Application.GetNamespace("MAPI")
taskFldr = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks)
olTask = taskFldr.Items.Add
With olTask
.Subject = Item.Subject
.Attachments.Add(Item)
.Body = Item.Body
.DueDate = Now + 1
.Save()
.Display() 'show the task to add notes
End With
' End If
End Sub

Resources