Excel VBA PCOMM only getting numbers and not text

Vallsta94

New Member
Joined
Jul 19, 2022
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Hello there,
Im trying to get text from PCOMM but only getting the numbers.
Have try so many things, and cant find a solution. Hope you can help me out.
The text looks like this in PCOMM GB0006
And Artikel1 should get GB and Artikel2 should get 0006.
Then when i but them together in cell B2 its should be GB0006.
But what i get is only 6.


The code looks like this:

Dim Artikel1 As Long
Dim Artikel2 As String

On Error Resume Next
autECLOIA.waitforinputready
Artikel1 = CDbl(autECLPSObj.GetText(7, 26, 2))
autECLOIA.waitforinputready
Artikel2 = CDbl(autECLPSObj.GetText(7, 33, 4))
autECLOIA.waitforinputready

Artikel = Artikel1 & Artikel2
Range(B2).Value = Artikel

Thank you for helping me out!
Best Regards, Vallsta
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to MrExcel!
I'm also an AS400 user and have some experience handling PCOMM related to Excel.
Since Artikel1 should get GB, it must be declared as String. Seems Artikel2 gets 0006. It's converted as a numeric when you put it in a cell. But as long as GB is placed before it, it will be GB0006 as intended. Anyway, I think that it works just by changing the declaration.

VBA Code:
Dim Artikel1 As String

Additionally, I recommend removing "On Error Resume Next". So, it gives an error when Artikel1 gets a string "GB" because the variable is declared as Long. You might have noticed what I said before you asked here.
 
Upvote 0
Ah forgot to say, I guess that "CDbl" function is also not necessary. Because those are taken as a String.

VBA Code:
    Dim Artikel1 As String
    Dim Artikel2 As String

    'On Error Resume Next
    autECLOIA.waitforinputready
    Artikel1 = autECLPSObj.GetText(7, 26, 2)
    autECLOIA.waitforinputready
    Artikel2 = autECLPSObj.GetText(7, 33, 4)
    autECLOIA.waitforinputready

    Artikel = Artikel1 & Artikel2
    Range(B2).Value = Artikel
 
Last edited:
Upvote 0
Ah forgot to say, I guess that "CDbl" function is also not necessary. Because those are taken as a String.

VBA Code:
    Dim Artikel1 As String
    Dim Artikel2 As String

    'On Error Resume Next
    autECLOIA.waitforinputready
    Artikel1 = autECLPSObj.GetText(7, 26, 2)
    autECLOIA.waitforinputready
    Artikel2 = autECLPSObj.GetText(7, 33, 4)
    autECLOIA.waitforinputready

    Artikel = Artikel1 & Artikel2
    Range(B2).Value = Artikel
Works perfect! Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top