Kccc

im makeing my own calculator for the game Runescape, i know i just play it in my spaire time and i was felling i needed to know more about visual basic and how to make a calculator, so heres a pic,

what i want to know is,
1.how do i set values for each item in the combo box,
2.how to get it toso that when u hit the calc button it mult the number in the first text box by the selected combo box items value and display it in the 3rd textbox, all help will be appreated,

### Re: Visual Basic Express Edition having calculator problems

nobugz

A combobox can store more than just strings, it can store objects. Check this thread for C# code that shows the technique.

### Re: Visual Basic Express Edition having calculator problems

Kccc

i dont know c# and what i mean is if i put 200 in the first texbox and selected shafts it would do
200*15 then display the result in the 3rd textbox, and i need to know how to set the value of the combobox item like shafts is worth 15 there for 200*15 is 200 logs becoming 3000 exp

### Re: Visual Basic Express Edition having calculator problems

Kccc

i have this code and i was wondering if it set it so that shafts = 20exp so that when i did 200*shafts it would come out like 200*20
if so then how do i get the calculate button to do the math from textbox 1 and combobox1 to appear in texbox 3
Dim x As New Integer
x = 20
String.Equals("shafts", x)

### Re: Visual Basic Express Edition having calculator problems

nobugz

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'--- Fill the combobox
'... Etc
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Try
Dim amount As Decimal = Decimal.Parse(txtAmount.Text)
Dim unit As Unit = CType(cboUnits.Items(cboUnits.SelectedIndex), Unit)
lblResult.Text = CStr(amount * Unit.mMult)
Catch ex As Exception
lblResult.Text = ex.Message
End Try
End Sub

'--- What we store in cboUnits:
Private Class Unit
Public mText As String
Public mMult As Decimal
Public Sub New(ByVal txt As String, ByVal mult As Decimal)
mText = txt
mMult = mult
End Sub
Public Overrides Function ToString() As String
Return mText
End Function
End Class

End Class

### Re: Visual Basic Express Edition having calculator problems

Kccc

Thank you SOOOO much for that your the man

### Re: Visual Basic Express Edition having calculator problems

Kccc

ok 1 more question how do i insted of getting it 2 mult 2 numbers do i get it to subtract 2 numbers then devide buy another heres the code i have but it dosent do it correctly, i dont know whats wrong i dont get eny errors so help plz

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'--- Fill the combobox

End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Try
Dim unit2 As Unit = CType(cboUnits2.Items(cboUnits2.SelectedIndex), Unit)
Dim unit As Unit = CType(cboUnits.Items(cboUnits.SelectedIndex), Unit)
Dim amount As Decimal = Decimal.Parse(txtAmount.Text)
lblResult.Text = CStr(unit2.mMult - amount)
Catch ex As Exception
lblResult.Text = ex.Message
End Try
End Sub

'--- What we store in cboUnits:
Private Class Unit
Public mText As String
Public mMult As Decimal
Public Sub New(ByVal txt As String, ByVal mult As Decimal)
mText = txt
mMult = mult
End Sub
Public Overrides Function ToString() As String
Return mText
End Function
End Class
End Class