Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

error in function

Posted on 2004-10-17
12
Medium Priority
?
175 Views
Last Modified: 2010-05-02
'I have defined the following sub in Module1
__________________________________________
Public Sub labelloader(objname As Label)

With objname
.Caption = "Hello"
End With

End Sub
______________________

If I call

Private Sub Form_Load()
Module1.labelloader (Label1)
End Sub

on my form I have a label called Label1

-----------------------

but on loading I am getting a type mismatch error. The pupose of above sub is that I need to dynamically load the names of labels on runtime instead of me typing there names everywhere in the design. I also need to know a function that splits a string based on a delimiter like * and stores it in an array. Please help
0
Comment
Question by:anshuma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +4
12 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12333644
Change the call to this:

Call Module1.labelloader(Label1) 'With Call keyword

=or=

Module1.labelloader Label1  'Without the parenthesis

Hope it helps!

0
 
LVL 32

Expert Comment

by:Erick37
ID: 12333652
P.S

Since the function is Public, you do not need to use Module1...

Call labelloader(Label1)

=or=

labelloader Label1
0
 
LVL 20

Accepted Solution

by:
hes earned 1000 total points
ID: 12333686
Change it to:

Private Sub Form_Load()
 
Call labelloader(Label1)

End Sub


For the second use the split function

Dim NewArray
Dim MyString as String
MyString = "12345*67890"
NewArray = Split(MyString,"*")
' NewArray(0) now contains "12345"
' NewArray(1) contains "67890"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Assisted Solution

by:anv
anv earned 400 total points
ID: 12336129
try the following argument in the function
Public Sub labelloader(objname As control)

With objname
.Caption = "Hello"
End With

End Sub

private sub Form_Load()
  labelloader(me.label1)
end sub
0
 
LVL 7

Assisted Solution

by:_agj_
_agj_ earned 200 total points
ID: 12336291
Public Sub labelloader(Byref objname As Label) should help

i dont suggest the 'As Control' technique since it leads to ambiguity and more memory usage...
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 12337044
Private Sub Form_Load()
      Form1.Show
      module1.labelloader Label1
End Sub
0
 

Author Comment

by:anshuma
ID: 12337177
"anv" seems more correct as I am passing the array of controls, any suggestions
0
 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 200 total points
ID: 12337327
As for the function you need,Split is the one you're looking for.


Dim myArray() As String
Dim mystring As String

mystring = "Try*this*function"
myArray = Split(mystring, "*")
0
 
LVL 10

Expert Comment

by:anv
ID: 12337369
hi for second part of ur question..


Dim myArray
Dim mystring As String

mystring = "Try*this*function"
myArray = Split(mystring, "*")

actually split returns a variant array...
..so if u give

Dim myArray() As String
it will give an error here..

try using this code...
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 200 total points
ID: 12337560
Use object

ie

im module

Public Sub labelloader(objname As Object)
Dim lbl As Object

For Each lbl In objname
    With lbl
        .Caption = "Hello"
    End With
Next
End Sub


in form

Private Sub Form_Load()
labelloader Label1
End Sub
0
 
LVL 10

Expert Comment

by:anv
ID: 12337577
hi EDDYKT

dont u think object and Control (in this case) wont make any difference..??
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12337632
Any control can be referenced by object

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question