|
-
Mar 6th, 2006, 09:38 AM
#1
Thread Starter
Lively Member
read .caption from a button
I want my program to read from a label. so that when i click on a button it reads its caption and changes somthing in a modual.
I have this modual
VB Code:
Public Type DataType
TodayMonth As String
TodayMonthNum As Integer
TodayDay As Integer
username As String
ChosenMonthNum As Integer
ChosenMonth As String
ChosenDay As Integer
TotalUsers As Integer
End Type
Public Data(0) As DataType
and this is the code inside each button
VB Code:
Dim TodayDate As Integer
TodayDate = FriA.Caption
Data(0).TodayDay = TodayDate
but when i run the program i get this error.
Run Time Error "424":
Object required
So can anyone see a problem with my code, or is it that you can't read captions this way, and if thats the case how do i read captions?
-
Mar 6th, 2006, 09:47 AM
#2
New Member
Re: read .caption from a button
As I see you want to read caption and save it to an Integer so you have to use Val() function for this ...
-
Mar 6th, 2006, 09:56 AM
#3
Fanatic Member
Re: read .caption from a button
I don't know how you're getting an 'Object required' error because you have a Type Mismatch problem. When I pasted your code into a project with one button, one label and one module, I got a Type Mismatch error.
The mismatch error occurs because the .Caption property of the Label control is a String and you are trying to assign it to TodayDate, which you have declared as an Integer.
Try this following code, it worked fine for me [changes in bold]:
VB Code:
'MODULE CODE:
Public Type DataType
TodayMonth As String
TodayMonthNum As Integer
TodayDay As [B]Date[/B]
username As String
ChosenMonthNum As Integer
ChosenMonth As String
ChosenDay As Integer
TotalUsers As Integer
End Type
Public Data(0) As DataType
'FORM CODE:
Private Sub Command1_Click()
Dim TodayDate As [B]Date[/B]
TodayDate = [B]CDate([/B]Label1.Caption[B])[/B]
Data(0).TodayDay = TodayDate
[B]MsgBox Data(0).TodayDay[/B]
End Sub
Private Sub Form_Load()
[B]Label1.Caption = Date[/B]
End Sub
Do canibals not eat clowns because they taste funny? 
-
Mar 6th, 2006, 09:57 AM
#4
Fanatic Member
Re: read .caption from a button
Maybe you could post some more of your code and the line that errors out if possible.
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Mar 6th, 2006, 10:07 AM
#5
Fanatic Member
Re: read .caption from a button
@doofusboy why did you change everything to dates? He's trying to get an interger of some kinda from the caption on a button not a label. I'm not sure why he's doing that but he has some kind of plan. really all he needed to change so that he always gets an integer from a button is to do this TodayDate = CInt(Val(friA.caption)). You might be right but that's not the way i read what he's posted so far.
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Mar 6th, 2006, 10:23 AM
#6
Thread Starter
Lively Member
Re: read .caption from a button
space_monkey your right, it has to be an integer as it does indeed have a plan. I'll try your TodayDate = CInt(Val(friA.caption)) idea and get back to you.
-
Mar 6th, 2006, 10:25 AM
#7
Thread Starter
Lively Member
Re: read .caption from a button
Nope, I tried your idea space monkey (TodayDate = CInt(Val(friA.caption))) but i still get the same error.
The line that errors out is this one:
VB Code:
[b]TodayDate = FriA.Caption[/b]
-
Mar 6th, 2006, 10:27 AM
#8
Fanatic Member
Re: read .caption from a button
What is the caption on the button at that moment? and when in the process of your program are you calling this function?
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
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
|