How to add message box in vb? - asp.net

How to add message box using vb?
I get an error below when using MsgBox()

VB doesn't automatically assign a string type so maybe there's the problem...
Try this:
Dim msg$ = "text..."
The above is a short version of:
Dim msg As String = "text..."
If you disable the Option Explicit compile option, then you can just write:
msg$ = "text..."

Related

vb.net Document Generation, Handling Greater Than & Less Than Symbols in Word

We are using TinyMCE editor to store Rich Text in a MS SQL database.
When using "<" & ">" symbols, TinyMCE converts these into the HTML escaped characters &lt ; and &gt ; For Example: <p><This is some test information then sometime I use this></p>
We are trying to export these symbols in a Microsoft Word document using document automation however the symbols do not appear in the document.
Function PreFormatHTML(ByVal html As String) As String
If String.IsNullOrEmpty(html) Then Return html
html = WebUtility.HtmlDecode(html)
Return html
End Function
Dim SumRng As Word.Range = objWordDoc.Bookmarks.Item("bSummary").Range
SumRng.Text = PreFormatHTML(GeneralComponent.CheckReadNull(SqlReader.Item("Summary")))
This also doesn't work. I'm using Word 2013 and TinyMCE text editor.
Any suggestions?
Without seeing the full html I can only make an assumption however what I would suggest is use WebUtility.HtmlDecode:
Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.
This is how you would use it:
html = WebUtility.HtmlDecode(html)
With Word this is how I have tested:
Dim s As String = "<this is some text and I'm wondering what to do>"
Dim wrd As New Word.Application
Dim doc As Word.Document = wrd.Documents.Add()
Dim para As Word.Paragraph = doc.Content.Paragraphs.Add()
para.Range.Text = WebUtility.HtmlDecode(s)
This is what the text looks like in my Document:
Edited as per OP's comment:
Dim s As String = "<p><This is some test information then sometime I use this></p>"
Dim wrd As New Word.Application
Dim doc As Word.Document = wrd.Documents.Add()
Dim para As Word.Paragraph = doc.Content.Paragraphs.Add()
para.Range.Text = WebUtility.HtmlDecode(s)
This code produces the following output in my Document:
Edited as per OP's update to question:
I have created a document called test.docx and added a bookmark called bSummary. I have done this in an attempt to replicate the OP's code.
Dim s As String = "<p><This is some test information then sometime I use this></p>"
Dim wrd As New Word.Application
Dim doc As Word.Document = wrd.Documents.Open("C:\test.docx")
Dim SumRng As Word.Range = doc.Bookmarks.Item("bSummary").Range
SumRng.Text = PreFormatHTML(s)
The output is the same as above. This leads me to think that whatever is passed into PreFormatHTML is not what you think it is. Is GeneralComponent.CheckReadNull(SqlReader.Item("Summary"))) passing into PreFormatHTML the following string; <p><This is some test information then sometime I use this></p>?
OP has confirmed the HTML is returned from PrrFormatHTML as expected. The issues seems to be linked to the Document. It may be to do with the with version of Word Interop that the OP is using. I'm using Microsoft Word 16.0 Object Library whilst the OP is using Microsoft Word 15.0 Object Library.

Convert from string to textbox object

I am trying to convert a string to textbox, but I am getting an error that it cannot convert to integer?!
I have the following code:
Dim curr As String
curr = "Detail_0107"
Dim NEWTEXT As TextBox = TryCast(Me.Controls(curr), TextBox)
NEWTEXT.Text = "test"
On the TryCast, I get the following error:
Conversion from string "Detail_0107" to type 'Integer' is not valid
Detail_0107 is a textbox on my form. Can I do this?
Thanks
Your problem seems to be that you're setting Detail_0107 as a string. If you want to set the text of Detail_0107, all you need to do is the following:
Detail_0107.Text = "test"
As you said Detail_0107 is already a textbox on your form, there shoud already be an object for it.
Try using Me.Controls.Find(curr) instead. Additionally, every control has a .Text property. It's part of the base Control type, and therefore you have no need to cast to TextBox. If you're very sure the Detail_0107 control does exist in that collection, you can get the code down to just this:
Me.Controls.Find("Detail_0107").Text = "test"

Verify existence of an item in a dropdownlist

How do I check for the existence of an item in a dropdownlist in vb.net?
Here's my not working code:
dim ddlTestDropdown as dropdownlist
ddlTestDropdown = New DropDownList()
If(ddlTestDropdown.Items.FindByValue("42") Is Not nothing)
Console.WriteLine("It's there")
End If
it won't let me compare the returned ListItem to nothing
Update: The error is from saying Is Not the fix is to say:
If(Not ddlTestDropdown.Items.FindByValue("42") Is Nothing)
Alternate answer:
Here's what I found to do this. Like #praythyus tried you need to test for contains, but vb.net only lets you do contains on a listitem. So I combined what I did with what he did and this worked:
Dim SetThisIfExists = ddlTestDropdown.Items.FindByValue("42")
If(ddlTestDropdown.Items.Contains(SetThisIfExists))
ddlTestDropdown.SelectedIndex = ddlTestDropdown.Items.IndexOf(SetThisIfExists)
End If
Sorry for giving C# syntax. Can you try with
as #RS said, you need to fill the ddl after initializing.
if(ddlTestDropdown.Items.Contains("42"))
{
}
Or instead of FindByValue can you use FindByText

Referencing a label in my asp.net page from code behind

Using VS 2013 VB.
I have the following line of code
Dim myLabel As Label = CType(Me.Controls("lbladd"), Label)
Whenever I run the page I get the following error
Conversion from string to type integer is not valid
I have several labels on my asp.net page each with a number at the end of the id which increases by one. My eventual aim is to loop through each label and add a string to each one using something like the following
For i = 0 To splitAddress.Count - 1
Dim myLabel As Label = CType(Me.Controls("lbladdress" & i + 1), Label)
myLabel.Text = splitAddress(i)
Next
Where splitaddress is a list of strings.
I just don't know why its throwing the error and mentioning an integer.
Me.Controls is of type ControlCollection and it is expecting a parameter of type integer, but you are providing a parameter of type string.
To find a control on the page you can use a method FindControl of class Page. You can see the info in MSDN.
You can update your code to use this method:
Dim myLabel As Label = CType(Me.FindControl("lbladdress" & (i + 1).ToString()), Label)

Start an Instance of Autodesk Inventor

Am Using Inventor api for customizing inventor documents.Here I use vb.net code for start an instance of the Inventor .my code is
inventorApp = CreateObject("Inventor.Application", "")
inventorApp.Visible = True
it is ok and working fine .but when we open the visual studio run as administrator then the createobject having some error.Any one know any other way to start an instance of Inventor?
Try using the marshal method instead.
Dim m_inventorApp As Inventor.Application
Try ' Try to use active inventor instance
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
m_inventorApp.SilentOperation = True
Catch ' If not active, create a new instance of Inventor
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
' Must set visible explicitly
m_inventorApp.Visible = True
m_inventorApp.SilentOperation = True
End Try
Catch
'Cant get or create an instance of inventor.
End Try
Private Sub Open_Button_Click()
ThisApplication.SilentOperation = True 'Suppresses the resolve links dialog
Dim myPath As String
myPath = FileName.Text 'Gets the string, FileName, from module 1
Dim Shell As Object
Set Shell = CreateObject("Shell.Application")
Shell.Open (myPath) 'Opens selected file
Resolve_and_Open.Hide 'Hides module
CompareStrings
End Sub
This is to open a sad assembly that needs to resolve links. I'm not sure if this will get around that error, but try using this:
ThisApplication.SilentOperation = True
Either that, or creating a shell and then opening it that way instead of directly.

Resources