We help IT Professionals succeed at work.

Combobox formular for form load

Jason
Jason asked
on
I am after formula help

I have a combobox and i need it to list currency in increments of 10 cents

I have this

            Dim h
            Dim h1 As String
            For h = 1 To 50
                h1 = h + 0.1
                cboMin.Items.Add("$" & h1)
                cboMax.Items.Add("$" & h1)
            Next h

But the results of this is
$1.1
$2.1
$3.1
etc
What I need is
$1.10
$1.20
$1.30
etc

The formula need to start from $1.00 up to $5.00
Comment
Watch Question

Full Stack .NET Developer
Commented:
Hello try:
            Dim h as Integer
            Dim h1 As Decimal = 0
            For h = 1 To 50
                h1 += 0.1
                cboMin.Items.Add("$" + h1.ToString("N"))
                cboMax.Items.Add("$" + h1.ToString("N"))
            Next h

Open in new window

Carlos VillegasFull Stack .NET Developer

Commented:
Also you can try:
Dim h as Integer
Dim h1 As Decimal = 0
For h = 1 To 50
    h1 += 0.1
    cboMin.Items.Add(h1.ToString("C"))
    cboMax.Items.Add(h1.ToString("C"))
Next h

Open in new window

Author

Commented:
Thks
Carlos VillegasFull Stack .NET Developer

Commented:
You're welcome, but I think that you really need is this:
Dim h1 As Decimal = 1
Dim txt As String
Do While h1 <= 5
    cboMin.Items.Add("$" + h1.ToString("N"))
    cboMax.Items.Add("$" + h1.ToString("N"))    
    h1 += 0.1
Loop

Open in new window

Carlos VillegasFull Stack .NET Developer

Commented:
Ignore line #2

Author

Commented:
yv989c:

Thanks I just added an if statement in to handle the > $1
So all good thks for your help

Explore More ContentExplore courses, solutions, and other research materials related to this topic.