Assign value (numeric) to combox's items?

Discussion in 'Questions (Windows Mobile)' started by kyto, Aug 14, 2007.

  1. kyto

    kyto Member Licensed User

    Hi! I´m Newbie to Basic4ppc (Excelent tool).

    My intention is to create a ComboBox that it contains Items (Product 1, Product 2, Product 3…) And on having selected, automatically there is assigned to him a numerical value (Cost) that appears in a Textbox.
    Is it possible to do this?
    Attachment sample file.
    Thanks for his attention.
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    There are several ways to achieve this.
    One way is to save the prices in an ArrayList:
    You will need to add an ArrayList from the designer.
    Code:
    Sub Globals
        
    End Sub

    Sub App_Start
        Form1.Show
        ArrayList1.Add(
    10)
        ArrayList1.Add(
    20)
        ArrayList1.Add(
    30)
    End Sub

    Sub ComboBox18_SelectionChanged (Index, Value)
        TextBox1.Text = ArrayList1.Item(Index)
    End Sub
     
  3. kyto

    kyto Member Licensed User

    Thank you.

    I will try it.
    Thank you very much!
     
  4. Cableguy

    Cableguy Expert Licensed User

    This kind of relation can be easily created using a ini file containing both product name and cost and add simultaneously ( to the same index ) the product name to a combobos and the cost to an array list...
     
  5. kyto

    kyto Member Licensed User

    Thanks! It works, but another question...

    It works, both! For now, I’m using Erel´s method.
    Now I added another ComboBox (Tax) that it contains ítems ( A, B, C) whit another assigned cost (1,2,3).
    Whit a button click, I calculate total cost of both items input previously.

    Sub Button1_Click
    Textbox3.Text=textbox1.Text+textbox2.Text
    End Sub

    It works perfectly, My question is: I can calculate and show automatically these result without the button?


    Code:
    Sub Globals
        
    End Sub

    Sub App_Start
        Form1.Show
        ArrayList1.Add(
    10)
        ArrayList1.Add(
    20)
        ArrayList1.Add(
    30)
        ArrayList2.Add(
    1)
        ArrayList2.Add(
    2)
        ArrayList2.Add(
    3)   
    End Sub

    Sub ComboBox18_SelectionChanged (Index, Value)
        TextBox1.Text = ArrayList1.Item(Index)
    End Sub

    Sub ComboBox2_SelectionChanged (Index, Value)
        TextBox2.Text = ArrayList2.Item(Index)
    End Sub

    Sub Button1_Click
    Textbox3.Text=textbox1.Text+textbox2.Text
    End Sub
    Thanks for his responses.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    What about this:
    Code:
    Sub App_Start
        Form1.Show
        ArrayList1.Add(
    10)
        ArrayList1.Add(
    20)
        ArrayList1.Add(
    30)
         ArrayList2.Add(
    1)
        ArrayList2.Add(
    2)
        ArrayList2.Add(
    3)    
        ComboBox18.SelectedIndex = 
    0
        ComboBox2.SelectedIndex = 
    0
    End Sub

    Sub ComboBox18_SelectionChanged (Index, Value)
        TextBox1.Text = ArrayList1.Item(Index)
         Textbox3.Text=textbox1.Text+textbox2.Text
    End Sub

    Sub ComboBox2_SelectionChanged (Index, Value)
        TextBox2.Text = ArrayList2.Item(Index)
        Textbox3.Text=textbox1.Text+textbox2.Text
    End Sub
    BTW, I recommend you to change the controls names to a more meaningful name. This will help you once your project grows.
     
  7. kyto

    kyto Member Licensed User

    Error: Input string was not in a correct format.

    I will change the control names, thanks for recommendation.

    I used the code
    but it indicates me an error:
    "An error occurred on sub combobox18 selectionchanged.
    Line number: 14

    Textbox3.Text= textbox1.Text+textbox2.Text
    Error description:
    Input string was not in a correct format.
    Continue?...

    Which is the error?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Add these lines to Sub App_Start (first lines):
    TextBox2.Text = ""
    TextBox3.Text = ""
     
  9. taximania

    taximania Well-Known Member Licensed User


    :cool: Using the binary.dll ? you could create and save, 'then modify if you wish', a file on disk .dat .ini .ect so the information or value's you want are already set in the textbox? 'values'. Read the values of the file with your App_Start Sub

    This is an addition I could have made to my port settings in my 'bad' GPS example. I didn't.

    Perhaps I'll try and see if it works :sign0161:
     
  10. Cableguy

    Cableguy Expert Licensed User

    I was not targeting the binary dll in my answer, only how to create and matain a valid relation beetween the combobox and the textboxes values...

    Sorry but I just don't see were binary dll was mentioned in this thread...
     
    Last edited: Aug 15, 2007
  11. kyto

    kyto Member Licensed User

    Solved.Thanks.

    Solved!
    I added:
    TextBox2.Text = "0"
    TextBox3.Text = "0"

    It works.
    Thanks!
     
  12. kyto

    kyto Member Licensed User

    How to do it?

    Now it works as i wanted it, but now I want to add another textbox (Class) that should indicate a letter (A, B, C) depending on the result of textbox3 (Total).
    For example, if the Total is 2, textbox (Class) shows "A", if the result is 3, textbox (Class) shows "B".
    I tried it, but I do not find the form.
    Is it possible?

    Erel: Thanks for your patience with this beginner.
     
  13. Cableguy

    Cableguy Expert Licensed User

    You should try case select...See the help about Case....
     
  14. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Kyto,

    As CableGuy points out, you should use the Select keyword.
    I've attached what I think it is that you require.

    Regards,
    RandomCoder.
     
  15. kyto

    kyto Member Licensed User

    Something like this...

    Thanks for his responses.

    What I need is something similar; I need to develop some simple applications of use in medicine, to calculate some scales, for example a so-called Modified Child-Turcotte-Pugh classification for cirrhosis (Attached).
    Depending on the chosen parameters, a score is obtained (Total numerical score), and from this one, there is obtained the class (Child-Turcotte-Pugh class):
    “A” if total numerical score is 5-6 points.
    “B” if total numerical score is 7-9 points.
    “C” if total numerical score is 10-15 points.

    I will try with his suggestions.

    Regards.
     
  16. Cableguy

    Cableguy Expert Licensed User

    I think this is what you wanted...
     
  17. kyto

    kyto Member Licensed User

    Yes!

    This is exactly what I want! Of this I will base for other applications, which have basically the same structure.

    Thank you very much Cableguy!
    :sign0060:
     
  18. LineCutter

    LineCutter Active Member Licensed User

    This is clearly a good way to learn some programming skills, but in the time between now & then end of your learning curve you might want to take a look at Medcalc (www.med-ia.ch)
    Also, be VERY careful that your calculations give the correct answers under all circumstances if you ever plan on using them for real!
     
Loading...