Windows Phone VB "NavigationService is not declared" - visual-studio-2012

Im creating a very simple Windows Phone 8.1 app in Visual Studio Express. I have added a Hyperlink control, then from that I have double click to go to the relevant VB page.
As instructed by the many tutorials out there I have added the code for the button - which should navigate it to the second page I have created.
Private Sub hyperlinkButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
NavigationService.Navigate(New Uri("/SecondPage.xaml", UriKind.Relative))
End Sub
However VB keeps on giving me the error "NavigationService is not declared"
Searching the error message has given me very little joy so far.

In Windows Phone 8.1, code for navigation to another page are declared as,
this.Frame.Navigate(typeof(SecondPage));

You cannot just call the class as you will need to get it from the app (so that the system navigates within the app). This is done by accessing the PhoneApplicationFrame!
It should look something like this:
Private Sub hyperlinkButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Uri uri = New Uri("/SecondPage.xaml", UriKind.Relative);
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(uri)
End Sub

Related

Userform won´t load after "software" update

I made a VBA Project with 2 userforms in a verison of Office 365. But after an recent update (new computer with new installation of Office) the userforms cant be loaded. I have not been able to spot the diffrence between the Excel versions as all the versionnumbers match eachother.
I thought it was a problem with the datepicker control but error presistes even after that control is removed. I have also verified that Excel is of 32 bit verison on both computers
Option Explicit
Public Sub Menu() <-Shortcut runs this
UserForm2.Show
End Sub
Private Sub UserForm_Initialize() <-Userform2 Initializes
Set UF = New UserForm1 <- Error
Do stuff in UserForm2
End Sub
When the datepicker control was in the UserForm1 the error recived was:
Could not read some objects since they are´nt availible on this computer
Followed by
Complie error in hidden modul UserForm1.
Error usally shows when the code is incomapitble
with the app version, platform or architecture.
These are the reference for the Project:
VBA
Excel 16 Obj. Lib.
OLE Automation
Office 16 Obj. Lib.
Forms 2 Obj. Lib.
Common Controls-2 6.0 (SP6)
My knowledges limt has been reached as I thought that this is was 64 bit issue. If I remove the datepicker control from UserForm1 it only shows the second error.
If you google for it you will find e.g. this:
Download the MSCOMCTL.ocx in Microsoft Download.
On search menu / Cortana search command prompt and run it as administrator by right clicking it.
Copy the MSCOMCTL.ocx file to C:\Windows\SysWOW64.
Navigate the command prompt to the location C:\Windows\SysWOW64 and type regsvr32 mscomctl.ocx.
Do regsvr32 both mscomctl.ocx and mscomct2.ocx

Display PDF in Excel VBA UserForm

I am running Excel 2016, which may be relevant if the below is a compatibility issue...
In short, I am trying to display a PDF, embedded in a UserForm in Excel.
I have a UserForm, say UserForm1.
I have enabled the following extra references:
Microsoft Visual Basic for Applications Extensibility 5.3
Adobe Acrobat Browser Control Type Library 1.0
This allows me to add the Adobe PDF Reader as an "Additional Control"
The control appears as a hatched box icon (bottom left), which I'm not sure it's meant to. Then if I try to add one of these objects to UserForm1 (both programmatically and in design view) it gives me an error
Element not found
For reference, the relevant lines of VBA I was using were:
Dim PDFviewer As AcroPDF
Set PDFviewer = PDForm.Frame1.Controls.Add("AcroPDF.PDF.1")
Which I took from this Adobe forums thread: https://forums.adobe.com/thread/1065554
Resources online suggest it might be that the AcroPDF control is no longer supported. If so, is there another way to achieve what I want?
As an alternative to using the AcroPDF, try using the WebBrowser Object.
It requires including the additional control
Microsoft Web Browser
Add a WeBrowser on the UserForm named WebBrowser1
Private Sub UserForm_Click()
Me.WebBrowser1.Navigate "about:blank"
Me.WebBrowser1.Document.write "<HTML><Body><embed src=""C:\temp\SO_Answers\test.pdf"" width=""100%"" height=""100%"" /></Body></HTML>"
End Sub
You can just .Navigate to the PDF directly, but, to quote my comment:
"It's safer to use the html part, depending on the machine settings, sometimes direct navigation will initiate download instead of display."

Reportviewer not visible

I am using Visual Studio 2013 Professional and vb.net. When I start a new Windows Form and drag ReportViewer to the blank form, it does not appear on the form. At the bottom, it shows ReportViewer1; however, there is no reportviewer visible. This means I can't attach the viewer to a report or database.
If I start an entirely new project, I can drag the reportVierwer. This is a big project or I would just start a new one and do it.
For some reason (on VS2015) the ReportViewer instance is not added to the Controls collection of the form inside the InitializeComponents method.
Adding this line (reportViewer being the instance of ReportViewer) fixes the problem:
this.Controls.Add(reportViewer);
You can always add it in code behind manually, or to manually edit the designer.
Add the Load event handler to the form to refresh the report viewer on Load:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ReportViewer1.RefreshReport()
End Sub
And in designer create the ReportViewer instance. In InitializeComponent:
Private Sub InitializeComponent()
Me.ReportViewer1 = New Microsoft.Reporting.WinForms.ReportViewer()
'...
'
'ReportViewer1
'
Me.ReportViewer1.Location = New System.Drawing.Point(13, 13)
Me.ReportViewer1.Name = "ReportViewer1"
Me.ReportViewer1.Size = New System.Drawing.Size(396, 246)
Me.ReportViewer1.TabIndex = 0
'...
End Sub
Friend WithEvents ReportViewer1 As Microsoft.Reporting.WinForms.ReportViewer
It's not ideal solution. When adding to your main code you are mixing presentation and logic. When modifying designer code there is a risk it will be overridden.
Perhaps some improvement would be to create yet another Form partial class where you put the above mentioned code. For instance, as LoadReportViewer method and then invoke the method from your code. This way you do not mingle designer code with logic and you don't risk the change is removed by designer.

Getting Xpath when clicking on element in a Visual Basic webbrowser control

I am trying to write a visual basic application to retrieve xpaths from html pages. What I would like to do is have a page load in the web browser, click on any given element on the web page, and have the xpath of that element stored in a variable.
I have been searching the web for 2 days but can not find anything. How can this be done?
I have a basic understanding of VB. I'm just not sure what the code for the onclick event would be.
Use OnBeforeNavigate event and return the URL property
In Access VBA:
Assuming your WebBrowser object is called WebBrowser6
Private Sub WebBrowser6_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
MsgBox (URL)
End Sub

Making a program auto login to twitch.tv

So im trying to make a program with multiple buttons. Basically each button will relate to one account on twitch(.)tv . I help doing this. I understand the button needs to 1. navigate to twitch(.)tv/login . 2. then it needs to get the elementbyID of the login id for that text box. Can someone please help with this error I am getting? http://prntscr.com/3aqhwq
Could someone also make sure that I have the right ID for that login blank on twitch(.)tv/login . I need to be able to make it to automatically input a email into the email text box of that webpage and then the password then to click to submit button, Like invokemember. http://prntscr.com/3aqieh
The problem with with your code is You place navigate and get element-id in on same button
loading page takes some time but your code is not waiting for that time .
place navigate url to other button or wait till browser load complete
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("login_user_login").SetAttribute("Value", "123#gmail.com")
End Sub

Resources