?
Solved

Converting a String into a Function  (VB.NET)

Posted on 2003-02-26
8
Medium Priority
?
219 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
[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
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
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!

 

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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

800 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