PCOMM gettext is pulling invisible information - vb.net

I've had a randomly recurring issue where I can use gettext to pull information just fine from a page on a PCOMM (IBM Personal Communicator) screen, then when I go to the next screen it will pull that SAME information, despite appearing visually blank.
I can't paste screenshots for InfoSec reasons... But here's the gist:
Dim ps As New AutPS
Dim oia As New AutOIA
Page 1: ps.GetText(15,31,7) = 1800.00 (I can see this value on the screen.)
Go to next page, wait for oia.InputInhibited = 0 And ps.Ready
Page 2: ps.GetText(15,31,7) = 1800.00 (Screen in this position appears blank.)
This issue is not isolated, and is repeatable with a specific account number.

Found a solution!
The key lies with using the ps.autECLFieldList. This object can detect when a given field (located using FindFieldByRowCol) is displayed or not, so when used in tandem with our getText, we can make sure that we're only retrieving information from a visible field.
Dim fl As Object = ps.autECLFieldList
fl.refresh() 'Good practice to make sure the Field List is up to date
If fl.FindFieldByRowCol(15, 31).display Then
Amount = ps.GetText(15, 31, 7)
End If

Related

Return the line to its original position after making a Requery

I apologize for my English is a Google translation.
This is a question that I have had a hard time with for a long time and in all the places that have been talked about it remains unanswered, so I am publishing my solution for the benefit of all.
Sometimes you are required to refresh the source of the form (in continuous form) and then you use let's say a bookmark to return to the record you were before the refresh, the problem is that if we say the form now shows you records 40-60 and you stand on record 45, when you return to 45 after refresh it is not The fifth will be displayed on the screen but it will be the first, which may cause confusion for the user, I have always looked for a way to return the same record that will be the fifth on the screen and the user will not see any change.
I found that it is possible to use the "CurrentSectionTop" property, it means where you are located in relation to the top edge of the form, you need to lower the height of the header from it.
Below is the code:
Const MaxRecordInViwe = 50
Const ValuePerLine = 564
MySelTop = Me.SelTop
CurrentRowInViwe = (Me.CurrentSectionTop - Me.FormHeader.Height) / ValuePerLine
Me.Requery
Me.SelTop = (MySelTop - MyCurrentRowInViwe) + MaxRecordInViwe
Me.SelTop = MySelTop - MyCurrentRowInViwe
Me.SelTop = MySelTop
If your screen has more than 50 entries, you will change the default "MaxRecordInViwe", if you enter less you can leave it unchanged.
The constant "ValuePerLine" fits my form, I did not find a formula to calculate it but you can find it manually:
Go to the first record
In the Immediate window, type the following code:
?Form_table1.CurrentSectionTop - Form_Table1.FormHeader.Height
In the form, go to the second entry
In the Immediate window, type the following code:
?(Form_table1.CurrentSectionTop- Form_Table1.FormHeader.Height)- {The previous result})
Enter the result to set "ValuePerLine"

How to identify which monitor a winform is displayed on, in a multi monitor setup?

I have found a lot of answers researching this, but non address my question.
Assume that user has 2 monitors, say a laptop screen with 1600×1200 res, and external monitor of 2560×1440 res. Regardless how the 2 displays are set up, if a client moves the main-form of the program to the external monitor, I would like it to report that its on 2560×1440 res. When the main-form is moved on to the laptop it should report the 1600x1200.
Is this possible? I know how to report the res, I just do not know how to identify which monitor the main-form is sitting on.
You need to first identify what you mean by the form being on a screen, because it's possible for a single form to span multiple screens. You're going to be using the Screen class regardless, but the calculations will be different. The simplest option would be to use the Location property, e.g.
For Each scrn In Screen.AllScreens
If scrn.Bounds.Contains(Location) Then
MessageBox.Show($"Resolution: {scrn.Bounds.Width} x {scrn.Bounds.Height}")
Exit For
End If
Next
Another option would be to use the screen that contains the largest proportion of the form, e.g.
Dim maxArea = 0
Dim resolution = Size.Empty
For Each scrn In Screen.AllScreens
Dim intersection = Rectangle.Intersect(scrn.Bounds, Bounds)
Dim area = intersection.Width * intersection.Height
If area > maxArea Then
maxArea = area
resolution = scrn.Bounds.Size
End If
Next
MessageBox.Show($"Resolution: {resolution.Width} x {resolution.Height}")
Note that this code will display the resolution of the first encountered if the equal parts of the form are on multiple screens.
There may be other options too, although these seem the most likely.
EDIT:
It's also worth noting that the first code won't work for a maximised form because the actual Location value will be outside the bounds of the screen it's on, so you'd need a bit of jiggery-pokery to handle that. The second code will handle that without issue.

WebBrowser.DocumentText Not Updating

