It seems to me that they're not possible in VB 6... am I incorrect?
Printable View
It seems to me that they're not possible in VB 6... am I incorrect?
Direct polymorphism (mutation of data within a program to generate a file that runs the same but is internally different) is impossible because Windows locks a file that is being run, so no. However, using program A (the main program) to write a stub program (we'll call it program B) then terminating and passing control to program B then program B doing the changes...that's possible :-)
You should look at:
http://en.wikipedia.org/wiki/Polymorphic_code
http://en.wikipedia.org/wiki/Self-modifying_code
Note that the second link points out CLEARLY why this is not possible..."Because of the security implications of self-modifying code, some operating systems go to lengths to rule it out."
I think I may be confused about polymorphism, then.
I was wanting to do two bits of code, depending on the data sent to them.
Function diceRoller(ByVal numOne as Interger)
and
Function Dicroller (ByVal numOne as Interger, ByVal numTwo as Inerger)
That kinda thing.
I don't think VB6 supported overloading values.
Overloading! That's it.
So we've decided Overloading and direct Polymorphism are out. What about Recursion?
Function DiceRoller(ByVal numOne As Integer, Optional ByVal numTwo As Integer = 0)
See 'Function Statement' in VB help files
VB6 allows for optional values, so you could do
Function Diceroller (ByVal numOne as Interger, Optional ByVal numTwo as Inerger)
you could then do Diceroller(1,2) or Diceroller(1,) (or something like that)
Edit: Damn, someone else got there first :-)
You guys are awesome. :)
Any scoop on "Recursion"?
If you give more information about what you're trying to achieve, we might be able to make other suggestions about ways of going about it. But glad we could help :-)
I'm just asking if it's possible, really. :P
I remember many problems I had with it in Java, but I also recalled that when I had taken VB the year before, it wouldn't all fuctions to call themselves.
I really liked the resursive sorting and such that it does. Highly inefficient, but very fast.
I'm not sure what you mean by recursion. I know what recursion is, but I've never personally written anything that recursively does stuff in a program...I do my best to be efficient :-)
Edit: However, I *have* seen something recently that uses a similar "recursion" to the one in http://en.wikipedia.org/wiki/Recursion for the factorial...it was posted here in classic VB so I can assume that recursion is doable in VB in much the same way as on wikipedia
It was inefficient in a good way... I think it's binary sorting or something, I can't really remember.
I know it used recursion. :P I believe my instructor said it was one of the fastest ways to sort, it was... just inefficient.
Recursion (by definition) is simple:
Of course, this example is a silly way to code a simple loop, but it demonstrates recursion at a very basic level.VB Code:
Sub SayHello(ByVal NumTimes As Integer) If NumTimes > 0 Then MsgBox "Hello!" NumTimes = NumTimes - 1 SayHello(NumTimes) End If End Sub