Dynamic Crystal Report - vb.net

I want to get the following working, please could someone advise...
Dim rpt As ReportDocument
If (Exists(rpt.ReportDefinition.ReportObjects("crlTitle"))) Then
txtTitle = CType(rpt.ReportDefinition.ReportObjects("crlTitle"), TextObject)
txtTitle.Color = mainColour
txttitle.Text = "Report Title"
End If
Any help much appreciated.

I've never done anything like that...I'm not sure if it's possible. What will work for sure though is to use a parameter to control the report title. Simply create a parameter and then rpt.SetParamterValue("title", "Some Title")

Since you've identified the problem as "Exists is undefined". Addressing that problem is more straightforward. Try replacing the "Exists" line with:
If (rpt.ReportDefinition.ReportObjects.Contains("crlTitle")) Then
Were there any other problems?

Here is my solution:
Dim rpt as ReportDocument
Dim rptTextObject as TextObject = nothing
Dim mainColour As Color = Color.Green
Try
If (rpt.ReportDefinition.ReportObjects("crlTitle") IsNot Nothing) Then
rptTextObject = CType(rpt.ReportDefinition.ReportObjects("crlTitle"), TextObject)
rptTextObject.Color = mainColour
rptTextObject.Text = "Report Title"
End If
Catch
End Try
I do this for each Object on the report that I want to either set text or set colour.

Put this line of code at the beginning of the module
Imports System.IO.File

Related

VB.Net Handling Multiple Forms into Panel

I have tried to find an answer to this already, but cannot find one that answers this question.
I have a Master Form which contains two panels. In the master Form I am trying to write a subroutine to handle the loading of a form into one of the panels.
One panel always contains the same form and the code which works for this is:
'Configure Toolbar Import
Dim toolbarHandler As _pnl_header = New _pnl_header()
toolbarHandler.Size = pnlHeader.Size
toolbarHandler.TopLevel = False
pnlHeader.Controls.Add(toolbarHandler)
toolbarHandler.Show()
The panel successfully shows the form _pnl_header as expected.
The second panel will change the displayed form depending on user input, so rather than having to write the above code for every eventuality i would like one Public Sub to handle them all...
I've started writing a sub along the lines of:
Public Sub LoadContentPanel(WhichForm As Form)
Try
Dim contentHandler As WhichForm = New WhichForm()
contentHandler.Size = pnlContent.Size
contentHandler.TopLevel = False
pnlContent.Controls.Add(contentHandler)
contentHandler.Show()
Catch ex As Exception
MsgBox("Unable to Handle Content Panel Change. Error: " & ex.Message, vbOKOnly + vbCritical, "Load Error")
End Try
End Sub
However this fails as 'WhichForm' is not defined - how is best to correct this? or is there a better alternative?
Thanks
Without going into what you are doing I can explain where the error comes from.
Here you declare argument variable WhichForm of type Form
Public Sub LoadContentPanel(WhichForm As Form)
. . . . .
Code is incorrect in the next declaration line. WhichForm is a variable and not a type. Hence
Dim contentHandler As WhichForm = New WhichForm()
is invalid at As WhichForm. Because after As you need a type name. If you did
Dim contentHandler As Form = New Form()
it would work.
It seems that all you need to do is remove Dim contentHandler As WhichForm... and rename argument WhichForm to contentHandler.

VBA Getting Compile Error: Invalid use of new keyword

this code is use to convert PDF to excel.
But a problem was found during the compilation. The error message getting is "Compile Error: Invalid use of new keyword" at line "Set AC_PD = New Acrobat.CAcroHiliteList". I have no idea to fix this and had many try on this. I need some advise, guidance from you. Appreciated and Thank you.
Private Sub ABC()
Dim AC_PD As Acrobat.CAcroPDDoc
Dim AC_Hi As Acrobat.CAcroHiliteList
Set AC_PD = New Acrobat.CAcroPDDoc
Set AC_Hi = New Acrobat.CAcroHiliteList
'...
End Sub
Judging by a cursory look at the documentation, it looks like their COM interfaces might be a little jacked up. Try this instead:
Set AC_PD = CreateObject("AcroExch.PDDoc")
Set AC_Hi = CreateObject("AcroExch.HiliteList")
The typedef names are on page 19.

Getting A NullRefrenceException And Cannot Find Out Why?

