Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

error in function

'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
anshuma
Asked:
anshuma
  • 3
  • 2
  • 2
  • +4
5 Solutions
 
Erick37Commented:
Change the call to this:

Call Module1.labelloader(Label1) 'With Call keyword

=or=

Module1.labelloader Label1  'Without the parenthesis

Hope it helps!

0
 
Erick37Commented:
P.S

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

Call labelloader(Label1)

=or=

labelloader Label1
0
 
hesCommented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
anvCommented:
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
 
_agj_Commented:
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
 
Ioannis ParaskevopoulosCommented:
Private Sub Form_Load()
      Form1.Show
      module1.labelloader Label1
End Sub
0
 
anshumaEngineeringAuthor Commented:
"anv" seems more correct as I am passing the array of controls, any suggestions
0
 
Ioannis ParaskevopoulosCommented:
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
 
anvCommented:
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
 
EDDYKTCommented:
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
 
anvCommented:
hi EDDYKT

dont u think object and Control (in this case) wont make any difference..??
0
 
EDDYKTCommented:
Any control can be referenced by object

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now