_ComObject to type Integer
_ComObject to type Integer
(OP)
I am using the following code, which works fine in VBA but not in VB...grrrrr
ClaimLines needs to be a number since mathmatical fucntions are performed based off its value or values < or > ClaimLines. I could stand to have it grabbed from extra as another data type as long as i can then convert that in to a true number
Say the number in that area of the screen is 32, well, the Excel VBA macro can get it and have it stored directly to ClaimLines (which is Dim'med as Integer). When I use a VB version of this macro I get the following error:
"Conversion from type '_ComObject' to type 'Integer' is not valid"
The Exception text is below:
I guess what im most confused about is why in Excel VBA it works fine but then in VB I have issues....once again, i can use and work in VBA at work but anything VB has to be done away from a system i can test on...any help would be greatly appreciated
ClaimLines needs to be a number since mathmatical fucntions are performed based off its value or values < or > ClaimLines. I could stand to have it grabbed from extra as another data type as long as i can then convert that in to a true number
CODE
Dim ClaimLines as Integer
ClaimLines = Sess0.Screen.Area(21, 8, 21, 9).Value
ClaimLines = Sess0.Screen.Area(21, 8, 21, 9).Value
"Conversion from type '_ComObject' to type 'Integer' is not valid"
The Exception text is below:
CODE
************** Exception Text **************
System.InvalidCastException: Conversion from type '_ComObject' to type 'Integer' is not valid.
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)
at HCFMacro.HCFMainForm.RunMacrobutton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
HCF Central Macro - for net 2
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/ab94883/Desktop/HCF%20Central%20Macro%20v2.01.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.InvalidCastException: Conversion from type '_ComObject' to type 'Integer' is not valid.
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)
at HCFMacro.HCFMainForm.RunMacrobutton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
HCF Central Macro - for net 2
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/ab94883/Desktop/HCF%20Central%20Macro%20v2.01.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
I guess what im most confused about is why in Excel VBA it works fine but then in VB I have issues....once again, i can use and work in VBA at work but anything VB has to be done away from a system i can test on...any help would be greatly appreciated
RE: _ComObject to type Integer
Hi,
Because ALL the stuff you scrape from a screen is TEXT -- every bit of it.
You must TEST and CONVERT.
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: _ComObject to type Integer
like i said earlier, i cant code in VB and test the VB version til tomorrow but im thinking something along the lines of the following, surely someone has done this in VB before (PLEASE TAKE NOTE THAT THE CODE IN THE FIRST POST WORKS FINE IN VBA AND DOES NOT CAUSE A CONFLICT, ONLY A CONFLICT IS CAUSED IN THE VB STANDALONE VERSION)
CODE
Dim ClaimLinesString as String
ClaimLinesString = Sess0.Screen.Area(21, 8, 21, 9).Value
ClaimLines = Val(ClaimLinesString)
FYI, the number that will end up being assinged to ClaimLines will always be between 1-99 and will always be a whole number
RE: _ComObject to type Integer
It relates to the EDITOR/COMPILER that you're working in.
I would NEVER assume that the editor or compiler will handle my coding sloppiness, although, I'm sure that there ARE some things I overlook. I try not to let those thing occur.
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: _ComObject to type Integer
BTW, it used to be that
1) you would code your program on a code sheet.
2) you would very carefully check your code for proper syntax and logic flow
3) you would punch a program deck and submit at the control desk
4) several hours later, you would get a printout. Either it had nasty error messages or an output, that may or may not be what you were expecting.
So don't complain about what your VB compiler will not do for you.
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: _ComObject to type Integer
"It relates to the EDITOR/COMPILER that you're working in."
Great.....what about them is causing this error
you cant give me a specific reason as to why Excel VBA handles it fine but VB standalone doesnt.....all you do is call me sloppy and tell me how 'old-school' you are
you didnt even bother responding to if the
CODE
RE: _ComObject to type Integer
[code]
If IsNumeric(Trim(Sess0.Screen.Area(21, 8, 21, 9).Value)) then
ClaimLines = CInt(Trim(Sess0.Screen.Area(21, 8, 21, 9).Value))
Else
'whatever you want this condition to do.
End if
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: _ComObject to type Integer
Here's some actual code I use on a regular basis. In this case, since I am writing data to Excel, even if a field defined as CHAR contains numeric data, I prefix it with an APOSTROPHY, to convert it to a STRING.
CODE
Case "CHAR"
If IsNumeric(Trim(Mid(sIn, (iFR + nRow - 1) * 80 + iCol, iLen))) Then
GetField = "'" & Trim(Mid(sIn, (iFR + nRow - 1) * 80 + iCol, iLen))
Else
GetField = Trim(Mid(sIn, (iFR + nRow - 1) * 80 + iCol, iLen))
End If
Case "NUM"
GetField = Trim(Mid(sIn, (iFR + nRow - 1) * 80 + iCol, iLen))
End Select
Skip,
Just traded in my old subtlety...
for a NUANCE!
RE: _ComObject to type Integer
it appears though that it all goes back to a syntax error in my VB code vs my VBA code. Apparently i didnt end the claimLines = statement with .value in the VB version (cant believe i misssed that)
it works fine now with .value and claimLines dimmed as Int but i figured it is best practice to trap the variable first as a string with claimLinesString and then convert to NUM by using claimLines= Val(claimLinesString)