Crystal Report Load Report Failed vb.net - vb.net

I have an Error in Load report Failed.
This is my code :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CrystalReportViewer1.ReportSource = Application.StartupPath + "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem\Reports\CrystalReport1.rpt"
CrystalReportViewer1.SelectionFormula = "{Lastname} = '" & TextBox1.Text.ToString & "' "
CrystalReportViewer1.RefreshReport()
CrystalReportViewer1.Refresh()
End Sub
can you please help me.

You probably don't want to use Application.StartupPath and a path that starts like: "c:\Users". Probably your Application Startup Path is already like "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem"
If your reports are in the same folder as your .exe file, you probably want this line instead
'Not this (original)
'CrystalReportViewer1.ReportSource = Application.StartupPath + "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem\Reports\CrystalReport1.rpt"
'Which would end up looking like:
' "C:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystemC:\Users\user\Desktop\Lastnato\IT58 PROJECTS\BRCPS\SoftEng ProjSystem\Reports\CrystalReport1.rpt"
'Instead, just use the relative path
CrystalReportViewer1.ReportSource = Path.Combine(Application.StartupPath, "Reports\CrystalReport1.rpt")
Also, I recommend using Path.Combine() because it easily takes care of putting one backslash (not two or zero) when it combines.

Related

How to register an icon to a file association?

