Re: can run javascript can't run vbscript - WHY

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jared (ask_me_for_it_at_nospam.com)
Date: 10/11/04


Date: Mon, 11 Oct 2004 12:33:48 -0500

Scott,
    I explained my attitude, and apologized for it, yet you continue... I
will not comment any further, feel free to take one last shot and make it
good.
Jared

"Scott M." <s-mar@nospam.nospam> wrote in message
news:OK6JIE6rEHA.2764@TK2MSFTNGP11.phx.gbl...
> Inline....
>
>
> "Jared" <ask_me_for_it@nospam.com> wrote in message
> news:10ml40gl7kqb5d6@corp.supernews.com...
>> Scott,
>> First, I'm not try to "blast" you, but, if you leave a post that has
>> no explanation of why you believe a certain area is the root of the
>> problem you need to state it. I can come off a little harsh when I don't
>> see any reasoning behind the posts, for that, I apologize. It's not my
>> intention to get in a shouting match with others, It's a pet-peeve of
>> mine that causes the "rough" comments, people need to learn from the
>> mistakes they and others make, to make us all better at what we do. If
>> you know the secret of happiness/world peace/hunger (you pick a topic),
>> but are unwilling to share, how will other implement/learn from the
>> knowledge?
>>
>>>>>>> Change the VBScript so that your function is "Sub...End Sub", not
>>>>>>> "function...end function".
>>
>> Put yourself in Duncan's shoes, what in this comment would make him
>> believe this to is the resolution to the problem? Remember, this is all
>> that you supplied him. How will Duncan and others (myself included) LEARN
>> from this? Where is your reasoning? Why do you believe this to be the
>> problem? What will stop him/us from making the same mistakes in future
>> applications assuming this is the problem?
>
> Duncan, these newsgroups are not substitutes for someone having to know
> and understand a topic on their own. The OP must take some responsibility
> in getting a solution to their problem and understanding it. This is a
> .NET newsgroup and the OP was asking a question that seemed to only be
> about client-side VBScript (not really that relevant to this NG). Instead
> of ignoring the post or just telling the OP he was in the wrong group, I
> gave a brief potential fix for the problem as I saw it. The OP, you or
> anyone else could certainly have taken that and done a simple Google
> search on Function & VBScript and found why what the OP wrote was
> incorrect. Please don't lecture me on how to properly use NG's.
>
>>> It is a method of the window object in the BOM (browser object model,
>>> varies from browser to browser) not the DOM (Document Object Model, set
>>> by the W3C, describes how to programmatically access parts of a markup
>>> document [html or xml] without knowing or caring which is being used).
>>
>> This is why I said "I think", I don't want to come off as authoritative
>> on something I really do not know, I'm not trying to pass myself off as a
>> guru, or an expert in anything, I am only trying to help and learn in the
>> process.
>
> Then it may be wise for you to ask more questions, rather than
> authoritatively tell others that they are wrong, when they are not ("Sub -
> End Sub is not the problem with this. It can be declared function - end
> function.") - - wrong.
>
>> That is whole point of this newsgroup, If the other developers only
>> wanted answers they could use sites like experts-exchange, where people
>> are quick to give a fix, and don't explain the reasoning.
>
> See my first inline response.
>
>>
>>> It may well have been the case since depending on what browser/version
>>> he is using, the VBScript Interpreter may choke on a function that does
>>> not assign itself a value. This is what I was warning him of.
>>
>> You should have stated this in your original post, I would even go as far
>> as to reference to this if you know of one.
>> i.e. IE 4 with WSH 1.0 fail...
>
> Again, this is a VBScript issue, not a .NET one and a little work on your
> or the OP's part could have found this. The reason I can't give you an
> environment that it will/won't work in is because it depends on how the
> code is written. If you try to use the return value of a function that
> doesn't return a value (as the OP's function is set up), you will get an
> error. This is why you don't use Function...End Function when you are not
> returning a value.
>
>>
>>>> What did I say that would insinuate I believed this to be server side
>>>> code?
>>> You said: "The problem is he is trying to use a vbscript msgbox call in
>>> a web form." VBScript is client-side, but web forms are server-side.
>>> Regardless, based on the OP's code, he clearly wrote client-side code in
>>> VBScript, and under those conditions, the use of msgbox() is absolutley
>>> correct and is not the cause of his problem as you stated.
>>
>>I think you are confusing my response with a response post later. The
>>original post, it has no mention of runat=server in any source lines.
>>Thus, I made no mention of server side code and was trying to help
>>troubleshoot on the client side. By stating web form, one can't assume
>>that all processing/formatting is done on the server, I think you just
>>misunderstood me.
>
> I never said anything to you about server-side code. You started asking
> me what you said to make me beilive you were talking about server-side
> code and I simply answered your question. I think you are hung up on
> something I never said to you.
>
> n stated:
>>
>>> I changed the test vbscript to
>>> sub vbtest(sender AS Object, e AS EventArgs)
>>> lbErrorMessage.text = "VB Test" end sub
>>
>> He went on to state that this worked, but, he didn't understand why it
>> won't work in the client side, this is where the server-side discussion
>> started. Now the method has changed entirely, it is no longer a popup,
>> but a property set operation. How can you state that this fixed the
>> problem if the method changed? He also stated that his original problem
>> was still NOT working.
>
> I never stated that this did fix his problem. I think you are confused as
> to who said what. I indicated that he still has a problem because he is
> trying to call a server-side event from client-side code without setting
> some sort of flag.
>
>>
>>> Jared, did you read my response to you and the OP? Instead of blasting
>>> me for trying to clarify what the OP's problem/solution is and letting
>>> you know about the inacurracy of your diagnosis of the problem ("The
>>> problem is he is trying to use a vbscript msgbox call in a web form."),
>>> you could maybe go on to read the last piece of what I wrote, which is
>>> the correct root of the problem and correct solution for it.
>>
>> Pot calling the kettle black?
>> First, I did state in my last post that I was completely wrong about the
>> VBScript msgbox, so that can be put to rest. Regardless, he is using IE
>> 6.0 which I am using and the test page (.html) I wrote works as expected,
>> using a client-side button handler and an <a
>> href="vbscript:functionname()"></a> call, both use the same Function-End
>> Function syntax and both produce the expected results. Do you have any
>> other solutions for Duncan?
>
> I have answered Duncan's question:
>
> Your problem is that you are trying to mix client-side and server-side
> code,
> you are trying to mix JavaScript and VBScript and VB.NET languages.
>
> From an HTML hyperlink, you don't call a vbscript method as you have
> indicated(test), you do it like this: <A
> HREF="#" onClick="test">test</A>. But, even this won't solve your problem
> because you are trying to get a client-side element to fire a server-side
> event and this is a no-no.
>
> What you will need to do is set a "flag" on the client side, submit the
> form
> and during the server processing of the form's postback, check for the
> existence of the flag. If the flag is present, you can run a particular
> server event.
>
> It is clear to me that you would rather bicker over what your expectations
> of how people use NG's, rather than supply people with accurate
> information. It is also clear that your knowledge in this area is
> superficial at best.
>
> A little advice....tone down your redderick and attitutude and you too may
> learn something as you say you would like to. A simple reply to my first
> post of "Why would that cause the problem Scott?" would have worked.
> Instead, you have suggested code that is incorrect or poor design
> repeatedly and started a he said/she said contest, which doesn't have
> anything to do with the OP.
>
>>
>> Jared
>> ----------------------------------------------------
>>
>> "Scott M." <s-mar@nospam.nospam> wrote in message
>> news:%23ZooSixrEHA.3748@TK2MSFTNGP09.phx.gbl...
>>>
>>> "Jared" <ask_me_for_it@nospam.com> wrote in message
>>> news:10mjc171ronir90@corp.supernews.com...
>>>> Scott,
>>>> I know how sub and function work, that wasn't the point I was trying
>>>> to make, if you leave the call function end function it will still work
>>>> assuming the code in the call is correct. While I thought for sure I
>>>> have tried to use the msgbox function to create a popup in previous
>>>> apps I tried it and find that it does work. This is why I originally
>>>> recommended using the alert method of the window object in the first
>>>> place. Also, you noted that alert has no meaning in vbscript. I agree,
>>>> nor does it in javascript. It is part of the window object in the HTML
>>>> DOM (I think).
>>>
>>> It is a method of the window object in the BOM (browser object model,
>>> varies from browser to browser) not the DOM (Document Object Model, set
>>> by the W3C, describes how to programmatically access parts of a markup
>>> document [html or xml] without knowing or caring which is being used).
>>>
>>>>The script block allows us to access these methods. I would still use
>>>>the alert method from within a vbscript tagged script block. My original
>>>>point was you told Duncan that his entire problem was the fact that he
>>>>used function end function, which is not the case,
>>>
>>> It may well have been the case since depending on what browser/version
>>> he is using, the VBScript Interpreter may choke on a function that does
>>> not assign itself a value. This is what I was warning him of.
>>>
>>>>what if he wanted to return the results of the msgbox to one function,
>>>>but not another? Do you propose he create two separate methods?
>>>
>>> No, I would recommend having one function that returns a value and then
>>> a calling line of code could choose to use the return value or not. But
>>> having a function that does not return a value is incorrect usage of the
>>> Function...End Function syntax and in some circumstances CAN cause an
>>> error. This is what I was indicating. This is a matter of proper coding
>>> and not a matter of what's easiest to do.
>>>
>>>>While I agree that he should be using sub, do you dispute the fact that
>>>>it will not fix his problem?
>>>
>>>>As stated above, in some browsers it could very well be the source of
>>>>the problem.
>>>
>>>> Have you tried to use the alert method in a vbscript function call? Try
>>>> it and get back with me, does it work?. What did I say that would
>>>> insinuate I believed this to be server side code?
>>>
>>> You said: "The problem is he is trying to use a vbscript msgbox call in
>>> a web form." VBScript is client-side, but web forms are server-side.
>>> Regardless, based on the OP's code, he clearly wrote client-side code in
>>> VBScript, and under those conditions, the use of msgbox() is absolutley
>>> correct and is not the cause of his problem as you stated.
>>>
>>>> Scott, did you read my response to Duncan?
>>>
>>> Jared, did you read my response to you and the OP? Instead of blasting
>>> me for trying to clarify what the OP's problem/solution is and letting
>>> you know about the inacurracy of your diagnosis of the problem ("The
>>> problem is he is trying to use a vbscript msgbox call in a web form."),
>>> you could maybe go on to read the last piece of what I wrote, which is
>>> the correct root of the problem and correct solution for it.
>>>
>>> ==============
>>> Your problem is that you are trying to mix client-side and server-side
>>> code,
>>> you are trying to mix JavaScript and VBScript and VB.NET languages.
>>>
>>> From an HTML hyperlink, you don't call a vbscript method as you have
>>> indicated(test), you do it like this: <A
>>> HREF="#" onClick="test">test</A>. But, even this won't solve your
>>> problem
>>> because you are trying to get a client-side element to fire a
>>> server-side
>>> event and this is a no-no.
>>>
>>> What you will need to do is set a "flag" on the client side, submit the
>>> form
>>> and during the server processing of the form's postback, check for the
>>> existence of the flag. If the flag is present, you can run a particular
>>> server event.
>>> ==================
>>>
>>>
>>>
>>>>
>>>> Jared
>>>>
>>>> "Scott M." <s-mar@nospam.nospam> wrote in message
>>>> news:Ono7wavrEHA.4004@TK2MSFTNGP10.phx.gbl...
>>>>> Jared,
>>>>>
>>>>> In VB 6.0/VBScript/VB.NET you use Function...End Function when your
>>>>> method is going to return a value, you use Sub...End Sub when your
>>>>> method is not going to return a value. If you use Function...End
>>>>> Function and don't assign a return value to the function, then in the
>>>>> VB world, you are making a Sub.
>>>>>
>>>>> Since the OP's method does not return a value, he should be using
>>>>> Sub...End Sub, not Function...End Function.
>>>>>
>>>>> As for the use of msgbox:
>>>>>
>>>>> The OP has showed us that he is using client-side scripting here, not
>>>>> server side scripting and he has indicated that he is using VBScript
>>>>> as the client-side scripting language. While this is not generally
>>>>> desirable (because only IE supports client-side VBScript), it is
>>>>> perfectly fine if the target client is known to be IE. Now, in the
>>>>> VBScript language there IS a msgbox function that produces the box the
>>>>> OP is looking for. In VBScript, "alert()" has no meaning and would
>>>>> cause an error if used.
>>>>>
>>>>>
>>>>>
>>>>> "Jared" <ask_me_for_it@nospam.com> wrote in message
>>>>> news:10mh5085trmaa93@corp.supernews.com...
>>>>>> Sub - End Sub is not the problem with this. It can be declared
>>>>>> function - end function. The problem is he is trying to use a
>>>>>> vbscript msgbox call in a web form. I explained in another post that
>>>>>> the alert method is part of DOM and not part of javascript (I could
>>>>>> be wrong); anyways, the vbscript call should use the alert method as
>>>>>> well, and not the msgbox call.
>>>>>>
>>>>>> "Scott M." <s-mar@nospam.nospam> wrote in message
>>>>>> news:epUzO6krEHA.1816@TK2MSFTNGP09.phx.gbl...
>>>>>>> Change the VBScript so that your function is "Sub...End Sub", not
>>>>>>> "function...end function".
>>>>>>>
>>>>>>>
>>>>>>> "duncan" <dwang@woodace.co.uk> wrote in message
>>>>>>> news:8fe85207.0410091135.50385a5f@posting.google.com...
>>>>>>>> why does this work :-
>>>>>>>>
>>>>>>>> <HEAD>
>>>>>>>> .....
>>>>>>>> <SCRIPT LANGUAGE="javascript">
>>>>>>>> function test()
>>>>>>>> {
>>>>>>>> alert("test 1")
>>>>>>>> }
>>>>>>>> </SCRIPT>
>>>>>>>> ....
>>>>>>>> </HEAD>
>>>>>>>> <BODY>
>>>>>>>> ...
>>>>>>>> test
>>>>>>>> .....
>>>>>>>> </BODY>
>>>>>>>>
>>>>>>>> but this does not :-
>>>>>>>>
>>>>>>>> <HEAD>
>>>>>>>> .....
>>>>>>>> <SCRIPT LANGUAGE="vbscript">
>>>>>>>> function test()
>>>>>>>> msgbox("VB Test")
>>>>>>>> end function
>>>>>>>> </SCRIPT>
>>>>>>>> .....
>>>>>>>> </HEAD>
>>>>>>>> .....
>>>>>>>> <BODY>
>>>>>>>> ...
>>>>>>>> test
>>>>>>>> ...
>>>>>>>> </BODY>
>>>>>>>>
>>>>>>>> As you can see the only real difference is I have changed
>>>>>>>> JavaScript
>>>>>>>> to be vbscript and this is the problem. I don't even get a script
>>>>>>>> error reported by IE6 when I try to run the VB version. I tried
>>>>>>>> varying vbscript eg vb, vbs but nothing happens.
>>>>>>>>
>>>>>>>> Why can I not run my vb function just like I can Javascript. It
>>>>>>>> defies logic (or at least mine!! which says a simple name change
>>>>>>>> should not cause this problem)
>>>>>>>>
>>>>>>>> What I am trying to achieve is to run my actual code as a client
>>>>>>>> side
>>>>>>>> script - with NO postback. I have managed to run some JavaScript
>>>>>>>> without causing a post back using the <A>...</A> and I can run my
>>>>>>>> vb
>>>>>>>> actual code from a <ASP:BUTTON> but this causes a postback. I
>>>>>>>> want
>>>>>>>> to use vb/vbscript as I am familiar with vb and want to get my
>>>>>>>> pages
>>>>>>>> working asap.
>>>>>>>>
>>>>>>>> One very frusttrated newbie (to ASP.NET / VB.NET)
>>>>>>>>
>>>>>>>>
>>>>>>>> Duncan
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Quantcast