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?
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 ...
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
Re: read .caption from a button
Maybe you could post some more of your code and the line that errors out if possible.
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.
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.
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]
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?