×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

_ComObject to type Integer

_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

CODE

Dim ClaimLines as Integer
ClaimLines = Sess0.Screen.Area(21, 8, 21, 9).Value
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:

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
----------------------------------------

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: _ComObject to type Integer

(OP)
Skip, I understand that....but can you provide an answer as to why in VBA this works fine but then in VB as a standalone app it screws up.  The only thing i can think of is that in Excel VBA it doesnt care that your setting a variable you dimmed as an Integer to a text value (and then will let you perform calculations with it), unless there is somthing different about the way excel handles grabbing the data

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 ClaimLines as Integer
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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: _ComObject to type Integer

(OP)
skip,

"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

ClaimLines =val(ClaimLinesString)
is correct and will work.....why does it seems like you like pointing out my 'oh so obvious' errors instead of actually answering my questions
 

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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

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

    Select Case arySpecs(TP, i)
        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
I actually have a table of data that defines the fields on each of my IMS screens.  But this shows how I routinely test for numeric values.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: _ComObject to type Integer

(OP)
thanks for the tips skip

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)

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close