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.
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 SubSub App_Start Form1.Show ArrayList1.Add(10) ArrayList1.Add(20) ArrayList1.Add(30)End SubSub ComboBox18_SelectionChanged (Index, Value) TextBox1.Text = ArrayList1.Item(Index)End Sub
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...
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 SubSub App_Start Form1.Show ArrayList1.Add(10) ArrayList1.Add(20) ArrayList1.Add(30) ArrayList2.Add(1) ArrayList2.Add(2) ArrayList2.Add(3) End SubSub ComboBox18_SelectionChanged (Index, Value) TextBox1.Text = ArrayList1.Item(Index)End SubSub ComboBox2_SelectionChanged (Index, Value) TextBox2.Text = ArrayList2.Item(Index)End SubSub Button1_ClickTextbox3.Text=textbox1.Text+textbox2.TextEnd Sub Thanks for his responses.
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 = 0End SubSub ComboBox18_SelectionChanged (Index, Value) TextBox1.Text = ArrayList1.Item(Index) Textbox3.Text=textbox1.Text+textbox2.TextEnd SubSub ComboBox2_SelectionChanged (Index, Value) TextBox2.Text = ArrayList2.Item(Index) Textbox3.Text=textbox1.Text+textbox2.TextEnd Sub BTW, I recommend you to change the controls names to a more meaningful name. This will help you once your project grows.
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?
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:
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...
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.
Kyto, As CableGuy points out, you should use the Select keyword. I've attached what I think it is that you require. Regards, RandomCoder.
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.
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:
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!