I am loading a web page into webbrowser control and after waiting for the document to load, I am reading in the .documenttext to retrieve various bits of data.
I then want to test if the data on the web page has changed (it's a dynamic update) and if so, I retrieve the updated data.
The problem is that .document.text is not updating, either after a dynamic update to the page or if I physically navigate within the browser control to another page.
When I loop through all elements using '.getelementsbytagname' I get the up to date web page data, but obviously want to avoid this if the data hasn't changed. So '.document' updates but '.documenttext' doesn't.
So the '.documenttext' doesn't get updated when the web page changes. Is there a way to force this update? Or a better/simpler way to check for a page update?
.refresh() does work, but I don't want to be reloading the document when it's already up to date.
Dim pp = Uni.wbUni.DocumentText
If pp = GlobalVariables.unistr Then
Console.WriteLine("no change" & Now())
Exit Sub
End If
Console.WriteLine("change" & Now())
GlobalVariables.unistr = Uni.wbUni.DocumentText
So from the above pp never actually updates
Dim pp = Uni.wbUni.Document.Body.InnerText

How to select dropdown lists with no id

I've been researching this for the last couple days but haven't found a solution yet. Any help would be greatly appreciated.
I'm using VBA to put a push button on an Excel spreadsheet which will open an Internet Explorer window, log people into a particular site, search for a particular "case" (webform) on the site, fill in the values the way the user specified on the sheet, and then submit the form. Everything works except the form fields that are drop down lists. When I run it, it fills in the values I want in those fields but it seems like it's not actually selecting them from the list, just overwriting what's displayed there, because when it clicks submit an error window pops up saying to fill in those drop down fields.
From my research I've seen various solutions for how to search a drop down list and set it to the selected index once it's located the text I want, but my problem is that I haven't had luck selecting the drop down list at all. If you look at the screenshot below, that shows one of the fields as it looks in Internet Explorer's dev tools:
The highlighted portion is the id number I use to paste in my text (what I'm doing right now that isn't working) but the line below it with class ns-dropdown seems like it might be what I really want to access, but that line doesn't have an id.
Here's the relevant portion of my code:
Dim IE As Object
Dim IEForm As HTMLDocument
Set IEForm = IE.Document
With IEForm
.getElementById("custevent_crc_code_fs").innerText = Sheet1.Cells(9, 3) 'CRC Code
.getElementById("inpt_status4").innerText = Sheet1.Cells(8, 3) 'Status
.getElementById("inpt_custevent95").innerText = Sheet1.Cells(11, 3) 'Department
.getElementById("inpt_custevent426").innerText = Sheet1.Cells(10, 3) 'Case Origin
.getElementById("inpt_custevent447").innerText = Sheet1.Cells(6, 3) 'Created By
.getElementById("inpt_custevent1188").innerText = Sheet1.Cells(7, 3) 'Contact Reason
.getElementById("btn_multibutton_submitter").Click
End With
Let me know if you need any more information. I've been wrestling with this for a while and am trying not to flood you with too much extraneous info about things I've tried.

Programmatically set margins in report viewer control

In onw of our application, we have some reports that need very specific margins that are dependant of the printer the user have. It is used to print into preformatted paper with blanks to fill and depending of the printer, the printing is off by some margins. To make things worse, we don't actually control what printer is used because it is not an internal application.
The only solution I could think of is to let the user configure the margins somehow. I thought I could just dynamically change the report margins like I did with datasources and actual report (I have one control that is used to display every reports from my application and it works alright), but I can't seem to find that damn property to do so. There is a margin property on the report viewer but it's for the form display so it doesn't cut it.
Does anyone knows how to. What I was thinking to do is to define the margins before the user loads the report, i.e. when he clicks on the report button, I load the report, set the margins (or vice-versa is necessary) and then display it.
Before someone mention it, I know the user can, once the report is loaded, change the page setup to fit his needs, but this has two drawbacks. First one is that it is not saved each time and I need it to be 'saveable' and by users. The second one is that Report viewer seems to have some bugs when the regional setting aren't set to what it's expecting and we can't force the users to changes their setting to accommodate one application.
Edit: Forgot to mention, it this is of any uses. My reports are all local reports.
'creates a new page setting
Dim instance As New PageSettings()
'create the new margin values (left,right,top,bottom)
Dim value As New Margins(0, 0, 0, 0)
'gives your new pagesetting a value
instance.Margins = value
'report viewer now sets your margins
ReportViewer1.SetPageSettings(instance)
You can't do this directly. Try controlling your margins in the report with report parameters.
Well, I just had this similar problem; needed a report to have 0" margins, otherwise the blasted thing went from 2 pages to 6, and it split the data vertically, so the pages made no sense. I was having to set it manually in the Print Setup to print, but the end goal of this report is to be emailed to customers as a PDF, and guess what, when I set the margins manually and exported, it still split into 6 pages and bombed out. So risking everything, I tried one last supreme effort to fix this blasted thing - I opened up the .rdlc with word pad, and miracle of miracles, found 1in, etc. I set all those buggers to 0in, saved, ran my .net code (2008), opened up Print Setup, and hallelujah, there was my 0in settings. Now for the supreme test - I exported it as a PDF, went to the file, and son of a gun! Sweet. There were two crisp clean perfectly laid out pages. All was beneficent in the universe, I calmed down and let the midiclorians flow through me, and just basked in a moment so rare that it is rarely realized by some - a simple fix.
Check out the ReportPageSettings class, part of the report viewer control. Setting those values looks like it should get you what you need.
More settings;
Dim myPageSettings As New PageSettings()
myPageSettings.Margins = New Margins(0, 0, 0 , 0)
Dim paperSize As PaperSize = New PaperSize()
'ToDo: update with the PaperKind
'that your printer uses
paperSize.RawKind = PaperKind.A4
' paperSize.RawKind = System.Drawing.Printing.PaperKind.A4
myPageSettings.PaperSize = paperSize
'False for "Portrait"
'True for "Landscape"
myPageSettings.Landscape = False
'report viewer now sets your margins
ReportViewer1.SetPageSettings(myPageSettings)
this code work with me, the numbers in mm
Dim newPageSettings As New System.Drawing.Printing.PageSettings
newPageSettings.Margins = New System.Drawing.Printing.Margins(50, 100, 45, 45)
ReportViewer1.SetPageSettings(newPageSettings)
im using vb.net 2013