I got problem with resources. My project have 400 small images for status indicator. All images are set in 4 groups (4 different folders). Group are identified by My.Settings.imagevalue parameter. Indicator can give value from 1 to 100. Every new indicator value are displayed in: MainForm.indication_Value.Text .
As I have so many images, I would like to use dll with images as external resource. I have putted all images in 4 dll's, 100 images on each one. On top of DLL structure are RCData, where are set all images by value 1 to 100. I plan to use same DLL's for few apps seamlessly.
I use very simple code on text changes to change image:
Private Sub preview()
Dim indication As String
indication = MainForm.indication_Value.Text & ".jpg"
Dim resource As String = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, My.Settings.imagevalue, indication)
If IO.File.Exists(resource) Then
indication_preview.Image = Image.FromFile(resource)
Else
indication_preview.Image = My.Resources.Resources._error
End If
End Sub
How can use images from externa DLL with logic I have created before? I really don't want to write messy code for each image.
Thanks in advance for response!
Related
Im rather new to vb.net and have encountered following issue:
Im trying to open up 5 different folders in 5 different explorer windows. All of them should be opened in a fixed position and with a fixed size.
Lets say Folder1 should be at (5,5) with a size of (100,150)
Folder2 should be at (50,5) with a size of (80,75)
Folder3 should be at (100,5) with a size of (100,50)
Folder4 should be at (150,5) with a size of (35,90)
Folder5 should be at (200,5) with a size of (50,35)
I've found this method online to move ALL instances of explorer.exe to a fixed position and resize it -> https://social.msdn.microsoft.com/Forums/vstudio/en-US/f4effba6-ed9b-4e4d-a163-922fc158fdfd/open-file-explorer-and-change-its-sizelocation?forum=vbgeneral
Sub MoveAllExplorerWindows()
Dim ExplorerFileName As String
For Each ExplorerWindow As SHDocVw.InternetExplorer In New SHDocVw.ShellWindows()
ExplorerFileName = Path.GetFileNameWithoutExtension(ExplorerWindow.FullName).ToLower()
If ExplorerFileName.ToLowerInvariant() = "explorer" Then
ExplorerWindow.Left = 0
ExplorerWindow.Top = 0
ExplorerWindow.Width = Screen.PrimaryScreen.WorkingArea.Width / 2
ExplorerWindow.Height = Screen.PrimaryScreen.WorkingArea.Height
End If
Next ExplorerWindow
End Sub
But I want to have, depending on the actual folder, a different location and size. The code above would resize every explore.exe window and put it in the location (0,0).
Does anyone have any idea how I could change the code or implement something completely new?
Thanks in advance! <3
It is my first time building a database and I wanted to share a solution to a problem I encountered.
My problem was that I wanted to show different images for each record in a report, but I also wanted to be able to move the database. This was a problem. I search in all the forums and all the different solutions didn’t work. I also found an article written by Microsoft saying that the only way is to either store the full path to the images or to store the image in the database. But this causes a problem if the database is moved, or storing the images in the database will take up a lot of storage space.
The problem is that the codes doesn’t work for each record in the report, the codes are for the entire report. So writing codes to find the backend and the image folder would result in displaying the first image in the report for all the records in that report.
However I discovered, when only storing the name of the image in a table, it would sometimes work (but it shouldn’t have, because I didn’t have the path) but when I restarted the database it would stop working. Investigating further I discovered that whenever you open the file browser it will store the path in some kind of memory. As long as the path to the images is stored in the memory it will be able to link the images to the path.
So my solution…
When the form, from where you access the reports is opened, the file browser is opened and the path to the images is pasted in (using codes to find backend and the image folder) and then the browser is closed. And this creates a link to the image names (stored in a table) with the path. And each different images will be shows for each different records in the report.
Not a pretty solution. Whenever the form is opened, you will see a flash of the file browser. But it gets the job done.
In the load form event:
`' this will find the backend and the image folder:
Dim filepath As String
Dim strBackEndPath As String
Dim lenPath As Integer
Dim i As Integer
Dim j As Integer
strBackEndPath = CurrentDb.TableDefs("yourTabeInBackend").Connect
j = InStrRev(strBackEndPath, "=") + 1
strBackEndPath = Mid(strBackEndPath, j)
BackPath = Left(strBackEndPath, InStrRev(strBackEndPath, "\"))
filepath = BackPath & "YourImageFolder\"
'this will open the folder browser and paste in the path and close it:
Dim f As Object
Set f = Application.FileDialog(msoFileDialogFolderPicker)
Dim varFile As Variant
Dim strPath As String
Dim fileName As String
With f
.InitialFileName = (filepath)
.AllowMultiSelect = False
SendKeys "{ESC}", True
f.Show
For Each varFile In .SelectedItems
Next varFile
End With
`
You can move the pictures to a subfolder of the folder of your database.
Then save the pictures' names like this:
Picture1.jpg
Picture2.jpg
etc.
When you run the application, obtain the path to the pictures:
PictureFolder = CurrentProject.Path & "\FolderName\"
Then the path to a picture will be:
PictureFolder & Me!PictureFileName.Value
When you "move" your database, move both the database file and the folder with the picture files with it.
yup, i just encountered same problem and i agree with what Richard_Ha said, but in my case i solve it with storing image path on textbox and its work..
first textbox name "fileimage_txt" and bound to list of image filename on table
second textbox name "image_path" with property
Source Control : =GetImagePath()
visible : No (if u dont want it get printed)
and image control with property
Source Control : =[path_txt] & [fileimage_txt]
I'm now created an application that encode value into QR code, and turn into image. Then, I want to store the image to my local. But, I tried many solutions that I found on Google and here. The issue still prompt out unexpectedly everytime. My code and a sample error picture is shown below. Please help me!
A generic error occured in GDI+
Dim qrCodeObject As QRCodeEncoder = New QRCodeEncoder()
Dim image As Image
Dim bitmap As Bitmap
qrCodeObject.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE
qrCodeObject.QRCodeScale = 6
qrCodeObject.QRCodeVersion = 5
qrCodeObject.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H
image = qrCodeObject.Encode(value)
bitmap = New Bitmap(image)
bitmap.Save(value + ".jpg")
ANSWER: Always save file with different name and doesn't include any illegal characters
Path concatenation with simple strings is crap.
Use Path.Combine to build a path, because this ensures your path does
contain needed slashes if it would otherwise not be valid.
Dim Pat As String = Path.Combine(String.Concat(value, ".jpg"))
bitmap.save(Pat)
If this does not help, we need to know what "value" contains in your case.
This is a fairly simple app that opens and decodes packed XML. I can open the files directly from the apps UI no problem.
The issue is, I have 2 types associated with my app.
The ICON shows next to the 2 file types as they should, how ever, only one, if double clicked shows up in the Environment.GetCommandLineArgs().
Dim arguments() = Environment.GetCommandLineArgs() seems fool-proof.
I have used a msgbox to trap and display anything in position 1 of the list and the 2nd file type NEVER sends anything to the args list.
I am deploying (for now) using clickOnce and added per what I read at MS's site the following to the manifest file:
<fileAssociation
xmlns="urn:schemas-microsoft-com:clickonce.v1"
extension=".visual"
description="WoT visual file"
progid="wotvisual"
defaultIcon="XMLFile_789_32.ico"
/>
<fileAssociation
xmlns="urn:schemas-microsoft-com:clickonce.v1"
extension=".chunk"
description="WoT chunk file"
progid="wotchunk"
defaultIcon="XMLFile_789_32.ico"
/>
This is at the head of my main form load event:
Dim arguments() As String = Environment.GetCommandLineArgs()
If arguments.Length > 1 Then
Dim s1 = arguments(1)
If s1 <> String.Empty Then
openVisual(s1)
End If
I should mention that dbl clicking either file does indeed open my app.. It just never sees anything as in file path, from the .chunk types.
And if you spotted it, this is World Of Tanks I'm working with. I write tools for the modding community.
I need to get the Folder size and display the info on a report (SSRS). I need to do this for a number of Databases (loop!). These DB's are websites' backends.
Are any samples available for this? Does xp_filesize and the like the right solution?
Looking at the question and Tomalak's response, and I'm assuming the reporting server will be able to reach the folders held in the DB:
Firstly set up the query to get you back the result-set of paths - I assume you'll have no trouble with this part. Next you'll need to add a custom code function to your report: http://msdn.microsoft.com/en-us/library/ms155798.aspx - This function will take the folder path as a parameter, and pass back the size of the folder. You'll have to write in VB.Net if you want to embed the code in the report, or you could code up a DLL and bring that in.
An example VB.Net code block (Remember you may need to prefix objects with System.IO.) http://www.freevbcode.com/ShowCode.asp?ID=4287
Public Shared Function GetFolderSize(ByVal DirPath As String, _
Optional IncludeSubFolders as Boolean = True) As Long
Dim lngDirSize As Long
Dim objFileInfo As FileInfo
Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath)
Dim objSubFolder As DirectoryInfo
Try
'add length of each file
For Each objFileInfo In objDir.GetFiles()
lngDirSize += objFileInfo.Length
Next
'call recursively to get sub folders
'if you don't want this set optional
'parameter to false
If IncludeSubFolders then
For Each objSubFolder In objDir.GetDirectories()
lngDirSize += GetFolderSize(objSubFolder.FullName)
Next
End if
Catch Ex As Exception
End Try
Return lngDirSize
End Function
Now, in your report, in your table, you'd have for the cell that shows the folder size an expression something like:
=Code.GetFolderSize(Fields!FolderPath.Value)
I doubt this approach will be performant for a manually-viewed report, but you might get away with it for small result sets, or a scheduled report delivered by email?
Oh, and this piece suggests you 'may' run into permissions issues using System.IO from within RS: http://blogs.sqlxml.org/bryantlikes/pages/824.aspx
Could you clarify who should do what in your scenario? Do you want SQL Server do get the info or do you want Reporting Server do that?
What exactly do you mean by "folder size"? Is "one folder, sum up each file" enough or does it need to be recursive? Either way, I'd go for a little custom .NET function that uses System.IO.Directory and it's relatives.
I'd consider splitting this into two pieces, maybe a Windows Service to scan the directories and aggregate the data into a database, then use SSRS to report on the database as usual.
The reason I suggest this is to use master..xp_filesize and it's kin the account the SQL Server service is starting with needs access to the paths to be scanned. Once this turns into accessing paths on other machines I'd be less comfortable with the security implications of that.
Hope this helps
In SSRS you can to do this with the help of custom data extension. U need give the path for the datasource as your folder name and it will retrive your files and its related informations and displayed
For further reference and custom dll use this
http://www.devx.com/dbzone/Article/31336/0/page/4
I have done this earlier.
Note: you have to make related changes to Report Designer and Report Manager configuration files.