How do I implement a yes/no into a text box in VB.net? - textbox

I am looking for when a button is pressed the user is asked yes or no if they want the button to continue it's function if yes it will, if no it will close the text box and nothing will happen.
Here is my current code (reset button for text fields):
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtDistanceInp.Clear()
txtOwnerInp.Clear()
txtRegInp.Clear()
txtSpeedLimitInp.Clear()
txtTimeInp.Clear()
txtTimeInp2.Clear()
End Sub
Any help offered is useful, thanks.

You can use following approach:
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim result As MessageBoxResult = MessageBox.Show("Do you want to continue?", "test", MessageBoxButton.YesNo)
If result = MessageBoxResult.Yes Then
MessageBox.Show("Go Ahead")
Else
MessageBox.Show("Dont go")
End If
End Sub

Related

How to Programmatically add or remove items in ListBox FORM control

I am having a problem with OpenOffice.org ListBox Form control.
I have built a small form (not dialog) that contains a textbox and ListBox and 2 buttons.
Sub AddToList_ButtonClicked()
Dim oThisDoc As Object
Dim oForms as Object
Dim oForm as Object
oThisDoc = thisComponent.getDrawPage()
oForms = oThisDoc.getForms()
oForm = oForms.getByName("SimpleForm")
Dim oTextBox As Object
Dim oListBox As Object
oListBox = oForm.getByName("simpleListBox")
oTextBox = oForm.getByName("simpleTextBox").Text
oListBox.stringitemlist() = Array("One", "Two", "Three") '<--- Only possible way to add items to the ListBox Form Control :(
End Sub
Sub RemoveFromList_ButtonClicked()
Dim oThisDoc As Object
Dim oForms as Object
Dim oForm as Object
oThisDoc = thisComponent.getDrawPage()
oForms = oThisDoc.getForms()
oForm = oForms.getByName("SimpleForm")
Dim oListBox As Object
oListBox = oForm.getByName("simpleListBox")
oListBox.stringitemlist() '<--- contains array of items
oListBox.SelectedItems '<--- contains items selected for removal
End Sub
I would totally appreciate any solution for this problem!.
Is this what you are looking for?
' Add items.
oListBox.StringItemList() = Array("One", "Two", "Three")
oListBox.insertItemText(oListBox.ItemCount, "Four") ' This works even if oListBox starts out empty.
oListBox.insertItemText(oListBox.ItemCount, "Five")
' Remove the last item in the list.
oListBox.removeItem(oListBox.ItemCount - 1)
XrayTool shows that oListBox implements XItemList.
The form I used to test this code was in Writer, without any connection to Base.

Add menu item to Quickbooks

