ComboBox Query

I use a TextBox to add items into a ComboBox.
Can a ComboBox be added with items of different variables? (eg. string and interger)

I wanted to check if the selected item is an integer or not, i tried codes like this...
[code]If ComboBox1.text=[b]integer[/b] Then
[Statement]
End If[/code]
the bolded integer is not correct and cant work :p

Whats the correct way to do so??
Thanks

Comments

  • : I use a TextBox to add items into a ComboBox.
    : Can a ComboBox be added with items of different variables? (eg.
    : string and interger)
    :
    : I wanted to check if the selected item is an integer or not, i tried
    : codes like this...
    : [code]: If ComboBox1.text=[b]integer[/b] Then
    : [Statement]
    : End If[/code]:
    : the bolded integer is not correct and cant work :p
    :
    : Whats the correct way to do so??
    : Thanks
    :

    Best way to be sure is:
    [code]
    Dim nInt As Integer

    On Error Resume Next

    Err.Clear
    nInt = CInt(TextBox1.Text)
    If (Err.Number <> 0) Then
    'Not an integer
    Else
    'Integer
    End If

    'Removes errorhandling
    On Error GoTo 0
    [/code]
    There is a function, IsNumeric, but I don't know how strict it is.
    However, with this code, if you have as text "&H12" it'll interpret it as a hexadecimal number and the resulting integer would be 18.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • thanks it works!
    one more. i am not sure what events to use for the following process:

    I have a ComboBox which the Items will determine the score of a TextBox.text
    I used SelectedIndexChanged and this works well.

    But, when i wanna change the Item in the ComboBox which subsequently to change the score, which the procedure sequence is supposed to be:
    1) subtract the previous score
    2) add the new score based on new Item of ComboBox

    I tried to execute the subtraction by DropDown, GotFocus and other methods, which did not work as how I wanted. The problem occurs when I click the ComboBox many times (which multiplies the subtraction) without changing the Item. It is alright if I click and change the Item.

    Please Help!
  • : thanks it works!
    : one more. i am not sure what events to use for the following process:
    :
    : I have a ComboBox which the Items will determine the score of a
    : TextBox.text
    : I used SelectedIndexChanged and this works well.
    :
    : But, when i wanna change the Item in the ComboBox which subsequently
    : to change the score, which the procedure sequence is supposed to be:
    : 1) subtract the previous score
    : 2) add the new score based on new Item of ComboBox
    :
    : I tried to execute the subtraction by DropDown, GotFocus and other
    : methods, which did not work as how I wanted. The problem occurs when
    : I click the ComboBox many times (which multiplies the subtraction)
    : without changing the Item. It is alright if I click and change the
    : Item.
    :
    : Please Help!
    :

    Wouldn't it be easiest to recalculate the entire score? Just create a Sub called CalculateScore which checks all the states of the controls and then fills the textbox with the associated score.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories