I have created a custom control called MultiTextbox. When I place my control onto a form and try to run my project, I get the following errors:
'MultiTextBox' is not a member of 'MultiTextbox.MultiTextbox'.
Type 'MultiTextbox.MultiTextbox' is not defined.
In my Form1.Designer code, I can see the following issues:
Me.MultiTextbox1 = New MultiTextbox.MultiTextbox()
Me.MultiTextbox1.ObjectAlignment = MultiTextbox.MultiTextbox.ObjectPlacement.Left
Me.MultiTextbox1.Style = MultiTextbox.MultiTextbox.TextboxStyle.Normal
Friend WithEvents MultiTextbox1 As MultiTextbox.MultiTextbox
I don't understand why it is duplicating the Control name for a selected few items.
The properties it is referring to are custom properties based from Enums.
For example:
Public Enum ObjectPlacement
Left
Right
End Enum
Private m_ObjectAlignment As ObjectPlacement = ObjectPlacement.Left
'ObjectAlignment
<Browsable(True), Category("Appearance"), _
Description("The text to display as an input group header.")> _
Public Property ObjectAlignment As ObjectPlacement
Get
Return m_ObjectAlignment
End Get
Set(value As ObjectPlacement)
If m_ObjectAlignment = value Then Return
m_ObjectAlignment = value
Me.Invalidate()
End Set
End Property
UPDATE
If I place my custom control on a form and run, everything will work fine without error, but as soon as I modify my control in any way (e.g. Size, Style, etc.) it gives me errors, and I can't even run the application as the compiler just sits in an infinite loop saying 'Building...'. I have to force quit VS.
Okay, after some useful posts on this thread and some googling, I found that by removing the Root Namespace from my project it removed all of my compiler errors that I was getting regarding a duplicated namespace (MultiTextbox.MultiTextbox):
Me.MultiTextbox1 = New MultiTextbox.MultiTextbox()
Me.MultiTextbox1.ObjectAlignment = MultiTextbox.MultiTextbox.ObjectPlacement.Left
Me.MultiTextbox1.Style = MultiTextbox.MultiTextbox.TextboxStyle.Normal
Friend WithEvents MultiTextbox1 As MultiTextbox.MultiTextbox
Secondly, the lockups that I was experiencing when trying to build my project was due to me setting a button's visible state within my paint event causing an infinite refresh loop of my control.
Related
enter code hereI am trying to assign a value to label in a Master Page using vb.net (not my first language-lol). I have followed info from these two references on how to access content from masterpage:
1.[https://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.90).aspx][1]
2.[nullreferenceexception was unhandled by user code in Master Page
I am getting Null Reference Exception on BUT ONLY when I try to call the method I created for it from another class. It works fine when I call it from the same class the method is in. I wrote a method from the starting page/class, WebForm1:
Public Sub PageIdentity(ByVal pageId As String)
' Gets a reference to a Label control inside a ContentPlaceHolder
Dim mpContentPlaceHolder As ContentPlaceHolder
'Dim mpTextBox As TextBox
Dim mpLabel As Label
mpContentPlaceHolder = CType(Master.FindControl("MainContent"), ContentPlaceHolder)*'Null Reference Exception here*
If Not mpContentPlaceHolder Is Nothing Then
mpLabel = CType(mpContentPlaceHolder.FindControl("lblPageIdentifier"), Label)
If Not mpLabel Is Nothing Then
mpLabel.Text = pageId
End If
End If
End Sub
when I call this function from another class in page load like this it throws null ref ex:
Dim oWebForm1 As WebForm1 = New WebForm1()
oWebForm1.PageIdentity("SomeText")
I must be doing something wrong in creating the instance? I tryed writing it as a Public Shared Function first but that created other problems. Can anyone help?
UPDATE: #Joey I replaced the commented line of code below as you suggested and put the sub in the master page code behind, Site1.Master.vb:
'mpContentPlaceHolder = CType(Master.FindControl("MainContent"), ContentPlaceHolder)
mpContentPlaceHolder = CType(Me.FindControl("MainContent"), ContentPlaceHolder)
I also ensured that the page directive on other pages included:
<%# MasterType VirtualPath = "~/Site1.Master" %>
On a test page, I called the sub like so:
Dim _SiteMaster As MasterPage = TryCast(Me.Master, MasterPage)
_SiteMaster.PageIdentity("SomeText")
I am getting blue squiggly line error, message: "PageIdentity is not a member of System.Web.UI.MasterPage"
The Master page inherits like this:
Public Partial Class Site1
Inherits System.Web.UI.MasterPage
The page calling the sub inherits like this
Public Class WebForm1
Inherits System.Web.UI.Page
Since you require the PageIdentity subroutine to be somewhat global you can move it into your master page. The master page can then be called by any page that references it. Use the following code on any page to call the PageIdentity routine:
Dim _SiteMaster As Site1 = TryCast(Me.Master, Site1)
_SiteMaster.PageIdentity("SomeText")
I am new here and really want your help.
I've been trying to disable my webbrowser's cache but I get overload resolution failed because no accessible "Navigate" without a narrowing conversion. I'm stuck and I don't know what to do anymore, I did search all the possible solutions but found no answer.
Here's my code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Const navNoReadFromCache As Long = 4
Const navNoHistory As Long = 2
Const navNoWriteToCache As Long = 8
Dim navflags As Long
navflags = navNoHistory + navNoWriteToCache
WebBrowser1.Navigate("url", 4)
End Sub
End Class
Original Error message is:
Error 2 Overload resolution failed because no accessible 'Navigate' can be called without a narrowing conversion:
'Public Sub Navigate(urlString As String, newWindow As Boolean)': Argument matching parameter 'newWindow' narrows from 'Integer' to 'Boolean'.
'Public Sub Navigate(urlString As String, targetFrameName As String)': Argument matching parameter 'targetFrameName' narrows from 'Integer' to 'String'.
.NET WebBrowserControl doesn't have overload what accept int or long argument.
So, you can't set BrowserNavConstants (this for IWebBrowser2 not .NET WebBrowserControl) value to .NET WebBrowserControl.
I found following page:
http://msdn.microsoft.com/en-us/library/40x214wa%28v=vs.110%29.aspx
The WebBrowser control stores Web pages from recently visited sites in a cache on the local hard disk. Each page can specify an expiration date indicating how long it will remain in the cache. When the control navigates to a page, it saves time by displaying a cached version, if one is available, rather than downloading the page again.
Use the Refresh method to force the WebBrowser control to reload the current page by downloading it, ensuring that the control displays the latest version.
Updated.
I try the code following, that looks like work fine :
private void button1_Click(object sender, EventArgs e) {
webBrowser1.Navigate("http://www.google.co.jp");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
}
This loads page two times.
So after some time of searching and testing different methods I came with a good result.
Shell("RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 8", vbHide)
This is the code I used to delete the cache that held my web browser on a blackscreen.
What it does is search for the Internet Explorer's Temporary files and deletes them, the vbHide has to be kept next to the comma to work, what is does is hide the window that pops us telling you it deletes temp files.
I'm using Smart Client Software Factory 2008. In the module controller, I have code that creates a new child controller only if it hasn't been created, by doing something like the following:
Dim key = "Item-" + item.ID.ToString()
Dim childWorkItem = Me.WorkItem.WorkItems.Get(Of ControlledWorkItem(Of ItemWorkItemController))(key)
If childWorkItem Is Nothing Then
childWorkItem = Me.WorkItem.WorkItems.AddNew(Of ControlledWorkItem(Of ItemWorkItemController))(key)
Else
childWorkItem.Activate()
End If
Multiple items reuse the same key, so when that action is triggered, it shows the tab instead of creating a new instance of it. This works great.
However, there is one drawback. Once activated, I need to run a check within that item's presenter. So I need to call a method on the presenter. Is there a way to invoka a method on the presenter, or is there an event that runs on the view when the work item is activated? I'm not sure how to make that happen?
Thanks.
If you are using a Smart Part as your View you should be able to accomplish this using the IWorkspace.SmartPartActivated event.
This is how I have it setup in my project. I apologize, my code is all in C# but you should be able to apply it in VB relatively easily.
The WorkItemController class has the Activate method setup like this
ISmartPartView _smartPartView
public void Activate()
{
IWorkspace contentWorkspace = this.WorkItem.Workspaces[WorkspaceNames.ShellContentWorkspace];
contentWorkspace.Activate(_smartPartView);
WorkItem.Activate();
}
In the ISmartPartView Presenter class you should be able to create a handler for the SmartPartActivated event like this:
IWorkspace contentWorkspace = this.WorkItem.Workspaces[WorkspaceNames.ShellContentWorkspace];
contentWorkspace.SmartPartActivated += workSpaceSmartPart_ActivatedHandler;
In the workSpaceSmartPart_ActivatedHandler event handler, you can check the SmartPart being activated and if its your ISmartPartView class you can run the desired code.
I am getting the following message when trying to return a new object to VBA from my Visual Foxpro COM server.
"Run-time error '-2147417851 (80010105)':
Method 'ReturnObject' of object 'Itestclass' failed"
If I remove the "Dim ... As" line the error goes away but then I lose intellisense for the COM object.
This is the VBA code:
Sub Test()
'' Removing the following line gets rid of the error but loses intellisense for the COM object
Dim objTest As testcom.TestClass
Set objTest = CreateObject("TestCOM.TestClass")
Set objNew = objTest.ReturnObject '' This is the line that causes the error
End Sub
I have created a link to the TestCOM type library in Tools > References
Here is the Visual Foxpro (VFP) code:
The COM server is being built as an out of process EXE. If I build it as an inprocess .DLL then the VBA code causes Excel to crash.
DEFINE CLASS ObjectToReturn AS SESSION OLEPUBLIC
ENDDEFINE
DEFINE CLASS TestClass AS SESSION OLEPUBLIC
FUNCTION ReturnObject
RETURN CREATEOBJECT("ObjectToReturn")
ENDFUNC
ENDDEFINE
I have tried changing the RETURN CREATEOBJECT("ObjectToReturn") to RETURN CREATEOBJECT("CUSTOM") but the problem persists.
Please advise how I can get rid of this error without losing the intellisense for the COM object in VBA. Thanks
I don't know why you are going through such difficulties... This should be able to help you... You can define your class as OlePublic and set some properties on it like the samples at the top. You can set these properties anywhere through the other functions that are not HIDDEN.
If you need to are trying to get at certain elements OF some other "object", try creating an instance of the object and stick it into a property on the OlePublic class... see my method
DoSomethingElse
which does a simple scatter NAME call to the "SomeObject" property of the class. Even though you are not explicitly returning it, it should be visible from within your creation of it from VB...
DEFINE CLASS VFPClassForVB as Session OLEPublic
cTmpFiles = ""
cCOMUser = ""
SomeObject = ""
FUNCTION Init()
*/ Who is user... always ignore the machine....
This.cCOMUser = SUBSTR( SYS(0), AT( "#", SYS(0)) +1 )
This.cTmpFiles = "somepath\"
*/ Unattended mode... any "MODAL" type dialog will throw error / exception
SYS(2335, 0 )
*/ ALWAYS HAVE EXCLUSIVE OFF FOR COM!!!
SET EXCLUSIVE OFF
*/ ALWAYS HIDE DELETED RECORDS!!!
SET DELETED ON
ENDFUNC
*/ Error handler at the CLASS level will always be invoked
*/ instead of explicit ON ERROR or TRY/CATCH handlers...
FUNCTION xError(nError, cMethod, nLine)
lcMsg = "User: " + SYS(0) + " Tmp:" + SYS(2023);
+ " Method: " + cMethod + " Error: " + STR( nError,5);
+ " Line: " + STR( nLine, 6 )
STRTOFILE( lcMsg, This.cTmpFiles + "COMLog.txt" )
*/ NOW, throw the COM Error...
COMReturnError( cMethod + ' Error:' + str(nError,5);
+ ' Line:' + str(nline,6);
+ ' Msg:' + message(), _VFP.ServerName )
RETURN
HIDDEN FUNCTION SomeOtherFunction( lcWhat String,;
lnThing as Integer ) as String
*/ Do something
RETURN 1
ENDFUNC
*/ Another completely visible function direct form VB
FUNCTION DoSomethingElse( SomeParameter as String ) as String
USE SomeTable
*/ Now, this object should be visible as a direct property in VB
SCATTER MEMO NAME This.SomeObject
ENDFUNC
ENDDEFINE
Your VB side, even from your sample...
Sub Test()
Set objTest = CreateObject("MySampleProject.VFPClassForVB")
objTest.DoSomethingElse( "I dont care" )
dim Something as objTest.SomeObject.ColumnFromTable
End Sub
You can create as many OlePublic classes in your in-code class libraries that you want to expose and just create those instances as needed. Let me know if this helps you get closer and we'll try to keep working it out.
I've tried all sorts of samples, but looking at what you have of the object where both are VFP OleObject entries, each is exposed, and can be created individually. You don't need to create one to create the other.
Is there some reason SPECIFIC you are trying to create one object from another? You can have one object expose a bunch of methods and properties to perform whatever you need from VFP.
If you want to have multiple object classes exposed, and under a central control, you can always create your primary object for communication and have IT create an instance of each "other" class on it. Then, expose methods on your main class to handle the communications between them to act out whatever it is you need.
Sorry, this can be a basic question for advanced VB.NET programmers but I am a beginner in VB.NET so I need your advice.
I have a web application and the login is required for some specific pages. To check if the user is logged in, the old programmer used this technique:
Dim sv As New WL.SessionVariables(Me.Context)
If Not (sv.IsLoggedIn) Then
Response.Redirect(WL.SiteMap.GetLoginURL())
End If
Well, I have to use this Logged In checking in a handler done by me and I tried this:
Public Class CustomHandler
Implements System.Web.IHttpHandler, IReadOnlySessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim sv As New WL.SessionVariables(context)
If Not (sv.IsLoggedIn) Then
context.Response.Write("No access unless you're the CEO!!!" & sv.IsLoggedIn)
ElseIf sv.IsLoggedIn Then
DownloadFile(context)
Else
End If
End Sub
//other code
End Class
Well, the "is logged in" checking is always false (even after I login) and I think it's an issue with the context. So all the other pages works fine with logging checking but this handler have this specific issue.
Can you guys give a helping hand?
UPDATE:
The logged in is done trough this method:
Public Sub SetCreditialCookie(ByVal accountID As Integer)
Me.AccountID = accountID
m_context.Session.Item("loggedInAccount") = accountID
m_context.Response.Cookies.Add(New System.Web.HttpCookie("account_id", CStr(m_context.Session.Item("account_id"))))
m_context.Response.Cookies("account_id").Expires = DateTime.Now.AddDays(5)
End Sub
and to check it it's logged in, this method is called:
Public Function IsLoggedIn() As Boolean
If Not m_context.Session.Item("loggedInAccount") Is Nothing And Me.AccountID = m_context.Session.Item("loggedInAccount") Then
Return True
Else
Return False
End If
End Function
UPDATE 2:
- debugging the code shown that there were multiple kind of logins and I was checking the wrong one with the session.
Due to the use of IReadOnlySessionState, is it possible that the SessionVariables class attempts in some way to modify the Session, which in turn causes an error (possibly handled and not visible to you).
If this is the case it could mean that the IsLoggedIn property is not correctly initialised, or does not function as expected?
Do you have access to the code for the class. If so, try debugging it to see what is happening.