Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetString Pulls Back Symbols Instead of AlphaNum Chars

Status
Not open for further replies.

cgraeter

Programmer
Sep 27, 2006
21
US
Hi all,

I have created an automation in Excel that interacts with Attachmate and I'm able to send text and commands without issues. However, when I use the GetString method to pull text from the screen, it's coming back as a series of unintelligible symbols. Does anyone know why this would be happening and how I can get it to pull back as it reads on the screen?

Thanks in advance!

Chris
 
this is how i get info from attachmate back to excel


Code:
a1 = Sess0.Screen.GetString(16, 1, 14) 'this is the attachmate field

           
Worksheets(1).Range("A1").Value = a1 'this is where i put the data in excel

hth
 
Thanks for responding, vzachin. This is exactly how I'm pulling data from the Attachmate screen as well, but for some reason, it doesn't pull back what I see on the screen. For instance, I can send the string "123" into Attachmate, but when I scrape that same string into a variable, it comes back as "ñòó". Any ideas?
 
i've never seen this problem before. what happens if you scraped protected fields from Attachmate?
 
On the plus side, you're getting three consecutive characters, you're just not getting "123". Let me know what values you get in the message boxes when you do something like this.

Code:
On Error Resume Next
putText = "123"
Sess0.Screen.PutString putText,1,1
getText = Sess0.Screen.GetString(1,1,3)
For i = 1 to Len(getText)
   sChar = Mid(getText,i,1)
   iAsc = Asc(sChar)
   MsgBox sChar & " : " & iAsc
   MsgBox Chr(iAsc-160) & " : " & (iAsc - 160)
Next
 
Skie,

After using your coding, the mystery deepens. I found that when I use PutString, it seems to place the "123" string into the emulator window, but it's not visible. I know it's there though, because the subsequent GetString pulls it back as "123". Weird!

I normally use SendKeys to place strings into the Attachmate window. When I do this, I can see the "123", but GetString pulls it back as "ñòó". The message boxes produced the following:
ñ:241 Q:81
ò:242 R:82
ó:243 S:83

vzachin,

I get symbols whether pulling from protected or non-protected fields. Doesn't seem to make a difference.

Any ideas after knowing this?
 
For some reason I thought it was pulling upper case of those. Change this:
MsgBox Chr(iAsc-160) & " : " & (iAsc - 160)
to this:
MsgBox Chr(iAsc-192) & " : " & (iAsc - 192)
and see if it returns this:
1:49
2:50
3:51

If that works correctly, then try inputting alpha characters and see if it returns the correct ones in the message box. If so, when it pulls from your session the font might be weird and the ASCII characters just aren't matching up.

You could do make a function for it.
Code:
Function FixMyStr(myStr)
    For i = 1 to length(myStr)
        myChar = Mid(myStr,i,1)
        myAsc = Asc(myChar)-192
        myFixedStr = myFixedStr & Chr(myAsc)
    Next
    FixMyStr = myFixedStr
End Function

Or if you want it shorter:
Code:
Function FixMyStr(myStr)
    For i = 1 to length(myStr)
        myFixedStr = myFixedStr & Chr(Asc(Mid(myStr,i,1))-192)
    Next
    FixMyStr = myFixedStr
End Function

If your alphas are returning correctly or the -192 doesn't return the correct value then we could probably modify the function for that too.
 
This worked well for the "123" example, but it doesn't appear to do the trick for other strings I've tested. If I try the string "cats", I get an invalid procedure call on the following line:

myFixedStr = myFixedStr & Chr(myAsc)

The value of myAsc at that point is -61, which I'm guessing is what's causing the issue. Any other thoughts?
 
Yeah, that'd be the problem. Maybe your alphas are correct and your numerics are only what's off. Try this.
Code:
Function FixMyStr(myStr)
    For i = 1 to length(myStr)
        myChar = Mid(myStr,i,1)
        myAsc = Asc(myChar)-192
        If myAsc > 0 Then
            myFixedStr = myFixedStr & Chr(myAsc)
        Else
            myFixedStr = myFixedStr & myChar
        End If
    Next
    FixMyStr = myFixedStr
End Function
 
It looks like the numeric characters I'm scraping are consistently 192 positions away from their real ascii representations. Unfortunately, alpha characters and symbols are all over the board. I created a loop that pulls back the ascii value of what I get when I scrape a particular character from my screen. Here is what I got:


