VBScript Syntax Highlighting in Web Page - vbscript

Single Code Comment for Visual Basic Script (VBScript) seems to be not working , i am using
Google-code-prettify
https://code.google.com/p/google-code-prettify/
For more details please see this fiddle :
http://jsfiddle.net/dekajp/27skU/1/
<div>
<pre class="prettyprint lang-vb">
' Variable Declaration
Dim szToken
Dim oXMLHTTP
Dim szBaseUri, szUri
szToken ="Please see Logon code example for how to obtain a Token"
' set the base URI path
</pre>
</div>
Looks like the single quote comment is not working or am i missing something ?

I'm not familiar with the tool. I am familiar with VB and VB.net you're using but see if this syntax works better for you. AHH... also... you can't use ' unless you're using straight VB programming. You must exit your ' with an addition ' at the end. Looking at Fiddle... all your Declarations and szToken were all highlighted as comments.
<div>
<pre class="prettyprint lang-vb">
<!--Variable Declaration-->
Dim szToken as String
Dim oXMLHTTP
Dim szBaseUri, szUri
szToken.text = ("Please see Logon code example for how to obtain a Token")
<!--set the base URI path-->
</pre>
</div>

I have similar situation. I removed run-prettify.js script and added prettify.js + lang-vb.js, and it helped. It's still not perfect, so I'm figuring out how to modify it, but. Comments are working great.

Related

Trying to set a copy to clipboard link in blogger blog1 widget

Im trying to configure a copy link to clipboard in my home page in blogger for each different article (data:post.url), at the end of other links to social webs, but I've not luck with the sintaxis.
This is what I would like to obtain:
<a href='javascript:getlink("https://www.venalacocina.com");'>
And this is the code what I'm trying to write to obtain those result
<a class='copi' expr:href='"javascript:getlink(\""+ data:post.url + "\");' id='btnCopiar'>
I'm lost with the appropriate use of " and " ¿how many and where should I use them to set the correct code?
¿Would someone give me the correct code correctly written?
thanks a lot in advance
In the end I did it; it was just a question of time.
I just changed and simplified the expression calling directly getlink() function and this is the result working perfectly for me:
<a class='copi' expr:onclick='"getlink(&apos;"+ data:post.url + "&apos;);"' id='btnCopiar'>

Insert Property of Picture Class

I have read all of the questions on here about this topic and none of them provided me with a workable solution, so I'm asking this one.
I am running a legitimate copy of Excel 2013 in Windows 7. I record a macros where I insert a picture, and in the open file dialog I paste this URL: http://ecx.images-amazon.com/images/I/41u%2BilIi00L._SL160_.jpg (simply a picture of a product on Amazon). This works as expected.
The resulting macros looks like this:
Sub insertImage()
'
' percent Macro
'
'
ActiveSheet.Pictures.Insert( _
"http://ecx.images-amazon.com/images/I/41u+ilIi00L._SL160_.jpg").Select
End Sub
However, when I attempt to run this, the Insert line breaks with the following error:
Run-time error '1004':
Unable to get the Insert property of the Picture class
I am trying to insert a number of pictures into an excel document and I am using the ActiveSheet.Pictures.Insert method to do this. I have been experiencing this issue there, so I recreated it in a way others could replicate to facilitate getting an answer...
An interesting thing to note is:
http://ecx.images-amazon.com/images/I/41u%2BilIi00L._SL160_.jpg 'This is what I pasted
http://ecx.images-amazon.com/images/I/41u+ilIi00L._SL160_.jpg 'This is what the recorded macros recorded
It looks like Excel automatically resolved the %2B to a +. I tried making that change, but to no success.
Another interesting thing to note is that sometimes this does work and sometimes it doesn't. This url is a case where it does not work. Here's one where it does: http://ecx.images-amazon.com/images/I/51mXQ-IjigL._SL160_.jpg
Why would Excel generate a macros it can't run? More importantly, how can I avoid this error and get on with my work!? Thanks!
Try this workaround:
Sub RetrieveImage()
Dim wsht As Worksheet: Set wsht = ThisWorkbook.ActiveSheet
wsht.Shapes.AddPicture "http://ecx.images-amazon.com/images/I/41u+ilIi00L._SL160_.jpg", _
msoFalse, msoTrue, 0, 0, 100, 100
End Sub
All fields are required, which is kind of a bummer since you cannot get the default size. The location offsets and sizes are in pixels/points. Also, the % turning to + is just alright, as % would cause it to be not recognized (dunno why).
Result:
Let us know if this helps.
I'm experiencing the same issue.
After some digging I found out Excel does a HTTP HEAD request before getting the image.
If this HEAD request is unsuccessful Excel will return the exact error messages mentioned in this discussion.
Your could easily test this using Fiddler.

