By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

Please I need Help Urgently on this

P: 5
I have these codes that are supposed to load control arrays (days of week), there is only one textbox visible at design time, but I want to use control array to initialize the other six textboxes in order to display (Monday-Sunday) according to local system settings. But when I compile it only shows the error message and when i click OK, it then shows the form with the number "70" on it.
Please could anyone help me figure out what might be wrong and the solution? Thanks in advance


visual basic code:--------------------------------------------------------------------------------Private Sub Form_Load()
Call GetWeekDay
Call Update_Controls
End Sub


Private Function GetWeekDay()
On Error GoTo Error_Handle
Weekday(0) = WeekdayName(vbUseSystemDayOfWeek)
Weekday(1) = WeekdayName(vbTuesday)
Weekday(2) = WeekdayName(vbWednesday)
Weekday(3) = WeekdayName(vbThursday)
Weekday(4) = WeekdayName(vbFriday)
Weekday(5) = WeekdayName(vbSaturday)
Weekday(6) = WeekdayName(vbSunday)

Dim i As Integer

For i = 0 To 5
Load txtwkdayname(txtwkdayname.UBound + 1)
txtwkdayname(txtwkdayname.UBound).Top = (txtwkdayname(i).Top + txtwkdayname(i).Height) + 8
txtwkdayname(txtwkdayname.UBound).Visible = True
Next i
Error_Handle:
MsgBox "Please Check Your Codes"

End Function

Private Sub Update_Controls()

Dim i As Integer

For i = 0 To txtwkdayname.UBound
txtwkdayname(i).Text = Weekday(i) & i
Next i

End Sub--------------------------------------------------------------------------------


When I change the Error message from "Error handler to "On Error Reume Next" I got a diferent result:
Six extra txtboxes were added as I wanted, but then there were numbers from 7(the default textbox), 1,2...6. I wanted them to display, from Monday-Sunday in the local system form.
What should I do to correct this?

Also How Can I claculate and display lunch hours(in and Out)?
Nov 26 '06 #1
Share this Question
Share on Google+
8 Replies


100+
P: 1,646
I have these codes that are supposed to load control arrays (days of week), there is only one textbox visible at design time, but I want to use control array to initialize the other six textboxes in order to display (Monday-Sunday) according to local system settings. But when I compile it only shows the error message and when i click OK, it then shows the form with the number "70" on it.
Please could anyone help me figure out what might be wrong and the solution? Thanks in advance


visual basic code:--------------------------------------------------------------------------------Private Sub Form_Load()
Call GetWeekDay
Call Update_Controls
End Sub


Private Function GetWeekDay()
On Error GoTo Error_Handle
Weekday(0) = WeekdayName(vbUseSystemDayOfWeek)
Weekday(1) = WeekdayName(vbTuesday)
Weekday(2) = WeekdayName(vbWednesday)
Weekday(3) = WeekdayName(vbThursday)
Weekday(4) = WeekdayName(vbFriday)
Weekday(5) = WeekdayName(vbSaturday)
Weekday(6) = WeekdayName(vbSunday)

Dim i As Integer

For i = 0 To 5
Load txtwkdayname(txtwkdayname.UBound + 1)
txtwkdayname(txtwkdayname.UBound).Top = (txtwkdayname(i).Top + txtwkdayname(i).Height) + 8
txtwkdayname(txtwkdayname.UBound).Visible = True
Next i
Error_Handle:
MsgBox "Please Check Your Codes"

End Function

Private Sub Update_Controls()

Dim i As Integer

For i = 0 To txtwkdayname.UBound
txtwkdayname(i).Text = Weekday(i) & i
Next i

End Sub--------------------------------------------------------------------------------


When I change the Error message from "Error handler to "On Error Reume Next" I got a diferent result:
Six extra txtboxes were added as I wanted, but then there were numbers from 7(the default textbox), 1,2...6. I wanted them to display, from Monday-Sunday in the local system form.
What should I do to correct this?

Also How Can I claculate and display lunch hours(in and Out)?
Hi looks like you have some global variables defined somewhere not in this code snippet. Could you also post these declarations?
Thanks
Nov 27 '06 #2

Expert 5K+
P: 8,434
I think you have failed to Exit Sub before your Error_Handle label.
Nov 27 '06 #3