There are two file extentions called .luo and .luda.
When the program loads the .luo and .luda are assigned.
The variables path and path2 contains the location to the icons.
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim path, path2 As String
path = Application.StartupPath & "ludafile.ico"
path2 = Application.StartupPath & "luofile.ico"
My.Computer.Registry.ClassesRoot.CreateSubKey(".luda").SetValue("", "Luda Solution (.luda)", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey(".luo").SetValue("", "Luda Page File (.luo)", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("LudaCreate\shell\open\command").SetValue("", Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
End Sub
The code above succesfully works but I want to register an icon to these files.
One icon for .luda and another for .luo.

File Association for my own Visual Basic application

I made my application that can read some specific extension on load in Visual Basic 2017.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Environment.GetCommandLineArgs(1).ToString = My.Application.Info.DirectoryPath.ToString + "\" + My.Application.Info.AssemblyName + ".exe" Then
Else
If System.IO.Path.GetExtension(Environment.GetCommandLineArgs(1)) = ".myOwnExt" Then
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(Environment.GetCommandLineArgs(1).ToString)
MsgBox(fileReader)
End If
End If
End Sub
But I want to make my program default for that extension and I want to set my icon for those files. Is it possible to make it happen with Visual Basic?
Your code would look something like this...
My.Computer.Registry.ClassesRoot.CreateSubKey(".myOwnExt").SetValue("", _
"myOwnExt", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey("MyProgramName\shell\open\command").SetValue("", _
Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
Here is a full example on how to do this in VB .NET. Like mentioned above you need to change some registry settings.
https://www.codeproject.com/Articles/18594/File-Association-in-VB-NET
On a quick glance at your code GetCommandLineArgs(1) needs to be changed to GetCommandLineArgs(0) to get this working.

Opening an Empty Directory from a Windows Form - VB.net

I'm trying to open a directory via my Windows Form created in VB.Net but every solution I've found doesn't seem to work.
Currently I'm using-
Dim path As String = Directory.GetCurrentDirectory()
Private Sub logDirBTN_Click(sender As Object, e As EventArgs) Handles logDirBTN.Click
Process.Start(path + "\Resources\Logs")
End Sub
Which returns "The system cannot find the file specified" exception. That's interesting because I know the folder is there. Furthermore this button's functionality works without any issue and from what I can tell the only difference is I'm opening a text file rather than an empty directory-
Private Sub stationListBTN_Click(sender As Object, e As EventArgs) Handles stationListBTN.Click
Process.Start("notepad.exe", path + "\Resources\StationList\StationList.txt")
End Sub
Here are all the other things I've tried-
Private Sub logDirBTN_Click(sender As Object, e As EventArgs) Handles logDirBTN.Click
'Process.Start("explorer.exe", path + "\Resources\Logs")
'Shell("explorer.exe", path + "\Resources\Logs", vbNormalFocus)
'Application.StartupPath & path + "\Resources\Logs"
'Shell(path + "\Resources\Logs", vbNormalFocus)
End Sub
Any help is greatly appreciated.
Dim MyProcess As New Process()
MyProcess.StartInfo.FileName = "explorer.exe"
MyProcess.StartInfo.Arguments = "C:\Blah"
MyProcess.Start()
MyProcess.WaitForExit()
MyProcess.Close()
MyProcess.Dispose()
Or just...
Process.Start("explorer.exe", "C:\FTP\")
Application.StartupPath is going to get you to your bin\Debug or bin\Release folder by the way, whatever folder the *.exe is in.
I'm guessing this is what you're looking for:
Process.Start("explorer.exe", Application.StartupPath & "\Resources\Logs")
Also, don't use + for joining strings. Use &
I assume you are trying to invoke Windows Explorer.
Add a trailing \ in the call to .Start
IO.Directory.CreateDirectory("C:\temp\temp")
Process.Start("c:\temp\temp\")
In the OP first example you were trying to open a file 'Logs'

StreamWriter leaving a file even if not saved

I have this code to write some data from textboxes into a textfile. And i'm using streamwriter to do this. Here you may see the code below:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Save As New SaveFileDialog()
Dim myStreamWriter As System.IO.StreamWriter
Save.Filter = "Text [*.txt*]|*.txt|All Files [*.*]|*.*"
Save.CheckPathExists = True
Save.Title = "Export & Save - FNG"
Save.FileName = txtTitle.Text & " - Plugs Details File Exported"
Save.ShowDialog(Me)
Try
myStreamWriter = System.IO.File.AppendText(Save.FileName)
myStreamWriter.Write("Details of Plugs:" & Environment.NewLine & txtDetails.Text & Environment.NewLine & DateAndTime.Now)
myStreamWriter.Flush()
Catch ex As Exception
End Try
End Sub
The code does work fine, it saves the details into a text file too. But the problem is when i cancel the save file dialog (without saving the textfile) it stil creates a file in the application start path. Why is this happening? What am i doing wrong? How do i correct this?
Try
If Save.ShowDialog(Me) <> DialogResult.Ok Then Return
Cancelling the dialog doesn't automatically make your Sub return!
Further, you are using StreamWriter wrong. Use
Using myStreamWriter As System.IO.StreamWriter = System.IO.File.AppendText(Save.FileName)
myStreamWriter.Write("Details of Pish flaps:" & Environment.NewLine & txtDetails.Text & Environment.NewLine & DateAndTime.Now)
End Using
And remove the Dim of the StreamWriter. This will ensure that the StreamWriter is closed even if an exception is thrown.

import image to picture box from desktop user

I want to import a picture from folder which created by project when installed on user desktop but each user have different user name , how can i import from picture from dsektop user
Here is My code
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles Button2.Click
PictureBox1.Image = Image.FromFile("(My.Computer.FileSystem.SpecialDirectories.Desktop, "New folder") \" + ID.Text + ".png")
end sub
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
this will resolve to the desktop folder for the current user. Are you really creating folders on the desktop? Usually data and subfolders are stored in AppData.
EDIT
I SUSPECT you might have need of this folder in other places and even if not it can be saved and 'fixed' before hand. Elsewhere, like when the app starts:
Friend mUserFolder As String
mUserFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
' your code was not adding the required backslash
mUserFolder &= "\Data\" ' append the sub folder name
Now to load the file in button click the code is simpler to read and debug:
PictureBox1.Image = Image.FromFile(muserFolder & ID.Text & ".png")
Also use & for concatenating strings instead of +