Developing a multilingual application in VB.Net 2008, Im able to add resources to forms and create a multilingual forms depending on uiculture. On reading Msdn on creating the multilingual string values for messagebox contents, have added the .resource file to the project files path as specified. There is no error on compilation but throws the MissingManifestResourceException error
Dim rm As ResourceManager
rm = ResourceManager.CreateFileBasedResourceManager("strFormResources", ".", Nothing)
Dim ci As CultureInfo
ci = New CultureInfo("fr-FR")
MessageBox.Show(rm.GetString("sample1", ci))
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: strFormResources locationInfo: fileName: strFormResources.resources
There is strFormResources.resources and strFormResources.fr-FR.resources in Resources of the project.
I have searched for this error details but could not find a solution. What am i doing wrong or is there any other method for displaying multilingual strings in the messagebox.
Thanks in advance
The lblBrowsefoldertoputconvertedfiles is a hint perhaps. You are supposed to pass the string resource name, not the name of the directory that contains the resource.
To do it "properly", be sure to take advantage of the My.Resources feature. Proceed as follows:
Project + Add New Item, General, Resources File
Name it Resources.fr-FR.resx and click Add
The string resource editor automatically opens. Add the strings that you've got in your original string table, now using French as the language.
Compile.
Look in your project's bin\Debug folder and verify that you now see the satellite assembly. It should be stored in the fr-FR directory with the project.resources.dll name.
Test this by dropping a button on your form and writing this code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Threading.Thread.CurrentThread.CurrentUICulture = _
System.Globalization.CultureInfo.GetCultureInfo("fr-FR")
MessageBox.Show(My.Resources.String1)
End Sub
Related
I have done a simple VB application with this code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim procName As String = Process.GetCurrentProcess().ProcessName
Dim processes As Process() = Process.GetProcessesByName(procName)
If processes.Length > 1 Then
Process.GetProcessesByName("keyinput")(0).Kill()
End If
End Sub
Public Sub type(ByVal int As Double, str As String)
For Each c As Char In str
SendKeys.Send(c)
System.Threading.Thread.Sleep(int * 1000)
Next
End Sub
Sub vai()
Dim line As String = ""
If File.Exists("trans.txt") Then
Using reader As New StreamReader("trans.txt")
Do While reader.Peek <> -1
line = reader.ReadLine()
type(0.155, line)
'SendKeys.Send(line)
SendKeys.Send("{ENTER}")
Loop
End Using
File.Delete("trans.txt")
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
vai()
End Sub
Basically the timer in it check if a file exists, read it and type the content simulating the keyboard.
I want this exe to start automatically when user login, it does it, apparently, I can see the form1 pop up but doesn't really works. Everyting is fine only if I run it manually by double-clicking the icon. Why and what can I do? Thanks
ps. i already tried to execute it with windows task manager, or putting a shortcut in the windows startup folder, or calling it from a cmd
EDIT:
when app starts automatically , process is running, but windows form is showing like this
Instead starting manually is showing like this:
I don't know this for a fact but I suspect that the issue is the fact that you are not specifying the location of the file. If you provide only the file name then it is assumed to be in the application's current directory. That current directory is often the folder that the EXE is in but it is not always and it can change. DO NOT rely on the current directory being any particular folder. ALWAYS specify the path of a file. If the file is in the program folder then specify that:
Dim filePath = Path.Combine(Application.StartupPath, "trans.txt")
If File.Exists(filePath) Then
Using reader As New StreamReader(filePath)
EDIT:
If you are running the application at startup by adding a shortcut to the user's Startup folder then, just like any other shortcut, you can set the working directory there. If you haven't set the then the current directory will not be the application folder and thus a file identified only by name will not be assumed to be in that folder.
If you are starting the app that way (which you should have told us in the question) then either set the working directory of the shortcut (which is years-old Windows functionality and nothing to do with VB.NET) or do as I already suggested and specify the full path when referring to the file in code. Better yet, do both. As I already said, DO NOT rely on the current directory being any particular folder, with this being a perfect example of why, but it still doesn't hurt to set the current directory anyway if you have the opportunity.
It was a Windows task scheduler fault, that for some reason didn't executed the exe correctly at logon. I've solved the issue by using Task Till Down and everything works fine now.
The issue I am having is opening a program that's in my project folder after being published. here is my code:
Private Sub B_OpenCruc_Click(sender As Object, e As EventArgs) Handles B_OpenCruc.Click
System.Diagnostics.Process.Start("F:\Deploy\myprogram\Project\myprogram\myprogram\Crucible\Crucible.exe")
End Sub
now it works on my pc but not other pc's. I figured it's because its a full path. I also set properties to "content" and "copy always"
I tried using Dim Path As String = ("\My Project\Crucible\Crucible.exe") I would receive the following error
System.ComponentModel.Win32Exception: 'The system cannot find the file specified'
also this as well:
Severity Code Description Project File Line Suppression State
Warning Assembly 'Crucible\Crucible.exe' is incorrectly specified as a file. SCOfflineLoader
when I publish it.. the files are there but my program can't open it.
I can't seem to figure this out, is there a solution to this?
Basically the Goal I want to achieve is When I click a Button It will open a .exe
OR
When I click a button It will Open a .exe that the Target user already has (i.e notepad.exe)
Thanks.
You can use the Application.StartupPath property to get the directory where your application is running from.
Dim path As String = Path.Combine(Application.StartupPath, "Crucible.exe")
System.Diagnostics.Process.Start(path)
I am creating a small application to parse HTML of a page into variables so I can generate code for another proprietary application. I am using VB with HTMLAgilityPack for parsing. When I execute the load statement, no error are shown but all other code after that line simply fails to execute, as if it isn't even there.
Private Sub Importer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strImportType As String
Dim strImportURL As String
strImportType = main.importType
strImportURL = main.importURL
Dim web As New HtmlAgilityPack.HtmlWeb
Dim content As New HtmlAgilityPack.HtmlDocument
content = web.Load(strImportURL)
After using Visual Vincent suggestion to open the Exceptions Settings and force VB to fail it allowed for more information. This issue was simply that the file was not being found due to spaces in the filename. Adding quotes around the filename resolved the issue.
I am using the below code to navigate to a specific web address as follows :
WebBrowser1.Navigate("http://192.168.0.157/cm?cmnd=POWER%20Toggle"
The fact is that the the link returns a .json file and the WebBrowser controls displays the default save file dialog asking if i want to save the file or run it.
I want to ignore it the dialog and read from the .json file directly(i mean after downloading it).
I just want to get rid of the Save dialog of the webbrowser.I am a newbie so i don't know what to search or how to ask properly.
Though your post is not even close to be standard and hardly explains the issue, what i understand so far is that you have a few issues and i will answer them separately.
Disabling the download dialog of the webbrowser and downloading the files automatically
Firstly, you mentioned it returns a .json file. So , you can easily add a SaveFileDialogto your form or set a custom path(maybe in a variable) and check if the webbrowser is trying to download any .json files. Then you will Cancel the call(typically i mean that cancel the popup that says Save , Run ...) and make use of the SaveFileDialog or the local variable to save the file directly to disk. Here's a sample which uses a local string variable as the path and saves the .json file directly to disk :
Imports System.ComponentModel
...
Dim filepath As String '''class lever variable
Private Sub myBroswer_Navigating(sender as Object, e As WebBrowserNavigatingEventArgs) Handles myBroswer.Navigating
If e.Url.Segments(e.Url.Segments.Length - 1).EndsWith(".json") Then
e.Cancel = True
filepath = "C:\test\" + e.Url.Segments(e.Url.Segments.Length - 1)
Dim client As WebClient = New WebClient()
AddHandler client.DownloadFileCompleted , AddressOf New AsyncCompletedEventHandler(DisplayJson);
client.DownloadFileAsync(e.Url, filepath)
End If
End Sub
Displaying the result AKA .json
It is very easy to de-serialize/parse .json files.But first, download this , extract the ZIP and Add Reference to Newtonsoft.Json.dll. Now consider the bellow code snippet :
Private Sub DisplayJson()
Dim parseJson = Newtonsoft.Json.Linq.JObject.Parse(File.ReadAllLines(filepath))
MsgBox(parseJson("element name here").ToString)
End sub
Hope this helps
I've got a form that can be loaded from USB stick, from my home computer, or from work computers. The form executable is always stored in "some path\National Payroll\Build* and references a database in "some path\National Payroll".
The some path part changes, but the database is always in the parent directory. I've tried other advice to get the form's path, but I can only seem to get the path of the Local AppData folder where the form runs from when it is open, not the path of the form's executable. How do I get that?
Application.StartupPath
And, eventually Application.StartupPath.Parent
EDIT: TEST REPORT
Make a new project. Add a form with two TextBoxes named StartupPath and ExecutablePath. In the Form's Load event put the following code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
StartupPath.Text = Application.StartupPath
ExecutablePath.Text = Application.ExecutablePath
End Sub
Compile and deploy the executable on a USB flash drive (or wherever you want) and double click. This output will be produced: