Results 1 to 5 of 5

Thread: School project Currency converter Help :)

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    10

    School project Currency converter Help :)

    Hi

    I'm new to Visual Studio but I'm stuck at my new Project.
    For a School project, I have to make an Windows Form Application with a currency converter.

    I have 2 ListBoxes (i'm sorry my project is in Dutch):

    1. ListBoxMunteenheden: The user selects the currency like American Dollars, British pounds etc.
    If the value in the Inputbox is >0 and < 500 , the results go in the other ListBox.

    2. ListBoxWisselkoers: The result of Listbox 1 (ListBoxMunteenheden) shows here.

    When the user enters a currency twice and give a other value (>0 and <500), the old result in Listbox 2 (ListboxWisselkoers) needs to be removed.

    Can someone help me with this?

    My code is as follow:
    Code:
    Public Class Opdracht4
     
     
        Private Sub ListBoxMunteenheden_SelectedIndexChanged(sender As Object, e As EventArgs) Handles 
         ListBoxMunteenheden.SelectedIndexChanged
            'De Cases worden aangemaakt om de verschillende Munteenheden aan ListBox Wisselkoersen toe te voegen.
     
            Select Case ListBoxMunteenheden.SelectedIndex
     
                Case 0
                    'De Amerikaanse Dollar wordt toegevoegd aan ListBoxWisselkoersen
     
                    Dim AmerikaanseDollar As Decimal
     
                    AmerikaanseDollar = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Amerikaanse dollars (1 Euro 
                    = .... Amerikaanse Dollar):  ")
                    ListBoxWisselkoersen.Items.Add("1 Euro =  " & AmerikaanseDollar & "  Amerikaanse dollars")
                    ListBoxWisselkoersen.Items.Add(" ")
     
                    If AmerikaanseDollar <= 0 Then ListBoxWisselkoersen.Items.Clear()
                    If AmerikaanseDollar <= 0 Then MsgBox("U dient een andere waarde op te geven")
     
                    If AmerikaanseDollar >= 500 Then ListBoxWisselkoersen.Items.Clear()
                    If AmerikaanseDollar >= 500 Then MsgBox("U dient een andere waarde op te geven")
     
     
                Case 1
                    'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
                    ListBoxMunteenheden.Text = " "
                    MsgBox("U dient op een munteenheid te klikken")
     
     
                Case 2
                    'De Britse Pond wordt toegevoegd aan ListBoxWisselkoersen
                    Dim BritsePonden As Decimal
                    BritsePonden = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Britse Ponden (1 Euro = .... Britse Pond)")
                    ListBoxWisselkoersen.Items.Add("1 Euro =  " & BritsePonden & "  Britse Ponden")
                    ListBoxWisselkoersen.Items.Add(" ")
     
                    If BritsePonden <= 0 Then ListBoxWisselkoersen.Items.Clear()
                    If BritsePonden <= 0 Then MsgBox("U dient een andere waarde op te geven")
     
                    If BritsePonden >= 500 Then ListBoxWisselkoersen.Items.Clear()
                    If BritsePonden >= 500 Then MsgBox("U dient een andere waarde op te geven")
     
     
                Case 3
                    'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
                    ListBoxMunteenheden.Text = " "
                    MsgBox("U dient op een munteenheid te klikken")
     
     
     
                Case 4
                    'Wanneer er op de Euro wordt geklikt, verschijnt er een melding.
                    Dim Euro As Decimal
                    Euro = MsgBox("U heeft gekozen voor de Euro. Hiervan is de waarde altijd 1. Kies een andere munteenheid uit 
                     de lijst.")
     
     
                Case 5
                    'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
                    ListBoxMunteenheden.Text = " "
                    MsgBox("U dient op een munteenheid te klikken")
     
     
                Case 6
                    'De Russische Roebel wordt toegevoegd aan ListBoxWisselkoersen
                    Dim RussischeRoebel As Decimal
                    RussischeRoebel = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Russische Roebel (1 Euro = .... Russische Roebel)")
                    ListBoxWisselkoersen.Items.Add("1 Euro =  " & RussischeRoebel & "  Russische Robel")
                    ListBoxWisselkoersen.Items.Add(" ")
     
                    If RussischeRoebel <= 0 Then ListBoxWisselkoersen.Items.Clear()
                    If RussischeRoebel <= 0 Then MsgBox("U dient een andere waarde op te geven")
     
                    If RussischeRoebel >= 500 Then ListBoxWisselkoersen.Items.Clear()
                    If RussischeRoebel >= 500 Then MsgBox("U dient een andere waarde op te geven")
     
                Case 7
                    'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
                    ListBoxMunteenheden.Text = " "
                    MsgBox("U dient op een munteenheid te klikken")
     
                Case 8
                    'De Japanse Yen wordt toegevoegd aan ListBoxWisselkoersen
                    Dim JapanseYen As Decimal
                    JapanseYen = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Japanse Yen (1 Euro = .... Japanse Yen)")
                    ListBoxWisselkoersen.Items.Add("1 Euro =  " & JapanseYen & "  Japanse Yen")
                    ListBoxWisselkoersen.Items.Add(" ")
     
                    If JapanseYen <= 0 Then ListBoxWisselkoersen.Items.Clear()
                    If JapanseYen <= 0 Then MsgBox("U dient een andere waarde op te geven")
     
                    If JapanseYen >= 500 Then ListBoxWisselkoersen.Items.Clear()
                    If JapanseYen >= 500 Then MsgBox("U dient een andere waarde op te geven")
     
                Case 9
                    'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
                    ListBoxMunteenheden.Text = " "
                    MsgBox("U dient op een munteenheid te klikken")
     
            End Select
    Attachment 153247Attachment 153249
    Last edited by Shaggy Hiker; Nov 3rd, 2017 at 11:22 AM. Reason: Added CODE tags.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: School project Currency converter Help :)

    Please use formatting tags when posting code snippets.
    vb.net Code:
    1. Public Class Opdracht4
    2.  
    3.  
    4.     Private Sub ListBoxMunteenheden_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
    5.      ListBoxMunteenheden.SelectedIndexChanged
    6.         'De Cases worden aangemaakt om de verschillende Munteenheden aan ListBox Wisselkoersen toe te voegen.
    7.  
    8.         Select Case ListBoxMunteenheden.SelectedIndex
    9.  
    10.             Case 0
    11.                 'De Amerikaanse Dollar wordt toegevoegd aan ListBoxWisselkoersen
    12.  
    13.                 Dim AmerikaanseDollar As Decimal
    14.  
    15.                 AmerikaanseDollar = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Amerikaanse dollars (1 Euro
    16.                 = .... Amerikaanse Dollar):  ")
    17.                 ListBoxWisselkoersen.Items.Add("1 Euro =  " & AmerikaanseDollar & "  Amerikaanse dollars")
    18.                 ListBoxWisselkoersen.Items.Add(" ")
    19.  
    20.                 If AmerikaanseDollar <= 0 Then ListBoxWisselkoersen.Items.Clear()
    21.                 If AmerikaanseDollar <= 0 Then MsgBox("U dient een andere waarde op te geven")
    22.  
    23.                 If AmerikaanseDollar >= 500 Then ListBoxWisselkoersen.Items.Clear()
    24.                 If AmerikaanseDollar >= 500 Then MsgBox("U dient een andere waarde op te geven")
    25.  
    26.  
    27.             Case 1
    28.                 'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
    29.                 ListBoxMunteenheden.Text = " "
    30.                 MsgBox("U dient op een munteenheid te klikken")
    31.  
    32.  
    33.             Case 2
    34.                 'De Britse Pond wordt toegevoegd aan ListBoxWisselkoersen
    35.                 Dim BritsePonden As Decimal
    36.                 BritsePonden = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Britse Ponden (1 Euro = .... Britse Pond)")
    37.                 ListBoxWisselkoersen.Items.Add("1 Euro =  " & BritsePonden & "  Britse Ponden")
    38.                 ListBoxWisselkoersen.Items.Add(" ")
    39.  
    40.                 If BritsePonden <= 0 Then ListBoxWisselkoersen.Items.Clear()
    41.                 If BritsePonden <= 0 Then MsgBox("U dient een andere waarde op te geven")
    42.  
    43.                 If BritsePonden >= 500 Then ListBoxWisselkoersen.Items.Clear()
    44.                 If BritsePonden >= 500 Then MsgBox("U dient een andere waarde op te geven")
    45.  
    46.  
    47.             Case 3
    48.                 'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
    49.                 ListBoxMunteenheden.Text = " "
    50.                 MsgBox("U dient op een munteenheid te klikken")
    51.  
    52.  
    53.  
    54.             Case 4
    55.                 'Wanneer er op de Euro wordt geklikt, verschijnt er een melding.
    56.                 Dim Euro As Decimal
    57.                 Euro = MsgBox("U heeft gekozen voor de Euro. Hiervan is de waarde altijd 1. Kies een andere munteenheid uit
    58.                  de lijst.")
    59.  
    60.  
    61.             Case 5
    62.                 'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
    63.                 ListBoxMunteenheden.Text = " "
    64.                 MsgBox("U dient op een munteenheid te klikken")
    65.  
    66.  
    67.             Case 6
    68.                 'De Russische Roebel wordt toegevoegd aan ListBoxWisselkoersen
    69.                 Dim RussischeRoebel As Decimal
    70.                 RussischeRoebel = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Russische Roebel (1 Euro = .... Russische Roebel)")
    71.                 ListBoxWisselkoersen.Items.Add("1 Euro =  " & RussischeRoebel & "  Russische Robel")
    72.                 ListBoxWisselkoersen.Items.Add(" ")
    73.  
    74.                 If RussischeRoebel <= 0 Then ListBoxWisselkoersen.Items.Clear()
    75.                 If RussischeRoebel <= 0 Then MsgBox("U dient een andere waarde op te geven")
    76.  
    77.                 If RussischeRoebel >= 500 Then ListBoxWisselkoersen.Items.Clear()
    78.                 If RussischeRoebel >= 500 Then MsgBox("U dient een andere waarde op te geven")
    79.  
    80.             Case 7
    81.                 'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
    82.                 ListBoxMunteenheden.Text = " "
    83.                 MsgBox("U dient op een munteenheid te klikken")
    84.  
    85.             Case 8
    86.                 'De Japanse Yen wordt toegevoegd aan ListBoxWisselkoersen
    87.                 Dim JapanseYen As Decimal
    88.                 JapanseYen = InputBox("Geef de wisselkoers >0 en <500 voor de Euro tov Japanse Yen (1 Euro = .... Japanse Yen)")
    89.                 ListBoxWisselkoersen.Items.Add("1 Euro =  " & JapanseYen & "  Japanse Yen")
    90.                 ListBoxWisselkoersen.Items.Add(" ")
    91.  
    92.                 If JapanseYen <= 0 Then ListBoxWisselkoersen.Items.Clear()
    93.                 If JapanseYen <= 0 Then MsgBox("U dient een andere waarde op te geven")
    94.  
    95.                 If JapanseYen >= 500 Then ListBoxWisselkoersen.Items.Clear()
    96.                 If JapanseYen >= 500 Then MsgBox("U dient een andere waarde op te geven")
    97.  
    98.             Case 9
    99.                 'Wanneer er op een lege regel wordt geklikt, verschijnt er een melding.
    100.                 ListBoxMunteenheden.Text = " "
    101.                 MsgBox("U dient op een munteenheid te klikken")
    102.  
    103.         End Select

  3. #3
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,040

    Re: School project Currency converter Help :)

    Hi Angel,
    the first thing you will need is the Daily Rate.

    you can see them here(Daily) in XML
    Code:
    Public ECPXMLAddress As String = _
            "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  4. #4
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,040

    Re: School project Currency converter Help :)

    Hi,

    this will read the Exchange Rate from the EZB-Bank-Frankfurt (Daily updated) to a
    Datagridview

    Code:
    Imports System.Globalization
    
    
    Public Class Form2
    
        Private bs As New BindingSource
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            bs.DataSource = getECBCurrencyExchanges("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml")
            Me.DataGridView1.DataSource = bs
        End Sub
    
    
        Private Function getECBCurrencyExchanges(ByVal WebAddress As String) As  _
          IQueryable
            Try
                Dim xr As XElement = XElement.Load(WebAddress)
                Dim xn As XNamespace = xr.Attribute("xmlns").Value
    
                Dim xECBs = From ECB In xr.Descendants(xn + "Cube") _
        Where ECB.Attribute("currency") IsNot Nothing _
                        AndAlso ECB.Attribute("rate") IsNot Nothing _
                        Select Currency = ECB.Attribute("currency").Value, _
                        DisplayName = GetCurrencyName(ECB.Attribute("currency").Value), _
                             Rate = Double.Parse(ECB.Attribute("rate").Value, _
                               New CultureInfo("en-US"))
               
    
                Return xECBs.AsQueryable
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    
        Private Function GetCurrencyName(ByVal isoCode As String) As String
            Dim cultures As CultureInfo() = CultureInfo.GetCultures( _
              CultureTypes.SpecificCultures)
    
            For Each ci As CultureInfo In cultures
                Dim ri As New RegionInfo(ci.LCID)
                If ri.ISOCurrencySymbol = isoCode Then
                    Return ci.DisplayName
                End If
            Next
            Return String.Empty
        End Function
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: School project Currency converter Help :)

    I edited your post to add [CODE][/CODE] tags, which you can do by pressing the # button and pasting the code between the resulting tags. JMC used the VB button, instead, which gives you line numbers and syntax coloring. Which you choose is up to you.

    One thing to note is that you have Option Strict OFF. This allows you to do some unsafe stuff. For example, the InputBox returns ONLY a string. You are implicitly converting that to a decimal, but if the string can't be converted to a decimal, the code will simply crash with an invalid conversion exception. Options Strict would prevent you from doing things like that. The proper solution would be to take the return from InputBox, put it in a string, then use Decimal.TryParse to convert it to a decimal. Better still would be to not use the InputBox, but make your own form for this. InputBox is almost never the best answer. For one thing, you can't tell the difference between the user pressing the OK and Cancel button. Cancel will just return an empty string, which the user could do by not entering anything and pressing OK. However, you may be required to use InputBox, in which case you should at least recognize that it returns strings and act accordingly.

    There are also some inefficiencies like this:

    Code:
    If JapanseYen <= 0 Then ListBoxWisselkoersen.Items.Clear()
    If JapanseYen <= 0 Then MsgBox("U dient een andere waarde op te geven")
    This isn't technically wrong, it's just inefficient. A better way to write it would be:

    Code:
    If JapanseYen <= 0 Then 
       ListBoxWisselkoersen.Items.Clear()
       MsgBox("U dient een andere waarde op te geven")
    End If
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width