Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Converting a String into a Function  (VB.NET)

Posted on 2003-02-26
8
Medium Priority
?
220 Views
Last Modified: 2010-05-01
Hello,

I have an problem. I have an string datatype like this.


Dim sFunctionString as String
sFunctionString = "Msgbox(" & sMessage & ")"

so how can i convert this string to an executable function and call it?


Thank you for your support

Joerg Bonsack
0
Comment
Question by:Joerg_Bonsack
8 Comments
 
LVL 5

Expert Comment

by:bob_online
ID: 8025966
In VB, you can't.

YOu'd need to do somthing like

If left$(sFunctionString, 6) = "Msgbox" Then
   Msgbox ...
end if

And that kind of defeats the purpose
0
 
LVL 2

Expert Comment

by:IeuanJ
ID: 8026297
I dont think you can in VB, definately could in ANSI C, If i can get a hold of the code perhaps I could work some conversion or other but I wouldnt hold out too much hope.

Could you not just parse the string with an if/case statement for each possibilty as below ?

Dim strTemp As String
Dim strProcedure As String
Dim strParameter As String
Dim pointer As Integer

strTemp = "msgbox(""Hello"")"
pointer = InStr(1, strTemp, "(", vbTextCompare)

strProcedure = Left(strTemp, pointer - 1)

strTemp = Right(strTemp, Len(strTemp) - pointer)
pointer = InStr(1, strTemp, ")", vbTextCompare)
strTemp = Left(strTemp, pointer - 1)

strParameter = Replace(strTemp, Chr(34), "", 1, , vbTextCompare)

If strProcedure = "msgbox" Then
    MsgBox strParameter
End If
0
 
LVL 3

Expert Comment

by:schworak
ID: 8026858
How many different commands are you trying to place in a string like that?

If it is always msgbox then there are better ways.

If there are a limited number of commands, you may consider a case statement instead of IF THEN ELSE.

With a little more info, I may be able to offer better help.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Joerg_Bonsack
ID: 8026962
That is not the problem with if then else etc.


Let me explain it again:

I have a Active Searching Routine which is descibe like so:
 
'The namespace is Searcher
' The Properties are: folder
'                      item(smth.)

Public function Count_Sub_Folders(nCounter as integer)
Dim sFunction_Call as string
Dim nResult as integer
sFunction_Call = "Searcher."    
      for x = 1 to nCounter
           sFunction_Call = sFunction_Call & ".Folder.Item(" & nCounter & ")"
     next nCounter
sFunction_Call = sFunction_Call & ".count()"
'Here comes the problem:
' I have a builded string like:
searcher.folder.item(1).folder.item(2).folder.item(3)count
NResult= 'Here i need the function call'
end Function

The function must be filled dynamiclly with properties.

Thank you for your support
0
 
LVL 2

Expert Comment

by:IrishPheremone
ID: 8064728
Try this...

On a form or in a class (cannot do in a module)

' Call string function
Call CallByName(Me, sFunctionString, vbMethod)


Example on a form:

Public Sub Test(byVal sMessage as string)

 Call MsgBox(sMessage)

End Sub

Private Sub cmdButton_Click()

Call CallByName(Me, "Test", vbMethod, "Message 2B Displayed")

End Sub
0
 

Expert Comment

by:CleanupPing
ID: 8940451
Joerg_Bonsack:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8973023
Joerg_Bonsack, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9668040
PAQed - no points refunded (of 75)

Computer101
E-E Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

580 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