|
-
Feb 12th, 2004, 10:44 AM
#1
Thread Starter
New Member
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
-
Feb 12th, 2004, 10:51 AM
#2
Fanatic Member
Where is NewBase declared? and what is it?
If wishes were fishes we'd all cast nets.
-
Feb 12th, 2004, 10:55 AM
#3
Thread Starter
New Member
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"
-
Feb 12th, 2004, 11:00 AM
#4
Frenzied Member
Use the immediate window and see what is in optNumber(Index).Tag
-
Feb 12th, 2004, 11:00 AM
#5
Fanatic Member
The tag property must have something in it otherwise it will generate this error
VB Code:
If OptNumber(index).Tag = "" Then
'do nothing
Else
NewBase = OptNumber(index).Tag
End If
If wishes were fishes we'd all cast nets.
-
Feb 12th, 2004, 11:23 AM
#6
Thread Starter
New Member
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
-
Feb 12th, 2004, 11:34 AM
#7
Fanatic Member
Works find for me, you sure you have the tag property set?
If wishes were fishes we'd all cast nets.
-
Feb 12th, 2004, 11:36 AM
#8
Fanatic Member
oh I think I know what you want
add
txtnumber = OldNumber after the select case
If wishes were fishes we'd all cast nets.
-
Feb 12th, 2004, 11:43 AM
#9
Thread Starter
New Member
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)?
-
Feb 12th, 2004, 11:46 AM
#10
Fanatic Member
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.
-
Feb 12th, 2004, 12:12 PM
#11
Thread Starter
New Member
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)
-
Feb 12th, 2004, 12:20 PM
#12
Fanatic Member
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:
Dim oldbase As Integer
Dim newbase As Integer
Private Sub Option1_Click(Index As Integer)
Dim OldNumber As String
Dim NewNumber As String
OldNumber = txtnumber.Text
If Option1(Index).Tag = "" Then
'do nothing
Else
newbase = Option1(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
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
End Sub
If wishes were fishes we'd all cast nets.
-
Feb 12th, 2004, 12:44 PM
#13
Thread Starter
New Member
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?
-
Feb 12th, 2004, 05:48 PM
#14
Fanatic Member
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.
-
Feb 12th, 2004, 08:21 PM
#15
Thread Starter
New Member
BINGO! Thanks very much! I just realized the same a couple hrs ago. You've been very helpful.
-
Feb 12th, 2004, 08:23 PM
#16
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|