Is it possible to add a menu item to Quickbooks using the QBSDK?
I have found a couple of old examples that I can't make work.
I have created a custom application for my company and am trying to simplify it by making a menu item in Quickbooks.
Any help would be greatly appreciated.
Here is what I have tried so far, but I get an error message at the subAdd.SubscriberID.SetValue(Me.appGUID.ToString).
The error is: * Invalid GUID format. Must use zero for Custom Fields, or a GUID generated with GuidGen.exe for private data extensions.*
{
Dim subRq As ISubscriptionMsgSetRequest
subRq = MySessionManager.CreateSubscriptionMsgSetRequest(4, 0)
' Add a UIExtension subscription to our request
Dim subAdd As IUIExtensionSubscriptionAdd
subAdd = subRq.AppendUIExtensionSubscriptionAddRq
'
' set up the subscription request with the required information, we're adding to
' the file menu in this case, and just for fun, we're making it a cascading menu
subAdd.SubscriberID.SetValue(Me.appGUID.ToString) "<-----error happens here
subAdd.COMCallbackInfo.AppName.SetValue(Me.appName)
subAdd.COMCallbackInfo.ORProgCLSID.ProgID.SetValue("MenuEventContext.QBMenuListener")
subAdd.MenuExtensionSubscription.AddToMenu.SetValue("atmFile")
'
' For the cascade fun, we're just going to add items to the cascade menu...
Dim subMenu As IMenuItem
For i = 1 To 5
subMenu = subAdd.MenuExtensionSubscription.ORMenuSubmenu.Submenu.MenuItemList.Append
'
' this is the text that the user will see in QuickBooks:
subMenu.MenuText.SetValue("Sub Item " & i)
'
' this is the tag we'll get in our event handler to know which menu item was
' selected:
subMenu.EventTag.SetValue("SubMenu" & i)
Next i
'
' Send the request and get the response, since we're sending only one request there
' will be only one response in the response list
Dim subRs As ISubscriptionMsgSetResponse
subRs = MySessionManager.DoSubscriptionRequests(subRq)
Dim resp As IResponse
'
' Check the response and display an appropriate message to the user.
resp = subRs.ResponseList.GetAt(0)
If (resp.StatusCode = 0) Then
MsgBox("Successfully added to QuickBooks File menu, restart QuickBooks to see results")
Else
MsgBox("Could not add to QuickBooks menu: " & resp.StatusMessage)
End If
MySessionManager.CloseConnection()
MySessionManager = Nothing
Exit Sub
handleError:
MsgBox("Encountered error subscribing: " & Err.Description)
If Not MySessionManager Is Nothing Then
MySessionManager.CloseConnection()
End If
End Sub
The answer is yes.
The only purpose of UIExtensionSubscription is to add menu items to the top menus. Clicking the menus will then start your app, if it isn't already running, and pass it information about the current focused Quickbooks window.
Your application must be com accessible and registered.
As for your sample make sure you are passing { } around your GUID. I don't use function call unsure if you might need to cast to a string first or not.
There is a sample console app in C# in the current QBPOSSDK download from Intuit. I would thoroughly read the programmers guide and look at that sample.
One of my working requests, pretty close to the intuit sample:
Private Shared Function GetUIExtensionSubscriptionAddXML(ByVal strMenuName As String, ByVal strMainMenuName As String) As String
'strMainMenuName would be "Company" for example
'Create the qbXML request
Dim requestXMLDoc As New XmlDocument()
requestXMLDoc.AppendChild(requestXMLDoc.CreateXmlDeclaration("1.0", Nothing, Nothing))
requestXMLDoc.AppendChild(requestXMLDoc.CreateProcessingInstruction("qbxml", "version=""5.0"""))
Dim qbXML As XmlElement = requestXMLDoc.CreateElement("QBXML")
requestXMLDoc.AppendChild(qbXML)
'subscription Message request
Dim qbXMLMsgsRq As XmlElement = requestXMLDoc.CreateElement("QBXMLSubscriptionMsgsRq")
qbXML.AppendChild(qbXMLMsgsRq)
'UI Extension Subscription ADD request
Dim uiExtSubscriptionAddRq As XmlElement = requestXMLDoc.CreateElement("UIExtensionSubscriptionAddRq")
qbXMLMsgsRq.AppendChild(uiExtSubscriptionAddRq)
'UI Extension Subscription ADD
Dim uiExtEventSubscriptionAdd As XmlElement = requestXMLDoc.CreateElement("UIExtensionSubscriptionAdd")
uiExtSubscriptionAddRq.AppendChild(uiExtEventSubscriptionAdd)
'Add Subscription ID
uiExtEventSubscriptionAdd.AppendChild(requestXMLDoc.CreateElement("SubscriberID")).InnerText = MySubscriberGUID
'Add COM CallbackInfo
Dim comCallbackInfo As XmlElement = requestXMLDoc.CreateElement("COMCallbackInfo")
uiExtEventSubscriptionAdd.AppendChild(comCallbackInfo)
'Appname and CLSID
comCallbackInfo.AppendChild(requestXMLDoc.CreateElement("AppName")).InnerText = App_Name
comCallbackInfo.AppendChild(requestXMLDoc.CreateElement("CLSID")).InnerText = MyCLSID
' MenuEventSubscription
Dim menuExtensionSubscription As XmlElement = requestXMLDoc.CreateElement("MenuExtensionSubscription")
uiExtEventSubscriptionAdd.AppendChild(menuExtensionSubscription)
'Add To menu
menuExtensionSubscription.AppendChild(requestXMLDoc.CreateElement("AddToMenu")).InnerText = strMainMenuName
Dim menuItem As XmlElement = requestXMLDoc.CreateElement("MenuItem")
menuExtensionSubscription.AppendChild(menuItem)
'Add Menu Name
menuItem.AppendChild(requestXMLDoc.CreateElement("MenuText")).InnerText = strMenuName
menuItem.AppendChild(requestXMLDoc.CreateElement("EventTag")).InnerText = "menu_" & strMenuName.Replace(" ", "_")
Dim displayCondition As XmlElement = requestXMLDoc.CreateElement("DisplayCondition")
menuItem.AppendChild(displayCondition)
displayCondition.AppendChild(requestXMLDoc.CreateElement("VisibleIf")).InnerText = "InventoryEnabled"
displayCondition.AppendChild(requestXMLDoc.CreateElement("EnabledIf")).InnerText = "InventoryEnabled"
Dim strRetString As String = requestXMLDoc.OuterXml
WriteLocalLog("GetUIExtensionSubscriptionAddXML: " & strRetString)
Return strRetString
End Function

Implementing Try, Catch on Syndication Feed (RSS) Type

I want to create a try catch so that if the feed does not exist or cannot be created for some reason, it will return false or null so that I can then test the variable and create a default item.
Function GetFeed(url As String) As SyndicationFeed
Dim feed = New SyndicationFeed
Try
Dim reader = XmlReader.Create(url)
feed = SyndicationFeed.Load(reader)
Catch ex As Exception
feed = Nothing
End Try
Return feed
End Function
It says I can't set type "SyndicationFeed" to boolean.
The error is with this code:
Dim feedUrl = "http://rss.news.yahoo.com/rss/entertainment"
Dim feed As SyndicationFeed = GetFeed(feedUrl)
If feed = Nothing Then
End If
It says, "operator '=' is not defined for type SyndicationFeed."
In VB.Net you need to use the is operator to compare objects
So change your condition to:
If feed Is Nothing Then
End If
I am no VB expert but you need to use "Is" rather than "=". In other words, replace "If feed = Nothing Then" with "If feed Is Nothing Then".

Creating a List (of String) giving error" Object reference not set to an instance of an object. "

MVC 3 razor VB.NET project. I have resorted to manual building a list for a drop down box so I can insure certain values are available in the select list and also to control what the first item is in the list. The below is my code snippet for the part that is giving me problems..
Dim _courses1 As Integer = db.courses.ToList.Where(Function(r) r.course_day = "Tuesday").Count
Dim _classes1 As List(Of cours) = db.courses.ToList
Dim classRef1 As List(Of String)
If Not _selectedClass0 = "--" Then
classRef1.Add("--")
Else
classRef1.Add(_selectedClass0)
End If
For i As Integer = 0 To _courses1 - 1
For Each item In _classes1.Where(Function(f) f.course_day = "Tuesday")
Dim _item As cours = item
classRef1.Add(_item.course_ref)
Next
Next
ViewBag.tue1 = classRef1
The _selectedClass0 is just a string that gets set earlier... The error mentioned happens when it gets to the ClassRef1.Add(_selectedClass0) part of the else statement. Which _selectedClass0 string value at the time of error is "--". I have a feeling it is in how the list is being created but I am not certain... Any ideas???
You're not initializing classRef1.
Dim classRef1 As new List(Of String)
Another thing I see is in the first line - I've made the changes I see:
Dim _courses1 As Integer = db.courses.Where(Function(r) r.course_day = "Tuesday").Count()
You don't need ToList at the beginning if all your getting is the count.
You are declaring classRef1 to be a list of strings here:
Dim classRef1 As List(Of String)
But you're never actually creating an instance using New. I'm not sure about the VB syntax, as I'm a C# developer, but I'd guess you should add the following line right after the declaration:
classRef1 = New List(Of String)

Why does the DefaultModelBinder not bind to Char properties with value of " "c

I have a class like
Public Class Task
Property DuplexType As Char
Property Name As String
End Class
In my controller I have an action that looks like
<HttpPost()>
Function Edit(ByVal task As Task) As ActionResult
Dim duplexType = task.DuplexType
Dim valid = ModelState.IsValid
Return RedirectToAction("Index")
End Function
In the view, DuplexType = " " (single space) and Name = "Foo". Why doesn't the property DuplexType have a value? If I assign any other character it works fine.
In the controller name = "foo" but DuplexType = " (empty).
Also ModelState.IsValid = false if DuplexType = " ".
Have a look at the Response object and examine the values being populated by the form Post. You will probably see that values are trimmed and therefore lose the space. If possible try to UrlEncode the values.
Where I have had to preserve trailing spaces in my own projects, I have ended up having to put delimiters on the parameter and then strip them off in the action method.

Resources