|
Just make sure you are calling CurrentCulture.ClearCachedData() method everytime before you access current culture. That will give the latest information.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
d@nish,
yes, perfect. I didn't see the methode ClearCachedData. Thank you.
So complete coding is as follows. If the event is triggered for new settings in the windows control panel the Cached Info in the culture objects in cleared and a new transfer occurs from the datavariables to the frontend.
Imports System
Imports Microsoft.Win32
Imports System.Windows.Forms
Public Class Form1
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Adds Handler to receive Events for any changes in the windows control panel
AddHandler SystemEvents.UserPreferenceChanging, AddressOf SystemEvents_UserPreferenceChanging
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.PutDataToUI()
End Sub
Private Sub SystemEvents_UserPreferenceChanging(ByVal sender As Object, ByVal e As UserPreferenceChangingEventArgs)
If e.Category = UserPreferenceCategory.Locale Then
My.Application.Culture.ClearCachedData()
My.Application.UICulture.ClearCachedData()
Me.PutDataToUI()
Else
End If
End Sub
''' <summary>
''' Puts some data to an textbox
''' </summary>
''' <remarks></remarks>
Private Sub PutDataToUI()
Me.TextBox1.Text = My.Application.Culture.DisplayName & vbCrLf _
& My.Application.Culture.EnglishName & vbCrLf _
& Now.ToLongDateString & vbCrLf _
& Now.ToLongTimeString & vbCrLf _
& Now.ToShortDateString & vbCrLf _
& Now.ToShortTimeString & vbCrLf _
& My.Application.Culture.Name & vbCrLf _
& My.Application.UICulture.NativeName
End Sub
End Class
My be coding helps anybody.
regards,
bauer
|
|
|
|
|
gilchinger wrote: This does not work, because if you change the windows culture (windows control panel) the Thread Culture in the running vb.net program does not change.
A good thing, actually; imagine you displaying a monetary value, and say the cultural settings would give you a dollar-sign as the monetary unit. The value displayed is '10';
"$ 10.00"
Now you change your settings to Dutch. If the format were applied blindly, the control would show the same value in the new format;
"€ 10,00"
That's the same value, but not the same amount
I guess that the new information is stored in the Registry. Open RegEdit and explore this key;
HKEY_CURRENT_USER\Control Panel\International
I are Troll
|
|
|
|
|
Eddy,
of course, I agree.
A coding like this
Dim x As Double = 5000
Me.TextBox1.Text = x.ToString("C", My.Application.Culture.NumberFormat)
with blindly transfer to the new format is absulutly nonsense.
Option (1): adjust the amount before transfering to the new format
Option (2): Donn't use coding like mentioned above. Use always dollar, euro....,
I use option(2).
Only for date/time formats i use automatic adjustment to the new format.
|
|
|
|
|
gilchinger wrote: Only for date/time formats i use automatic adjustment to the new format.
I tend to store DateTime in GMT[^]. That would be overkill though if you're always in the same timezone.
The same goes for currency-conversions, or any other value that depends on a unit of measurement.
I are Troll
|
|
|
|
|
Hi guys im using vb.net. I've got two forms and ON LOAD of form1 i want form2 to automatically show with form1 hideing
i have already tried me.hide and my.forms.form2.show howver this doesn't work
any ideas??
Dan
|
|
|
|
|
You want to close thie first form or hide it? Anyways, create an object of form2 and then call show. From what you have posted, I assume you are treating it as a static method.
By the way, if you are hiding/closing the form1 in its load itself, why do you even need it?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
its part of a assignment however i need form1 to close. you mention create an object of form 2 could you explain that please. Im a bit of a novice programmer
Cheers
|
|
|
|
|
Form2 frm = new Form2();
frm.Show();
That is the C# version of what I was telling.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
found out how to do it on vb.net by using
form2 = new form2
form2.show
this shows no errors at first but when run it says
property can only be set to nothing?
is this the easiest way to do this, all i need to do is hide a form automatically when it appears. I would have thought that me.hide would have worked but for some stupid reason it dont??????
|
|
|
|
|
offroaderdan wrote: form2 = new form2
Nope. It should be dim frm as Form2 in VB.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
You cannot hide the form in the Load event of a form. When Load is raised and the code is executed, the form is not being shown yet. After your Load event code executes, the form is shown. You can only have a form hide itself AFTER the Load hander code executes.
|
|
|
|
|
sorry i need form 1 to hide not close
my bad
|
|
|
|
|
Sorry but i have reised that i have told you some details wrong.
I have an exisiting form called form2 with details and buttons and fun stuff like that on it. I dont wanna create a NEW form i just wanna display that form and hide form1.
|
|
|
|
|
Check the Application.OpenForms collection. This will give you all the open forms in your application. Then find the form2 in that and set it as the active form.
For hiding form1, you can use me.hide.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
how do i do this in vb.net?
i have tried
my.Application.OpenForms
?? how do i set form2 as the active form
sorry if i am being thick
|
|
|
|
|
Here's a twist: Don't use a form. Use a class; call form2 from it.
|
|
|
|
|
Hey there
I'm having trouble getting one element out of this XML file..
<sizedata Size= "VALUE" IGNORE THE REST OF THEM/>
here is a fully formed, but shortened XML file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Root Type="TRoot">
<Date>15/10/2009 12:30:08</Date>
<Folder fullpath="C:\" IsFilesNode="0">
<Name>C:\</Name>
<SizeData Size="74609238013" Allocated="72396726232" Wasted="234062016" CDRom="74727184384" Files="116733" Folders="12272" Compression="3"/>
</Folder>
<Folder fullpath="C:\" IsFilesNode="-1">
<Name>[Files]</Name>
<SizeData Size="18745407271" Allocated="18745561088" Wasted="153817" CDRom="18745475072" Files="69" Folders="0" Compression="1"/>
</Folder>
<Folder fullpath="C:\TEMP_\" IsFilesNode="0">
<Name>TEMP_ALAN</Name>
<SizeData Size="15469174140" Allocated="15489126222" Wasted="19886724" CDRom="15478267904" Files="9570" Folders="1832" Compression="1"/>
</Folder>
<Folder fullpath="C:\TEMP_\mp3\" IsFilesNode="0">
<Name>mp3</Name>
<SizeData Size="11504514137" Allocated="11513361814" Wasted="8829863" CDRom="11508457472" Files="4561" Folders="510" Compression="1"/>
</Folder>
<Folder fullpath="C:\TEMP_\mp3\My Music\" IsFilesNode="0">
<Name>My Music</Name>
<SizeData Size="11247143252" Allocated="11255940398" Wasted="8779436" CDRom="11251054592" Files="4532" Folders="506" Compression="1"/>
</Folder>
<Folder fullpath="C:\TEMP_\mp3\My Music\MP3\" IsFilesNode="0">
<Name>MP3</Name>
<SizeData Size="11074836494" Allocated="11083256268" Wasted="8402930" CDRom="11078576128" Files="4357" Folders="481" Compression="1"/>
</Folder>
<Folder fullpath="C:\TEMP_\mp3\My Music\MP3\MP3\" IsFilesNode="0">
<Name>MP3</Name>
<SizeData Size="9808652194" Allocated="9813168460" Wasted="4507742" CDRom="9810542592" Files="2458" Folders="242" Compression="1"/>
</Folder>
</Root>
The code I have is below:
<code>Try
Dim odoc As New System.Xml.XmlDocument
odoc.Load("C:\test\test.xml")
Dim oXmlLog As System.Xml.XmlElement
Dim text As String = ""
For Each oXmlLog In odoc.SelectNodes("Root")
Dim node As System.Xml.XmlElement
For Each node In oXmlLog.SelectNodes("Folder")
Dim fullpath As String = node.Attributes.GetNamedItem("fullpath").Value
'Dim SizeData As String = node.Attributes.GetNamedItem("SizeData").Value
Dim subnode = node.SelectSingleNode("Name")
Dim name As String = subnode.InnerText
Dim Date_ As XmlElement = odoc.DocumentElement
Dim Date_time As XmlNodeList = Date_.ChildNodes
Dim Date__time = (Date_time(0).InnerText)
text &= Date__time & fullpath & name & SizeData & Environment.NewLine
Next
Next
Console.Write(text)
Console.Read()
Catch ex As Exception
Console.Write(ex.ToString())
Console.Read()
End Try</code>
But I can't get the SIZE from SIZEDATA out and into a variable, can you help???
|
|
|
|
|
InnerText will give you all the inner nodes as well. Use .Value instead.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thanks for your reply...
Christian Graus wrote:
InnerText will give you all the inner nodes as well. Use .Value instead.
So how should this line be formed then ??
'Dim SizeData As String = node.Attributes.GetNamedItem("SizeData").Value
I have tried:
Dim subnode1 = node.SelectSingleNode("SizeData").Value
Dim Size As String = subnode1.InnerText
But this won't compile...
Any thoughts??
|
|
|
|
|
Perhaps if you told me the error, but .Value should return a string, not a node. That's the point, it REPLACES the call to InnerText, which you can't use, it won't work.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Sorry, I'm pretty new to this and am now a bit confused. In the original code above:
Dim fullpath As String = node.Attributes.GetNamedItem("fullpath").Value
Works and returns a value for "FullPath"
Dim SizeData As String = node.Attributes.GetNamedItem("SizeData").Value
Doesn't work and gives an "System.NullReferenceException" Error when compiled.
When that line is commented out the code returns all expected results.
Am I missing something here as the "fullpath" line in the XML is of the same form as the "SizeData" one.. So why do I get the error???
|
|
|
|
|
You are going about it in a kind of roundabout way (i prefer XPath) but I digress, you were on the correct path with your "subnode" line. Following your method, I just add two lines (your original subnode is the same).
Dim subnode = node.SelectSingleNode("Name")
Dim subnode2 = node.SelectSingleNode("SizeData")
Dim SizeData As String = subnode2.Attributes.GetNamedItem("Size").Value
|
|
|
|
|
Fantastic.. it's working....
here is the final code :
Try
Dim odoc As New System.Xml.XmlDocument
odoc.Load("C:\test\10g_2.xml")
Dim oXmlLog As System.Xml.XmlElement
Dim text As String = ""
For Each oXmlLog In odoc.SelectNodes("Root")
Dim node As System.Xml.XmlElement
For Each node In oXmlLog.SelectNodes("Folder")
Dim fullpath As String = node.Attributes.GetNamedItem("fullpath").Value
'Dim SizeData As String = node.Attributes.GetNamedItem("SizeData").Value
Dim subnode = node.SelectSingleNode("Name")
Dim name As String = subnode.InnerText
Dim subnode2 = node.SelectSingleNode("SizeData")
Dim SizeData As String = subnode2.Attributes.GetNamedItem("Size").Value
Dim Date_ As XmlElement = odoc.DocumentElement
Dim Date_time As XmlNodeList = Date_.ChildNodes
Dim Date__time = (Date_time(0).InnerText)
text &= Date__time & " " & fullpath & " " & name & " " & SizeData & Environment.NewLine
Next
Next
Console.Write(text)
Console.Read()
Catch ex As Exception
Console.Write(ex.ToString())
Console.Read()
End Try
Now I just need to get it to pass this info to SQL..
Thanks again...
|
|
|
|
|
Just because it might be easier for you to work with, take a look at this method. Drag a datagridview onto your form designer and put in the following code, change the table to see your different output. VS is very good at converting between XML and Datasets and vice-versa. If nothing else, the tables will help you visualize the structure of the XML, you can easily see from this sample that size is on a different 'level' than the rest of the data.
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'load xml into a dataset to use here
Dim dS As New DataSet
Dim fS As FileStream
'open the xml file so we can use it to fill the dataset
fS = New FileStream("C:\test\10g_2.xml", FileMode.Open)
'fill the dataset
Try
dS.ReadXml(fS)
Catch ex As Exception
MsgBox(ex)
Finally
fS.Close()
End Try
Me.DataGridView1.DataSource = dS.Tables(2)
End Sub
End Class
|
|
|
|