My goal here is to create a web browser that has a tab system in VB. Since I cannot explicitly name every single new tab the user will use, I have to make more generalized callings. Here's the conflicting code (my btnGo):
Dim thisBrowser As newWebBrowser = Me.tabBrowser.SelectedTab.Tag
If txtAdressSearch.Text.Contains(".com") Or txtAdressSearch.Text.Contains(".net") Or txtAdressSearch.Text.Contains(".gov") Or txtAdressSearch.Text.Contains(".edu") Or txtAdressSearch.Text.Contains(".org") Then 'More to be checked for
thisBrowser.Navigate(txtAdressSearch.Text)
Else
thisBrowser.Navigate("https://www.google.com/search?sourceid=chrome-psyapi2&rlz=1C1ASAA_enUS445&ion=1&espv=2&ie=UTF-8&q=" + txtAdressSearch.Text)
End If
And here's the newWebBrowser code:
Public Class newWebBrowser
Inherits WebBrowser
Private Sub webBrowserComplete() Handles Me.DocumentCompleted
Dim newTab As TabPage = frmBrowser.Tag()
Dim frmSK As New frmBrowser
Dim hi As String
newTab.Text = Me.DocumentTitle
frmSK.txtAdressSearch.Text = Me.Url.ToString
End Sub
End Class
Any time I enter something into txtAdressSearch, Visual Studio raises a NullRefrenceException and highlights thisBrowser.Navigate(txtAdressSearch.Text). As a side note, it says "Object reference not set to an instance of an object."
Anyone know whats the problem here? Thank you.
After debugging for more than an hour, I looked over my code and saw I was missing a big part of it. I wrote it all in and it worked fine. The issue was the tags weren't being defined correctly (and in some cases, not at all) so .Tag was returning Nothing.
Thanks to all who helped.

Error on passing multiple parameters to a Report Viewer

I'm trying to learn my way around VS 2013 using VB.net and its Report Viewer. I want to know how to pass a string to a parameter basically. And hopefully move on to other methods/procedures. Anyway I have a problem with this particular code block:
With Me.ReportViewer1.LocalReport
.ReportPath = "C:\Users\Kim\Documents\Visual Studio 2013\Projects\Tests\Tests\Report1.rdlc"
.DisplayName = "Test Report"
.DataSources.Clear()
End With
Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Normal)
Dim rpT As New ReportParameter("rpTitle", "Huehuehue")
Dim rpD As New ReportParameter("rpDate", "This day")
Dim HeaderParams As ReportParameter() = {rpT, rpD}
For Each param As ReportParameter In HeaderParams
ReportViewer1.LocalReport.SetParameters(param)
Next
If I comment out Dim rpD As New ReportParameter("rpDate", "This day") and change this line Dim HeaderParams As ReportParameter() = {rpT}, the rpT part will show correctly on the report form. The result is relatively the same if I exclude rpT instead. If I use both I get a Some parameters or credentials have not been specified on my report. I've been hovering around Google for sometime now but nobody else seems to have this kind of problem.
Solved it. Apparently you had to declare it as New ReportParameter() in the SetParameters. I don't know how to use an array there. But then again I'd still need to list all the parameters, so that'd be redundant. If anybody can improve this that would be great.
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {rpT, rpD})
This is how I send parameter values:
1) create a generic list of type ReportParameter
2) add your new parameters to the list with a parameter name and value and visibility
3) set the parameters for the LocalReport
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("ReportTitle", stgReportTitle, True))
paramList.Add(New ReportParameter("ReportFooter", stgReportFooter, True))
Me.vwrReport.LocalReport.SetParameters(paramList)
Always works!

Searching specific folder / extension using vb.net

I How can I search a specific file using vb.net and store the path in a variable?
For example if I need to know where I have *.abc files in my entire computer, how can this be done?
Thanks
Furqan
Dim di As New DirectoryInfo("c:\")
Dim files() As FileInfo = di.GetFiles("*.abc", SearchOption.AllDirectories)
There's the EnumerateFiles method that has been introduced in .NET 4.0. If not you could use the GetFiles method but be warned that this method returns an array of strings which represent the matched filenames and it could block for a long time.
Well this is awkward, but this seems to work for me before, maybe you can try it
If System.IO.File.Exists(txtName.Text) Then
MsgBox("Match not found")
Else
MsgBox("Match found")
End If
Update
This one works
Directory.SetCurrentDirectory(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\WinVault")
If Not System.IO.File.Exists(txtName.Text & ".wv") Then
btnSave.Enabled = True
Else
btnSave.Enabled = False
'Balloon tip
bTipControl = txtName
bTipCaption = "Vault Name"
bTipText = VAULT_NAME_EXIST
bTip_Show()
End If
And of course, make sure you do import System.IO or add reference if not available.