Reading strings in VBScript

I want to modify my function that strips the tag from the value of a database record in the title of French pages:
Function removeSup(strToRemove)
strToRemove = Replace(strToRemove,"<sup>","(")
strToRemove = Replace(strToRemove,"</sup>",")")
response.Write(strToRemove)
End Function
so that it can read the contents of the tag. If the contents is a ® or a ™, then do nothing, but if it's MD or MC, then do the replace.
I just haven't figured out how to read strings with VBScript so is this something that I should do with VBScript or have it passed to jQuery to do it?
You could work with Regular Expressions but if i understand what you mean the you can do it as below.
Jquery is javascript only, if this is for web, best not to mix vbscript and javascript unless realy necessary.
Function removeSup(strToRemove)
strToRemove = Replace(strToRemove,"<sup>MD</sup>","(MD)")
strToRemove = Replace(strToRemove,"<sup>MC</sup>","(MD)")
response.Write(strToRemove)
End Function

Need advice on this very odd error

I am trying to establish connection to a database through:
Dim sqCon As SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;Database=MegaDatabase;Integrated_Security=SSPI")
The problem is only on this line where it tells me that:
Array bounds cannot appear in type specifiers
The same problem does NOT appear in any of my other projects though I use this same format.
I need someone to tell me what exactly is wrong with this and how may I solve this.
Thanks for reading.
That (original version, now changed) doesn't look anything like valid syntax. There's no opening " character and there's too many ) characters at the end.
However, even with the fixes, I think what you probably wanted to do was to dim it as a new variable, something like:
Dim sqCon As New SqlConnection ("DataSource=...")
use the New keyword
Dim sqCon As New SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;Database=MegaDatabase;Integrated_Security=SSPI")

how to programmatically check protection on a word document vbscript

I'm using a vbscript to programmatically run through a list of word documents, open each one, modify it, then save it using ms word 2010. My problem is there are protected and unprotected documents in the list. When I reach a protected document, I get this error: This method or property is not available because the object refers to a protected area of the document.
So I did some research and found this code on the ms website:
If objDoc.ProtectionType <> wdNoProtection Then
objDoc.Unprotect
End if
Now the problem is a new error: The unprotect method or property is not available because the document is already unprotected. Is there a another way to check if the document is protected or unprotected, when you know there will be both in the list, to avoid the errors?
If you automate MS Office applications using VBScript (and use VBA sample code as a starting point), you may overlook the necessity of defining the wd*, xl*, or ad(?)* constants that are predefined in VBA, but missing in VBScript. Use the Docs and/or Debug output to add lines like:
Const wdNoProtection = <correct value>
to your script.
If you start your script with Option Explicit and either avoid the evil global On Error Resume Next entirely or at least disable it until the program is tested, you won't miss any of these beasts.
An even better approach is to write your script as a .wsf file. The <reference> tag 'includes' the definitions (so you can't be blamed for an incorrect Const line).
POC/Demo code:
<?xml version="1.0" standalone="yes" encoding="iso-8859-1" ?>
<package>
<job id="QEC">
<reference object="Excel.Sheet" reference="true"/>
<script language="VBScript">
<![CDATA[
' ############################################################################
a = inputbox ( "Name of an Excel Constant?" )
msgbox a & " = " & eval(a)
' ############################################################################
]]>
</script>
</job>
</package>

Resources