2 Replies - 519 Views - Last Post: 05 February 2012 - 12:50 PM Rate Topic: -----

Topic Sponsor:

#1 oli356  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-February 12

How to use lists - itemdata

Posted 01 February 2012 - 10:15 AM

Hey

I am trying to use a list for my program. It has various job roles and different pay levels, once a job role is selected (these are written in the list property, it needs to get the hourly rate from the indexdata in the propeties. This rate will then be used elsewhere.

I have tried doing it as an input, the list is called lstpaygrade and the variable is hourrate. I have this as my output
hourrate = Lstpaygrade.ListIndex

I have also tried it as .list and .listcount, I am then just trying to work out basic pay, overtime pay and output the gross pay (will be more later on). The output result though is very awkward.

The code:
Private Sub cmdcalculate_Click()


Dim hours As Single
Dim pensionselect As Boolean
Dim pensionpercentage As Integer
Dim taxablepay, tax1, tax2, hourrate, grosspay, basicpay, overtimehours, pensionamount As Currency

pensionpercentage = 5

'input

hours = txthours.Text
hourrate = Lstpaygrade.ListIndex

'process

'Works out the overtime hours
If hours > 40 Then
    overtimehours = hours - 40
Else
    overtimehours = 0
End If

   
  

basicpay = hours * hourrate
overtimepay = (overtimehours * hourrate) * 1.5
grosspay = basicpay + overtimepay


'output

txtgrosspay.Text = grosspay

End Sub


List:
Student
Mechanic
Minder
Tax Lawyer

ItemData:
650
2500
3800
7500


For example when I select student, input 1 hour the result should be 650 but its 0. The mechanic with the same hours is 1, minder 2, tax lawyer 3. These results should be 650, 2500, 3800 and 7500.
Any help appreciated, thanks.

Oli

Is This A Good Question/Topic? 0
  • +

Replies To: How to use lists - itemdata

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 323
  • View blog
  • Posts: 1,950
  • Joined: 19-May 09

Re: How to use lists - itemdata

Posted 05 February 2012 - 10:59 AM

As you surmise, the ItemData property is the way to go with this. Keep in mind that ItemData is an integer, so you can't have anything but a number and the number can't be greater than 32,768.

When you're creating your ListBox, use something like this to add an item: [code}With myList
.AddItem "Student"
.ItemData(.NewIndex) = 650
.AddItem "Mechanic"
.ItemData(.NewIndex) = 2500
[/code]and so on. To access the item data of a selected list item, use
myList.ItemData(myList.ListIndex)
You can use the With keyword here, too, and should (using With gives a performance bonus if you have more than one reference to a single object), but I wanted to give you an example without it in case you don't fully understand With yet.
Was This Post Helpful? 1
  • +
  • -

#3 oli356  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-February 12

Re: How to use lists - itemdata

Posted 05 February 2012 - 12:50 PM

Thanks Bob, meant to update this today. Figured out what the bit of code was to use for the list. After several changes I got it all working and tested =) Currently trying to transfer the program into C++ in a console application, while the VB part was for college purposes, I'm interested in different languages and how things work in C++. Just got a problem with my IF statement currently :)

Thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1