Char Ascii WhatIGet
==== ===== ========
Space 32 64
! 33 90
" 34 127
# 35 123
$ 36 91
% 37 108
& 38 80
' 39 125
( 40 77
) 41 93
* 42 92
+ 43 78
, 44 107
- 45 96
. 46 75
/ 47 97
0 48 240
1 49 241
2 50 242
3 51 243
4 52 244
5 53 245
6 54 246
7 55 247
8 56 248
9 57 249
: 58 122
; 59 94
< 60 76
= 61 126
> 62 110
? 63 111
@ 64 124
A 65 193
B 66 194
C 67 195
D 68 196
E 69 197
F 70 198
G 71 199
H 72 200
I 73 201
J 74 209
K 75 210
L 76 211
M 77 212
N 78 213
O 79 214
P 80 215
Q 81 216
R 82 217
S 83 226
T 84 227
U 85 228
V 86 229
W 87 230
X 88 231
Y 89 232
Z 90 233
[ 91 186
\ 92 224
] 93 187
^ 94 176
_ 95 109
` 96 121
a 97 129
b 98 130
c 99 131
d 100 132
e 101 133
f 102 134
g 103 135
h 104 136
i 105 137
j 106 145
k 107 146
l 108 147
m 109 148
n 110 149
o 111 150
p 112 151
q 113 152
r 114 153
s 115 162
t 116 163
u 117 164
v 118 165
w 119 166
x 120 167
y 121 168
z 122 169
{ 123 192
| 124 79
} 125 208
~ 126 161

I could certainly create a method that uses this info to translate the character to what they should be, but it's going to be really messy. Any other thoughts after seeing this or does anyone know what might be causing this in the first place?
 
This is a pretty good chunk of code. I wonder if the font Attachmate is using isn't matching up with Excel or something. You could try setting the Excel font to the same font and see what happens.
Code:
Function FixMyStr(myStr)
For i = 1 to length(myStr)
myChar = Mid(myStr,i,1)
myAsc = Asc(myChar)
Select Case True
Case myAsc = 64
    myFixedStr = myFixedStr & " "
Case myAsc = 75
    myFixedStr = myFixedStr & "-"
Case myAsc = 76
    myFixedStr = myFixedStr & "<"
Case myAsc = 77
    myFixedStr = myFixedStr & "("
Case myAsc = 78
    myFixedStr = myFixedStr & "+"
Case myAsc = 79
    myFixedStr = myFixedStr & "|"
Case myAsc = 80
    myFixedStr = myFixedStr & "&"
Case myAsc = 90
    myFixedStr = myFixedStr & "!"
Case myAsc = 91
    myFixedStr = myFixedStr & "$"
Case myAsc = 92
    myFixedStr = myFixedStr & "*"
Case myAsc = 93
    myFixedStr = myFixedStr & ")"
Case myAsc = 94
    myFixedStr = myFixedStr & ";"
Case myAsc = 97
    myFixedStr = myFixedStr & "/"
Case myAsc = 107
    myFixedStr = myFixedStr & ","
Case myAsc = 108
    myFixedStr = myFixedStr & "%"
Case myAsc = 109
    myFixedStr = myFixedStr & "_"
Case myAsc = 110
    myFixedStr = myFixedStr & "110"
Case myAsc = 111
    myFixedStr = myFixedStr & "?"
Case myAsc = 121
    myFixedStr = myFixedStr & "'"
Case myAsc = 122
    myFixedStr = myFixedStr & ":"
Case myAsc = 123
    myFixedStr = myFixedStr & "#"
Case myAsc = 124
    myFixedStr = myFixedStr & "@"
Case myAsc = 125
    myFixedStr = myFixedStr & "'"
Case myAsc = 126
    myFixedStr = myFixedStr & "="
Case myAsc = 127
    myFixedStr = myFixedStr & Chr(34)
Case myAsc > 128 and myAsc < 138
    myFixedStr = myFixedStr & Chr(myAsc-32)
Case myAsc > 144 and myAsc < 154
    myFixedStr = myFixedStr & Chr(myAsc-39)
Case myAsc = 161
    myFixedStr = myFixedStr & "~"
Case myAsc > 161 and myAsc < 170
    myFixedStr = myFixedStr & Chr(myAsc-47)
Case myAsc = 176
    myFixedStr = myFixedStr & "^"
Case myAsc = 186
    myFixedStr = myFixedStr & "["
Case myAsc = 187
    myFixedStr = myFixedStr & "]"
Case myAsc = 192
    myFixedStr = myFixedStr & "{"
Case myAsc > 192 and myAsc < 201
    myFixedStr = myFixedStr & Chr(myAsc-128)
Case myAsc = 208
    myFixedStr = myFixedStr & "}"
Case myAsc > 209 and myAsc < 218
    myFixedStr = myFixedStr & Chr(myAsc-135)
Case myAsc = 224
    myFixedStr = myFixedStr & "\"
Case myAsc > 225 and myAsc < 234
    myFixedStr = myFixedStr & Chr(myAsc-143)
Case myAsc > 239 and myAsc < 250
    myFixedStr = myFixedStr - Chr(myAsc-192)
End Select
FixMyStr = myFixedStr
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top