Results 1 to 16 of 16

Thread: run-time error 13 - type mismatch

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7

    run-time error 13 - type mismatch

    Hi, pls what's wrong with the code below?

    (PLS NOTE: optNumber is a radio button array, txtNumber is a text box)


    Private Sub optNumber_Click(Index As Integer)
    Dim OldNumber As String
    Dim NewNumber As String

    OldNumber = txtNumber.Text

    NewBase = optNumber(Index).Tag 'problematic line

    I keep getting the following error:

    "run-time error 13 - type mismatch"

    I'll be very grateful for any assistance offered

  2. #2
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Where is NewBase declared? and what is it?
    If wishes were fishes we'd all cast nets.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    Option Explicit

    'Variables to hold Old Base Type and New Base Type

    Private OldBase As Integer
    Private NewBase As Integer

    Hi, thanks. NewBase is an integer and is made general in "Option Explicit"

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Use the immediate window and see what is in optNumber(Index).Tag

  5. #5
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    The tag property must have something in it otherwise it will generate this error

    VB Code:
    1. If OptNumber(index).Tag = "" Then
    2.     'do nothing
    3. Else
    4.         NewBase = OptNumber(index).Tag
    5. End If
    If wishes were fishes we'd all cast nets.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    Originally posted by BrianS
    Use the immediate window and see what is in optNumber(Index).Tag
    What immediate window?

    Also thanks.. the runtime error 13 not longer appears but the calculator does not function properly - when i click one of 4 radio buttons (optNumber) it is meant to convert from one base to another eg binary to decimal etc

    The coding for the actual conversion works ok. but essentially the whole problem lies in the section below:

    Private Sub optNumber_Click(Index As Integer)
    Dim OldNumber As String
    Dim NewNumber As String

    OldNumber = txtNumber.Text

    If optNumber(Index).Tag = "" Then
    'do nothing
    Else
    NewBase = optNumber(Index).Tag
    End If

    Select Case NewBase
    Case 2
    txtNumber.MaxLength = 50
    Case 8
    txtNumber.MaxLength = 17
    Case 10
    txtNumber.MaxLength = 15
    Case 16
    txtNumber.MaxLength = 13
    End Select

    'If Base Type was clicked but no numbers entered then
    'change Old and New Base to the Type selected and exit
    If OldNumber = "" Then
    OldBase = NewBase
    Exit Sub
    End If

  7. #7
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Works find for me, you sure you have the tag property set?
    If wishes were fishes we'd all cast nets.

  8. #8
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    oh I think I know what you want

    add

    txtnumber = OldNumber after the select case
    If wishes were fishes we'd all cast nets.

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    Like this?

    End Select

    txtNumber = OldNumber

    'If Base Type was clicked but no numbers entered then
    'change Old and New Base to the Type selected and exit
    If OldNumber = "" Then
    OldBase = NewBase
    Exit Sub
    End If

    Also how do i set the tag property (if it isn't set already)?

  10. #10
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Yea.... ummm are you possibly mistaking the tag property (which is a value not used by visual basic, it's only there for the user to put "notes", extra data like keys, etc in) with the .caption property (which is used to display the text that is beside the radio button)?
    If wishes were fishes we'd all cast nets.

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    I'm not sure if that's the case because when i change .tag to .caption (as below) then I start getting the runtime error 13 again.

    Like I'd said earlier, the same code snippet work worked as a 'standalone base convertor' however when I integrated it into my scientific calculator code it just refused to run despite the fact it's EXACTLY the same code.

    Private Sub optNumber_Click(Index As Integer)
    Dim OldNumber As String
    Dim NewNumber As String

    OldNumber = txtNumber.Text

    'NewBase = optNumber(Index).Tag

    If optNumber(Index).Caption = "" Then

    'do nothing

    Else

    NewBase = optNumber(Index).Caption

    End If

    (note changing back from .Caption to .Tag causes the runtime error to disappear, however when the radio buttons (optNumber are clicked, nothing happens)

  12. #12
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Heres my code, based on yours.
    Note my radio buttons are called Option1 because I forgot to rename then when adding them to my form

    Now I manually added in the tags to each of the option buttons in the form view.

    VB Code:
    1. Dim oldbase As Integer
    2. Dim newbase As Integer
    3. Private Sub Option1_Click(Index As Integer)
    4.     Dim OldNumber As String
    5.     Dim NewNumber As String
    6.    
    7.     OldNumber = txtnumber.Text
    8.     If Option1(Index).Tag = "" Then
    9.         'do nothing
    10.     Else
    11.         newbase = Option1(Index).Tag
    12.     End If
    13.    
    14.     Select Case newbase
    15.         Case 2
    16.             txtnumber.MaxLength = 50
    17.         Case 8
    18.             txtnumber.MaxLength = 17
    19.         Case 10
    20.             txtnumber.MaxLength = 15
    21.         Case 16
    22.             txtnumber.MaxLength = 13
    23.     End Select
    24.     txtnumber = OldNumber
    25.     'If Base Type was clicked but no numbers entered then
    26.     'change Old and New Base to the Type selected and exit
    27.     If OldNumber = "" Then
    28.         oldbase = newbase
    29.         Exit Sub
    30.     End If
    31.  
    32. End Sub
    If wishes were fishes we'd all cast nets.

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    ok. thanks very much. i think we are almost there. but how did u manually add in the tags for each of the option buttons in form view?

  14. #14
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    I entered the values you have in your select case into the tag properties on the form.
    If wishes were fishes we'd all cast nets.

  15. #15

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    7
    BINGO! Thanks very much! I just realized the same a couple hrs ago. You've been very helpful.

  16. #16
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    No problem dude
    If wishes were fishes we'd all cast nets.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width