This solution uses en-US, fr, de, and jp for the culture encodings. The resource files contain the conversion units for each culture. The file exchange.en-US.txt is as follows: Toen-US=1 Tofr=.7 Tode=1.67 Tojp=1098.45 The file exchange.fr-fr.txt is as follows: Toen-US=1.43 Tofr=1 Tode=2.34 Tojp=1569.21 The file exchange.jp-ja.txt is as follows: Toen-US=.0009 Tofr=.00064 Tode=.0015 Tojp=1 The file exchange.de-ge.txt is as follows: Toen-US=.59 Tofr=.42 Tode=1 Tojp=657.7 Don't forget to use resgen.exe to place these files in .resource files. The user interface, exercise1.aspx, is as follows: 1: <%@ Page Inherits="ExchangeCalculator" src="/books/4/226/1/html/2/exercise1.vb" %> 2: 3: <html><body> 4: <font size="5">Currency Calculator</font><hr> 5: <form runat="server"> 6: <asp:Label runat="server"/> 7: <asp:TextBox runat="server"/> to 8: <asp:ListBox runat="server" 9: Size=1 10: AutoPostBack=true> 11: <asp:ListItem>en-US</asp:ListItem> 12: <asp:ListItem>fr-FR</asp:ListItem> 13: <asp:ListItem>de-ge</asp:ListItem> 14: <asp:ListItem>jp-ja</asp:ListItem> 15: </asp:ListBox> 16: </form> 17: <asp:Label runat="server"/> 18: </body></html> The code-behind, exercise1.vb, uses the conversions in the resource files to convert monetary values. It needs to retrieve the currency symbols, so it converts from culture to region by using a case statement; the user selects a culture, which is transferred to a region, which is used to retrieve the currency symbol. The code is as follows: 1: Imports System 2: Imports System.Web 3: Imports System.Web.UI 4: Imports System.Web.UI.WebControls 5: Imports System.Globalization 6: Imports System.Resources 7: Imports System.Threading 8: 9: Public Class ExchangeCalculator : Inherits Page 10: public lblAnswer as Label 11: public lblCurrency as Label 12: public tbValue as TextBox 13: public lbRegion as ListBox 14: 15: sub Page_Load(Sender as Object, e as EventArgs) 16: dim objRM as ResourceManager 17: dim strLanguage as string = Request.UserLanguages(0). ToString 18: 19: dim objCulture as new CultureInfo(strLanguage) 20: Thread.CurrentThread.CurrentCulture = new CultureInfo(strLanguage) 21: Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLanguage) 22: 23: dim objRegion as new RegionInfo(GetRegionFromCulture (objCulture.Name)) 24: lblCurrency.Text = objRegion.CurrencySymbol.ToString 25: 26: if Page.IsPostBack then 27: objRM = ResourceManager. CreateFileBasedResourceManager("exchange", _ 28: Server.MapPath("."), Nothing) 29: objRegion = new RegionInfo(GetRegionFromCulture (lbRegion.SelectedItem. Text)) 30: dim dblAnswer as double 31: dblAnswer = Ctype(tbValue.Text, Double) * CType(objRM.GetString("To" & lbRegion.SelectedItem.Text), Double) 32: lblAnswer.Text = objRegion.CurrencySymbol. ToString & dblAnswer.ToString 33: 34: objRM.ReleaseAllResources 35: end if 36: end sub 37: 38: private function GetRegionFromCulture (strCulture as string) as string 39: select case strCulture 40: case "en-US" 41: Return "us" 42: case "ja-ja" 43: Return "jp" 44: case "de-ge" 45: Return "de" 46: case "fr-FR" 47: Return "fr" 48: end select 49: end function 50: End Class |