|
|
 Here is a bit of code from Mountain Climbing Journal that combines an if statement and regular expressions to match an image and display it:
if left(me.SelText,9)="<img src=" AND Keyboard.AsyncControlKey=TRUE then
dim rg as new RegEx
dim match as RegExMatch
dim f as folderItem
dim imgsrc as string
if instr(me.SelText,"/") <> 0 then
rg.SearchPattern="<img src="+chr(34)+"\S*/(\w+\.\w+)"+chr(34)+">$"
match=rg.Search(me.SelText)
if match <> nil then
imgsrc= match.SubExpressionString(1)
else
MsgBox "Try reselecting, and include start and end tags."
end
else
rg.SearchPattern="<img src="+chr(34)+"(\w+\.\w+)"+chr(34)+">$"
match=rg.Search(me.SelText)
if match <> nil then
imgsrc= match.SubExpressionString(1)
else
MsgBox "Try reselecting, and include start and end tags."
end
end
f = getFolderItem(imgsrc)
if f <> nil then
picturev.Backdrop = f.OpenAsPicture
end if
picturev.Show
end
|
This code is stuck in the SelChange event for an EditField control. When the control key is down and the left hand side of the selection is "<img src=", the image is determined and displayed. If a full URL is used, indicated by "/", then a regular expression that assumes a URL pulls out the image file name from the end of the URL, otherwise, a regular expression that assumes it is just a plain reference to a local file is used. The idea is that the entries in the journal can refer to either local images or images on the web. If the image is stored on the web, the HTML version of the journal viewer can see the image via a browser. By then copying that image locally, the built-in image viewer of the journal can also view it. I'm sure there is a fancier regular expression that will account for both cases, but it was easier to use if in this case, as the regular expression wasn't apparent.
|
|