VBA Reflection capture

Faksebugt

New Member
Joined
Aug 23, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi
Using VBA via Reflection as interface I need to read reply from Host and paste it into Excel. I can send commands, but cannot capture the reply.
Ex.
----------
Dim Reply as String * 100

Session.Transmit "Alarms" & vbCrLf
Reply = .ReadChars (100, 1)
--------------
Even though several lines are printed om the screen, the Reply1 is empty or contains the the first character of the command "A"

Anyone knows how the read the reply - help would be much appreciated?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Add. info
In Win.10 and previous Office versions the command ".ReadChars()" worked. But aftger upgrading to WIn.11 and Office 365, it does not work any longer.
 
Upvote 0
Do you still have access to the older version where it works?
If so, take a look in VB and see which VBA Libraries are selected (from VBA, go to the Tools menu, select References, and see which libraries are checked).
Now, repeat that process in your new version, and verify all the same libraries are checked. If any are missing, find and select them from the list (they may have the same name, but a newer version number).
 
Upvote 0
@ Joe4
Yes - I have the old program - just not a Win.10 machine any more to test it on.
The communication using Reflection is working - all is ticked off at References. It is only the read command that does not work. Most of the times I do get one character into the Reply, and some times 5-10 characters. But it is not the first or last in answer - it is some random places from the reply.
I cannot use SendKey or ReadKey, as they are very sensitive to which window is in focus, but if any other program is better - I'm all ears.
 
Upvote 0
I have not used "Reflection", so I don't think I have much else to offer.
I just know that many times when it works on one version of Excel, but not a newer one, it is often people there are missing VBA libraries.

Good luck, I hope you figure it out!
 
Upvote 0
One other question - is your code in the new version EXACTLY like it was in the old version?
If not, please post your code for each. The small snippet of code you posted does not look correct/complete.
You usually do NOT start a command with a period (.) unless you are within a WITH block.
 
Upvote 0
Thanks for assisting :)
Sorry for the incomplete code-snap. Yes, I use a With block. The code is exactly as in the old version, which worked.
The code is lines, so that's why I only shoved the the command that not behave as it used to do. But here is a full example:
Sub LogTemp()
On Error GoTo ErrorHandler

Const NEVER_TIME_OUT = 0

Dim Temp As String * 2000
Dim Col As String
Dim colletter As String
Dim j As Integer
Static no As Long
Dim nextTime As Date

Sheets("TempPlot").Unprotect
Sheets("TempPlot").Activate

Session.Transmit CR
Session.WaitForString "# ", "10", rcAllowKeystrokes
Session.Transmit "sensors" & CR
Temp = Session.ReadChars(1900, 1)
Session.Transmit CR
Session.WaitForString "# ", "10", rcAllowKeystrokes

If i = 2 Then
colletter = "JKLMNOPQ"
Else
colletter = "RSTUVWXY"
End If
For j = 50 To 1900
Select Case Mid$(Temp, j, 4)
Case "Zynq"
Col = Mid$(colletter, 1, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 27, 4)
Case "Bott"
Col = Mid$(colletter, 2, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 26, 4)
Case "Fron"
Col = Mid$(colletter, 3, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 25, 4)
Case "Top "
Col = Mid$(colletter, 4, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 23, 4)
Case "Back"
Col = Mid$(colletter, 5, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 24, 4)
Case "Cent"
Col = Mid$(colletter, 6, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 26, 4)
Case "re 1"
Col = Mid$(colletter, 7, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 8, 4)
Case "re 2"
Col = Mid$(colletter, 8, 1)
Range("Stability!" & Col & Row).value = Mid$(Temp, j + 8, 4)
End Select
Next j

Range("Stability!Z1").value = Row + 1
Session.SelectText 1, 1, 0, 0

Exit Sub

ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly

End Sub
 
Upvote 0
OK, just wanted to rule out any obvious errors.

To be honest, I have been on this board over 20 years, and this is the first time I recall saying any question regarding "Relection", so I did a little research on it, and came across this:

Done know if that helps or not.
 
Upvote 0
Thanks Joe4. Not really - is is too old. Maybe I should make a new request here on a more general topic regarding MS Office VBA and Telnet.
 
Upvote 0
Thanks Joe4. Not really - is is too old. Maybe I should make a new request here on a more general topic regarding MS Office VBA and Telnet.
Only post a new question if you are going to post a new question (just don't post the same question again in a new thread).

Just note that this may be a tough topic to get help on. I don't think many people on this forum have experience with it.
 
Upvote 0

Forum statistics

Threads
1,223,708
Messages
6,174,006
Members
452,542
Latest member
Bricklin

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