P: 5
I think you have failed to Exit Sub before your Error_Handle label.
If I Exit SUB, like you said I get this message: "Compiler Error:label "On Error GoTo Error_Handle" not defined
Nov 27 '06 #4

Expert 5K+
P: 8,434
If I Exit SUB, like you said I get this message: "Compiler Error:label "On Error GoTo Error_Handle" not defined
I'm not sure we're talking about the same thing (plus, I got Sub and Function mixed up). Try this
Expand|Select|Wrap|Line Numbers
  1. Private Function GetWeekDay()
  2. On Error GoTo Error_Handle
  3. Weekday(0) = WeekdayName(vbUseSystemDayOfWeek)
  4. Weekday(1) = WeekdayName(vbTuesday)
  5. Weekday(2) = WeekdayName(vbWednesday)
  6. Weekday(3) = WeekdayName(vbThursday)
  7. Weekday(4) = WeekdayName(vbFriday)
  8. Weekday(5) = WeekdayName(vbSaturday)
  9. Weekday(6) = WeekdayName(vbSunday)
  10.  
  11. Dim i As Integer
  12.  
  13. For i = 0 To 5
  14.   Load txtwkdayname(txtwkdayname.UBound + 1)
  15.   txtwkdayname(txtwkdayname.UBound).Top = (txtwkdayname(i).Top + txtwkdayname(i).Height) + 8
  16.   txtwkdayname(txtwkdayname.UBound).Visible = True
  17. Next i
  18. Exit Function
  19. Error_Handle:
  20. MsgBox "Please Check Your Codes"
  21.  
  22. End Function
Oh, and a question (not terribly important, I'm just curious). Since this returns no value, is there any particular reason why it's a function rather than a Sub?
Nov 27 '06 #5

P: 5
Hi looks like you have some global variables defined somewhere not in this code snippet. Could you also post these declarations?
Thanks
Hi, thanks but I didnt declare any variable except the control variable(i) for looping, well, even as I added Weekday as variable I get these results(7,1,2,3,4,5,6). I dont know why its giving numbers instead of weekdays in local language. Thats the problem i am having at the moment. Here is how its been improved on now:

Option Explicit
Private Sub Form_Load()
Call GetWeekDay
Call Update_Controls
End Sub



Private Function GetWeekDay()
On Error Resume Next................................'I had to change this in order to
'make it run without error
Dim Weekday(6) As Date...... 'Gives same reult whether or not present'
Weekday(0) = WeekdayName(vbUseSystemDayOfWeek)
Weekday(1) = WeekdayName(vbTuesday)
Weekday(2) = WeekdayName(vbWednesday)
Weekday(3) = WeekdayName(vbThursday)
Weekday(4) = WeekdayName(vbFriday)
Weekday(5) = WeekdayName(vbSaturday)
Weekday(6) = WeekdayName(vbSunday)

Dim i As Integer

For i = 0 To 5
Load txtwkdayname(txtwkdayname.UBound + 1)
txtwkdayname(txtwkdayname.UBound).Top = (txtwkdayname(i).Top + txtwkdayname(i).Height) + 8................................................. .......................'needed to avoid cluttering
txtwkdayname(txtwkdayname.UBound).Visible = True
Next i


End Function

Private Sub Update_Controls()

Dim i As Integer

For i = 0 To txtwkdayname.UBound
txtwkdayname(i).Text = Weekday(i)
Next i

End Sub
Nov 27 '06 #6

Expert 5K+
P: 8,434
See my message just before willakawill's, about Exit Function.

Also, it seems as though you might need to define an array somewhere called Weekday(0 to 7). Either at the form level, or in a module as Public.
Nov 27 '06 #7

Expert 5K+
P: 8,434
See my message just before willakawill's, about Exit Function.

Also, it seems as though you might need to define an array somewhere called Weekday(0 to 7). Either at the form level, or in a module as Public.
Sorry, correction. Your array Weekday() is defined as Date - make it String.
Nov 27 '06 #8

P: 5
Sorry, correction. Your array Weekday() is defined as Date - make it String.
Thanks I have resolved the problem
Nov 27 '06 #9

Post your reply

Sign in to post your reply or Sign up for a free account.