0

My VB program is more or less a data entry application. I have ten fields on a third party web page that I want to fill using a String placed on the clipboard. I get a TitleNumber (TNtext) from the ClipBoard. I get a preFix, usrName and imageCount from a VB screen. The logic adds standard values for two other fields and date/time for four fields. I want to string this all together and put it on ClipBoard.Text so that the user can then go to the first of ten fields, hit Ctl-v and have all ten fields filled in.

I tried using vbTab to tab from one field to the next, but when I pasted the long string into the field, everything was output into that one field.

 partOne = fullTNtext + vbTab + "Family History Library" + vbTab + usrName + vbTab + "MS"
 partTwo = vbTab + dateTime + vbTab + vbTab + dateTime + vbTab + vbTab + imageChr
 partTree = vbTab + usrName + vbTab + dateTime + vbTab + vbTab + dateTime
 clipText = partOne + partTwo + partTree
 Clipboard.SetText(clipText)

This is the code I've tried so far. I pasted the string into a Word page (with special-characters turned on) and everything was there, including tab characters. But it seems that the tab characters get converted to spaces when pasting into a webpage field.

BTW: my VB program is on a client PC, not the web server...

JerrMerr
  • 11
  • 4
  • Can you show us what the DOM of the webpage looks like by right-clicking on the input, inspecting element, copying relevant code? Grabbing the HTMLElement and setting the value will be more reliable than trying to rely on copy/pasting values. – David Aug 06 '21 at 16:35
  • If you are doing this passing by a normal browser you cannot populate all fields with your Copy and Paste. The only way is that you make your own `WebBrowser` using `WebBrowser` Control then load the page and work on the DOM by individuating elements by id or name. – G3nt_M3caj Aug 06 '21 at 16:48
  • @JerrMerr - If you are not using the WebBrowser control, what are you using? Also, so that I can get notifications, could you tag me when you response? Just do the @ sign followed by my name. – David Aug 06 '21 at 20:24
  • @David I had never heard of the WebBrowser control. The web page was operating in Google Chrome (but would work with other browsers). My VB program was using a Windows form. IF build and pasting a string from the ClipBoard it would have been a simple task. I have researched the WebBrowser control and using it could probably solve the problem. But it is probably too difficult and time consuming for this project. – JerrMerr Aug 07 '21 at 00:19
  • You literally drag the WebBrowser control on a form and navigate to the URL. Not sure how this would be too difficult. – David Aug 07 '21 at 01:42
  • @David - WebBrowser has so many attributes and methods...is there any book or manual that explains how to use them? #1 how can you look at a page before displaying it? #2 if you want to change values on input fields before displaying the page, how do you do that? #3 is there anything special you have to do after updating a page to display it? – JerrMerr Aug 09 '21 at 22:43
  • MSDN should be your go to location: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser the best way to address this would be to get the element by it's ID (or some other attribute) and then set the innerHTML (or value, checked, etc.) – David Aug 09 '21 at 22:50
  • @G3ni_M3caj Here are a couple of the fields that I want to update: Scan Operator: Scan Machine #: – JerrMerr Aug 11 '21 at 15:34
  • @David Please review the comment above. – JerrMerr Aug 11 '21 at 15:35
  • Use `WebBrowser.Document.GetElementById` to get the inputs by their id, then use the `SetAttribute("value", -my value here-)` method on the HtmlElement returned by `GetElementById`. – David Aug 11 '21 at 15:40

1 Answers1

0

According to your comments, it looks like you're willing to use a WebBrowser control. Also, it looks like the HTML of the input's you're wanting to modify is:

<tr>
  <td>Scan Operator:</td>
  <td>
    <input id="scanOperator" name="scanOperator" type="text" value=""/>
  </td>
</tr>
<tr>
  <td>Scan Machine #:</td>
  <td>
    <input id="scan_machine" name="scanMachineId" type="text" value=""/>
  </td>
</tr>

What you can do is:

  1. Get the Document from the WebBrowser (documentation)
  2. Use the GetElementById method to get the HtmlElement by its respective id (documentation)
  3. Use the SetAttribute method of the HtmlElement to set the value (documentation)

Assuming that the name of your WebBrowser control is WebBrowser1, then here is an example:

Dim input = WebBrowser1.Document.GetElementById("scanOperator")
If (input IsNot Nothing) Then
    input.SetAttribute("value", "my scan operator value here")
End If

input = WebBrowser1.Document.GetElementById("scan_machine")
If (input IsNot Nothing) Then
    input.SetAttribute("value", "my scan machine value here")
End If
David
  • 5,877
  • 3
  • 23
  • 40
  • Thank you. That is exactly what I needed. One more question. I am working with four different web pages. I go forward thru the first two and cycle between that last two. How can my VB program tell which one of the four web pages is the current one/ – JerrMerr Aug 11 '21 at 16:51
  • You can get the HtmlDocument's URL property, https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.htmldocument.url?view=net-5.0#System_Windows_Forms_HtmlDocument_Url you can check the URL to see which page you're on. – David Aug 11 '21 at 16:56
  • About 10 minutes after I posted the question, I realized that that was probably the answer. With all your help and a couple video from https://sonarlearning.co.uk/coursepage.php?course=ext-csharp&videoindex=1993#1993 I should be able to finish the project. Thank you. – JerrMerr Aug 11 '21 at 17:24
  • No problem! I’m glad you got it squared away. – David Aug 11 '21 at 17:34
  • I got the code working on regular "input" fields. But on this field, there is no "value" attribute. All I want to insert is a String like "map_PD-TN-12345_no02". Scanning Site Notes: – JerrMerr Aug 16 '21 at 15:30
  • `textarea`s are a bit different in that you’ll want to set the HtmlElement’s `InnerHtml`. https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.htmlelement.innerhtml?view=net-5.0 – David Aug 16 '21 at 16:38
  • Got everything working. Cut 35 seconds of data entry down to 3 seconds! Everyone is excited... – JerrMerr Aug 21 '21 at 19:31