|
-
May 4th, 2000, 05:23 AM
#1
Thread Starter
Addicted Member
Hi everyone,
this is a bit of a strange question and I don't think you can do it, but I thought I'd ask anyway.
say you have a text file which contains vb code, is there anyway to say import that text file into your program to say turn it into a sub?
for example say you had a sub called lets say crypto
sub crypto
end sub
and that was all we had for the particular sub, now the text file we have, has the following code in it lets say:
dim crypt as string
dim cryp as string
cryp = text2.text
crypt = instr(1,cryp,"blah",vbTextCompare)
if crypt <>0 then
'more stuff here etc
end sub
now is there anyway to make the sub crypto imports that information???
thanx for any help.
-
May 4th, 2000, 05:32 AM
#2
Hyperactive Member
Why not just copy and paste?
-
May 4th, 2000, 05:35 AM
#3
Hyperactive Member
I'm not sure but I think he means during runtime.
"People who think they know everything are a great annoyance to those of us who do."
-
May 4th, 2000, 05:52 AM
#4
Frenzied Member
no, I think you can do it in Java though.
-
May 4th, 2000, 07:00 AM
#5
Thread Starter
Addicted Member
Yeah I mean at run time.
Yeah I mean at run time, I didn't think you could, it was just that my program gets data from a webpage, and if the webpages changes certain things in their layout and things then the way I get the data is invalid, and I have to make a new build sort of thing, I was just thinking instead of that maybe I could upload a text file to my site containg the latest code for extracting the code, and then download the text with the inet control, and import it into that sub, instead of having to keep making new builds sort of thing.
thanx for replying.
-
May 4th, 2000, 07:09 AM
#6
Hyperactive Member
There are compiler issues trying to do what you've asked in VB alone, but a VB-VBA approach may work. Make sure your References include "Microsoft Visual Basic for Applications Extensibility"
For demo sake, say you have textfile named mystuff.txt in c:\tmp that has:
Attribute VB_Name = "Module10"
Public Function Gee()
MsgBox "hello world"
End Function
Now in VB:
Private Sub JamCodeByWayOfOmaha_VBA()
Dim xlapp As Object 'Excel.Application
Dim xlbook As Object 'Excel.Workbook
Dim xlmodule As Object 'VBComponents
Dim xlmodule2 As Object
Dim strCode As String
' Start Excel
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = false ' value may have to be true, I'm winging this.
' Add new workbook
Set xlbook = xlapp.Workbooks.Add
' Add a module
Set xlmodule = xlbook.VBProject.VBComponents.Add(vbext_ct_StdModule)
' Add text by line to a macro in module
strCode = "sub MyMysteryMac()" & vbCr & _
" msgbox ""Hmm."" " & vbCr & "end sub"
xlmodule.CodeModule.AddFromString strCode
' or save some grief and import from textfile
Set xlmodule2 = xlbook.VBProject.VBComponents
xlmodule2.Import "c:\tmp\mystuff.txt"
' Run macros
xlapp.Run "MyMysteryMacro"
xlapp.Run "Gee"
' Pause to pat self on back and watch purists' heads explode...
MsgBox "All done, click to continue...", vbMsgBoxSetForeground
' Release modules & clean up
Set xlmodule = Nothing: Set xlmodule2 = Nothing
xlbook.Saved = false
xlapp.Quit
Set xlbook = Nothing: Set xlapp = Nothing
End Sub
Hope this helps.
[Edited by Mongo on 05-04-2000 at 08:18 PM]
-
May 4th, 2000, 05:09 PM
#7
Thread Starter
Addicted Member
THANKS!!!!
Thanx Mongo, I really didn't think that it was possible, I thought it was a bit stupid me even asking that question, great code.
But is there anyway to say put the function into a module you already have in your .exe? or make a module at run time in the exe and put the code in that sort of thing so that you can run the function in the module along side your form so you can send things to the form?
thanx again.
[Edited by Crypt on 05-05-2000 at 06:15 AM]
-
May 4th, 2000, 11:58 PM
#8
Hyperactive Member
At runtime there's plenty of deadwood space in a VB exe where you can write characters, but no, to my pea-brain knowledge, you cannot add function/sub functionality via a pre-post-compile methodology. You could expand the example I gave to store values on a worksheet and then read them from you VB app for use on a form or whatever.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|