DK-Flag Erik Østergaard - Source code snippets / Kildekode småstykker Go to Home Page
 (Geometric Shapes) Source code snippets Return
  
  
Bottom of This Page

 

VBS

- source code snippets /
- kildekode småstykker

Education

 


(Geometric Shapes) BASIC source code snippets BASIC (Beginner's All-purpose Symbolic Instruction Code) source code snippets / BASIC (Beginner's All-purpose Symbolic Instruction Code) kildekode småstykker

- included the programming languages variants: Basic, VB (Visual Basic), VBA (Visual Basic for Applications), and VBS (VBScript). / - inkluderet programmeringssprog varianterne: Basic, VB (Visual Basic), VBA (Visual Basic for Applications) og VBS (VBScript).

Overview / Oversigt
Warning Warning / AdvarselWarning: Don't run the script files without reading them first! /
Warning / AdvarselAdvarsel: Kør ikke script-filerne uden at læse dem først!

VBS - source code snippets / VBS - kildekode småstykker

(- a VBScript which uses the root WSH (Windows Script Host) COM object "WScript") / (- et VBScript som bruger rod WSH (Windows Script Host) COM objekt "WScript")

HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa. / HTML tag (billede) 'img' attribut: 'alt' til 'title', og omvendt.

Description: Process a HTML document to add image attribute 'alt' to 'title'. / Beskrivelse: Behandel et HTML-dokument for at tilføje billed attributten 'alt' til 'title'.

This program is being run under WSCRIPT. / Dette program køres under WSCRIPT.

Always work on a copy of the original file(s)! / Arbejd altid på en kopi af den (de) oprindelige fil(er)!

The quick and easy way to add 'alt' and 'title' attributes to HTML image 'img' tags - perfect for instantly restoring missing tooltips in the latest Internet browsers. If you as a web developer have created web pages that contain HTML image 'img' tags without an 'alt' attribute or more likely a 'title' attribute this script is for you. / Den hurtige og nemme måde at tilføje 'alt' og 'title' attributter til HTML billede 'img' tags - perfekt til straks at genoprette manglende værktøjstip i de nyeste internetbrowsere. Hvis du, som web-udvikler, har oprettet websider, der indeholder HTML billede 'img' tags uden en 'alt' attribut eller mere sandsynligt en 'title' attribut, er dette skript for dig.

The 'title' attribute will provide a tooltip, 'alt' is also an important attribute, since it specifies text to be displayed if an image can't be displayed. / 'title' attributten vil vise et værktøjstip, 'alt' er også en vigtig attribut, da den angiver tekst, der skal vises, hvis et billede ikke kan vises.

If you in an image 'img' tag provide the attribute 'alt' this script will automatically create a 'title' attribute with the same value for you, and vice versa. / Hvis du i et billede 'img' tag tilvejebringer attributten 'alt', vil dette skript automatisk skabe en 'title' attribut med den samme værdi for dig, og vice versa.

The files to be processed and the file(s) created by this script will always be in the script's directory and the file(s) created by this script will have the same base name as the script. However the file(s) processed by this script will just be overwritten. / De filer, der skal behandles, og den (de) fil(er) skabt af dette skript vil altid være i skriptets mappe, og filen(erne) skabt af dette skript vil have det samme base navn som skriptet. Men den (de) fil(er), som behandles af dette skript vil bare blive overskrevet.

Overview - Function(s)... / Oversigt - Funktion(er)...

- and Sub procedure(s)... / - og Sub procedure(r)...

A sub procedure is used exactly the same way as a function, the only difference being that it doesn't return a value and therefore can't be used as part of an argument. Sub procedures are used by Visual Basic to provide event handling. / En sub procedure anvendes på nøjagtig samme måde som en funktion, den eneste forskel er, at den ikke returnerer en værdi, og derfor ikke kan bruges som en del af et argument. Sub procedurer anvendes af Visual Basic til at tilvejebringe begivenhed håndtering.

Developed and tested under Microsoft Windows 7 Professional - Danish version. / Udviklet og testet under Microsoft Windows 7 Professional - dansk version.



' All variables must be declared before use.
Option Explicit

'
' alttitle.vbs
' (- a VBScript which uses the root WSH (Windows Script Host) COM object "WScript")
'
' Author: Erik Oestergaard / Forfatter: Erik Oestergaard
' E-mail: http://www.erikoest.dk/contact.htm
' Homepage: http://www.erikoest.dk
'
' Licence: Free to use, but please share improvements.
' No warranty - use at own risk. / Licens: Fri brug, men del
' venligst forbedringer. Ingen garanti - brug paa eget ansvar.
'
' HTML tag (image) 'img' attribute: 'alt' to 'title', and vice 
' versa. / HTML tag (billede) 'img' attribut: 'alt' til 'title', 
' og omvendt.
'
' Process a HTML document to add image attribute 'alt' to 'title'. / 
' Behandel et HTML-dokument for at tilfoeje billed attributten 
' 'alt' til 'title'.
'
' This program is being run under WSCRIPT. / Dette program koeres 
' under WSCRIPT.
'
' Always work on a copy of the original file(s)! / Arbejd altid 
' paa en kopi af den (de) oprindelige fil(er)!
'
' The quick and easy way to add 'alt' and 'title' attributes to HTML 
' image 'img' tags - perfect for instantly restoring missing tooltips 
' in the latest Internet browsers. If you as a web developer have 
' created web pages that contain HTML image 'img' tags without an 
' 'alt' attribute or more likely a 'title' attribute this script is 
' for you. / Den hurtige og nemme maade at tilfoeje 'alt' og 'title' 
' attributter til HTML billede 'img' tags - perfekt til straks at 
' genoprette manglende vaerktoejstip i de nyeste internetbrowsere. 
' Hvis du, som web-udvikler, har oprettet websider, der indeholder 
' HTML billede 'img' tags uden en 'alt' attribut eller mere 
' sandsynligt en 'title' attribut, er dette skript for dig.
'
' The 'title' attribute will provide a tooltip, 'alt' is also an 
' important attribute, since it specifies text to be displayed if 
' an image can't be displayed. / 'title' attributten vil vise et 
' vaerktoejstip, 'alt' er ogsaa en vigtig attribut, da den angiver 
' tekst, der skal vises, hvis et billede ikke kan vises.
'
' If you in an image 'img' tag provide the attribute 'alt' this 
' script will automatically create a 'title' attribute with the 
' same value for you, and vice versa. / Hvis du i et billede 
' 'img' tag tilvejebringer attributten 'alt', vil dette skript 
' automatisk skabe en 'title' attribut med den samme vaerdi for 
' dig, og vice versa.
'
' The files to be processed and the file(s) created by this script 
' will always be in the script's directory and the file(s) created 
' by this script will have the same base name as the script. However 
' the file(s) processed by this script will just be overwritten. / De 
' filer, der skal behandles, og den (de) fil(er) skabt af dette 
' skript vil altid vaere i skriptets mappe, og filen(erne) skabt 
' af dette skript vil have det samme base navn som skriptet. Men 
' den (de) fil(er), som behandles af dette skript vil bare blive 
' overskrevet.
'
' Installation in English: Copy 'alttitle.vbs' to an empty folder 
' or directory. / Installation paa dansk: Kopier 'alttitle.vbs' 
' til en tom mappe eller bibliotek.
'
' Use in English: Copy the files (with the file extensions 'htm', 
' or 'html' and the attributes 'Normal', or 'Archive') you want to 
' process to the same folder or directory. Run this 'alttitle.vbs' 
' script (double-click the script file name). / Brug paa dansk: Kopier 
' filerne (med filtypenavnene 'htm' eller 'html' og attributterne 
' 'Normal' eller 'Arkiv') som du vil behandle til den samme mappe 
' eller bibliotek. Koer 'alttitle.vbs' skriptet (dobbelt-klik paa 
' skript filnavnet).
'
' Note: / Bemaerk:
'
' For that the HTML tag supported by this script can be processed 
' by this script, the tag must start with '<img ' and end with '>' 
' on the same line. The attribute 'alt' to match must start with 
' 'alt="' and end with '"'. And, if present, the attribute 'title' 
' to match must start with 'title="' and end with '"'. / For at 
' HTML tag der understoettes af dette skript kan blive behandlet 
' af dette skript, skal tag'et begynde med '<img ' og slutte med 
' '>' paa den samme linie. Tilhoerende attribut 'alt' skal begynde 
' med 'alt="' og slutte med '"'. Og, hvis den findes, tilhoerende 
' attribut 'title' skal begynde med 'title="' og slutte med '"'.
'
' Furthermore, attribute 'alt' starting with 'alt='', 'alt=\"', 
' or 'alt=\'' is not processed by this script. Applies equally 
' to attribute 'title' starting with 'title='', 'title=\"', or 
' 'title=\'' and other variants. / Yderligere er attributten 'alt' 
' begyndende med 'alt='', 'alt=\"' eller 'alt=\'' ikke behandlet 
' af dette skript. Gaelder tilsvarende for attributten 'title' 
' begyndende med 'title='', 'title=\"' eller 'title=\'' og andre 
' varianter.
'
' Likewise, the tags 'input' and 'area' which also can contain 
' an 'alt' and/or 'title' attribute is not processed by this 
' script. / Ligeledes bliver tag'ene 'input' og 'area', som ogsaa 
' kan indeholde en 'alt' og/eller 'title' attribut, ikke behandlet 
' af dette skript.
'
' More information: / Mere information:
' http://www.erikoest.dk/scba_006.htm
'
' Version 1.0 / Version 1.0
'
' Latest release: April 27, 2014 / Seneste 
' udgave: 27. april 2014
'

' Define variables.
Dim intCounterFilesModified 'As Integer
Dim intCounterFilesNotModified 'As Integer

' Initialize variables.
intCounterFilesModified = 0
intCounterFilesNotModified = 0

Main

Sub Main()
' Process HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
Dim fs 'As Scripting.FileSystemObject
Dim fil, fils, fol
Dim strInputDirectory 'As String
Dim strInputFile 'As String
Dim strExtensions 'As String
Dim strExtension 'As String
Dim intCounter 'As Integer
Dim strMessageInfo 'As String
Dim f
Dim intFileAttributeValue 'As Integer
  If Lcase(Right(Wscript.FullName, 11)) = "wscript.exe" Then 
    If MsgBox ("This program is being run under WSCRIPT. Always work on a copy of the original file(s)! Results will be stored in a log at " & Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log" & ". Continue?", vbOkCancel, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa") = vbCancel Then Wscript.Quit
  Else
    MsgBox "This program is being run under CSCRIPT. Run this program under WSCRIPT.", vbOKOnly, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa"
    'Wscript.Quit
    Exit Sub
  End If
  Set fs = CreateObject("Scripting.FileSystemObject")
  strInputDirectory = fs.GetParentFolderName(Wscript.ScriptFullName)
  'MsgBox ("strInputDirectory = " & strInputDirectory)   ' Only for the purpose of debugging.
  strExtensions = "htm, html"   ' Source file extensions (comma delimited string/list) - Process what types of files?
  If strExtensions = "" Then Exit Sub
  'MsgBox ("Wscript.ScriptFullName = " & Wscript.ScriptFullName)   ' Only for the purpose of debugging.
  Set fol = fs.GetFolder(fs.GetParentFolderName(Wscript.ScriptFullName))
  Set fils = fol.Files
  intCounter = 0
  strMessageInfo = ""
  For Each fil In fils
    For Each strExtension In Split(strExtensions, ",")
      If Lcase(Mid(fil.Name, InStrRev(fil.Name, ".") + 1)) = Lcase(Trim(strExtension)) Then 
        'MsgBox ("fil.Name = " & fil.Name)   ' Only for the purpose of debugging.
        strInputFile = strInputDirectory & "\" & fil.Name   ' Full path and file name.
        'MsgBox ("strInputFile = " & strInputFile)   ' Only for the purpose of debugging.
        ' Make sure we will be working with the long file name.
        strInputFile = LongName(strInputFile)
        'MsgBox ("strInputFile = " & strInputFile)   ' Only for the purpose of debugging.
        If fs.FileExists(strInputFile) Then
          Set f = fs.GetFile(strInputFile)
          ' Attributes of files or folders:
          ' Constant     Value   Description
          ' Normal       0       Normal file. No attributes are set.
          ' ReadOnly     1       Read-only file. Attribute is read/write.
          ' Hidden       2       Hidden file. Attribute is read/write.
          ' System       4       System file. Attribute is read/write.
          ' Volume       8       Disk drive volume label. Attribute is read-only.
          ' Directory    16      Folder or directory. Attribute is read-only.
          ' Archive      32      File has changed since last backup. Attribute is read/write.
          ' Alias        1024    Link or shortcut. Attribute is read-only.
          ' Compressed   2048    Compressed file. Attribute is read-only.
          intFileAttributeValue = f.Attributes
          'MsgBox ("intFileAttributeValue = " & CStr(intFileAttributeValue))   ' Only for the purpose of debugging.
          ' Clean up.
          Set f = Nothing
          If intFileAttributeValue = 0 Or intFileAttributeValue = 32 Then
            'MsgBox ("strInputFile = " & strInputFile)   ' Only for the purpose of debugging.
            'MsgBox ("intFileAttributeValue = " & CStr(intFileAttributeValue))   ' Only for the purpose of debugging.
            intCounter = intCounter + 1
            processAlt2Title(strInputFile)
          End If
        Else
          Wscript.Quit
        End If
        Exit For
      End If
    Next
  Next
  ' Clean up.
  Set fils = Nothing
  Set fol = Nothing
  Set fs = Nothing
  ' Message - info.
  doBeep("2")
  strMessageInfo = ""
  strMessageInfo = strMessageInfo & "Files processed: "
  strMessageInfo = strMessageInfo & CStr(intCounter)
  strMessageInfo = strMessageInfo & ", of this is "
  strMessageInfo = strMessageInfo & CStr(intCounterFilesModified)
  strMessageInfo = strMessageInfo & " "
  If intCounterFilesModified = 1 Then
    strMessageInfo = strMessageInfo & "file"
  Else
    strMessageInfo = strMessageInfo & "files"
  End If
  strMessageInfo = strMessageInfo & " modified and "
  strMessageInfo = strMessageInfo & CStr(intCounterFilesNotModified)
  strMessageInfo = strMessageInfo & " "
  If intCounterFilesNotModified = 1 Then
    strMessageInfo = strMessageInfo & "file"
  Else
    strMessageInfo = strMessageInfo & "files"
  End If
  strMessageInfo = strMessageInfo & " not modified"
  strMessageInfo = strMessageInfo & "."
  ' Show result information.
  'MsgBox strMessageInfo, vbOKOnly, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa"
  WScript.Timeout = 10 : WScript.Echo strMessageInfo
End Sub

Sub processAlt2Title(strFile)
' Process File: HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, f, ts, theFile
Dim retstring 'As String
Dim processedretstring 'As String
Dim blnFileChanged 'As Boolean
  blnFileChanged = False
  Set fso = CreateObject("Scripting.FileSystemObject")
  'MsgBox ("FileNameLikeMine(""tmp"") = " & FileNameLikeMine("tmp"))   ' Only for the purpose of debugging.
  fso.CreateTextFile FileNameLikeMine("tmp")   ' Create a file.
  Set f = fso.GetFile(FileNameLikeMine("tmp"))
  Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
  Set theFile = fso.OpenTextFile(strFile, ForReading, False)
  ' The AtEndOfStream property applies only to TextStream files 
  ' that are open for reading, otherwise, an error occurs.
  Do While theFile.AtEndOfStream <> True
    retstring = theFile.ReadLine
    processedretstring = lineAlt2Title(retstring)
    If retstring <> processedretstring Then
      blnFileChanged = True
    End If
    If theFile.AtEndOfStream Then
      ts.Write processedretstring & vbCrLf
      'ts.Write processedretstring
    Else
      ts.Write processedretstring & vbCrLf
    End If
  Loop
  theFile.Close
  ts.Close
  If blnFileChanged = True Then
    intCounterFilesModified = intCounterFilesModified + 1
    f.Copy (strFile)   ' Copy a file.   ' Overwrite the original file!
  Else
    intCounterFilesNotModified = intCounterFilesNotModified + 1
  End If
  f.Delete   ' Delete a file.
  If blnFileChanged = True Then Write2Log(strFile)
  ' Clean up.
  Set theFile = Nothing
  Set ts = Nothing
  Set f = Nothing
  Set fso = Nothing
End Sub

Function lineAlt2Title(strLine) 'As String
' Process Line: HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
Const startOfTagStr = "<img " 'As String
Const endOfTagStr = ">" 'As String
Dim lineStr 'As String
Dim processedLineStr 'As String
Dim i 'As Integer   ' Iterator for loops.
Dim CompareMode 'As Integer   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
Dim startPosInt 'As Integer
Dim posStartOfTagInt 'As Integer
Dim posEndOfTagInt 'As Integer
Dim foundNotPartOfTagStr 'As String
Dim foundTagStr 'As String
  i = 0
  CompareMode = 1   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
  lineStr = strLine   ' Don't modify input variables.
  processedLineStr = ""
  startPosInt = 1   ' Important!
  posStartOfTagInt = 0
  posEndOfTagInt = 0
  foundNotPartOfTagStr = ""
  foundTagStr = ""
  If IsNull(lineStr) = True Then
    ' Make sure of the variable value if 'nothing' is the contents of the input.
    lineStr = ""
  End If
  If lineStr = "" Then
    ' The passed parameter (variable) must be a blank line and therefore...
    ' Do nothing.
    processedLineStr = lineStr
    lineAlt2Title = processedLineStr
    Exit Function
  End If
  Do While startPosInt <= Len(lineStr)
    ' Don't get stuck because of an error made during the development of the code.
    ' Do not allow an infinite loop. / Tillad ikke en uendelig loekke.
    ' Stop the loop.   ' Only for the purpose of debugging.
    'If MsgBox ("Do not allow an infinite loop." & " Continue the loop?", vbOkCancel, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa") = vbCancel Then Exit Do   ' Only for the purpose of debugging.
    foundNotPartOfTagStr = ""
    foundTagStr = ""
    'MsgBox("startPosInt = " & CStr(startPosInt) & "; Length of lineStr = " & CStr(Len(lineStr)))   ' Only for the purpose of debugging.
    ' The found tag must start and end on the same line (fragment).
    posStartOfTagInt = InStr(startPosInt, lineStr, startOfTagStr, CompareMode)
    If posStartOfTagInt <> 0 Then
      ' Found start of tag.
      posEndOfTagInt = InStr(posStartOfTagInt + (Len(startOfTagStr)), lineStr, endOfTagStr, CompareMode)
    Else
      ' Found no start of tag.
      posEndOfTagInt = 0
    End If
    'MsgBox ("startPosInt = " & CStr(startPosInt) & "; posStartOfTagInt = " & CStr(posStartOfTagInt) & "; posEndOfTagInt = " & CStr(posEndOfTagInt))   ' Only for the purpose of debugging.
    If posStartOfTagInt <> 0 And posEndOfTagInt <> 0 Then
      ' Found start and end of tag on the same line fragment.
      'MsgBox ("foundNotPartOfTagStr (Part # of #) = " & "§" & Mid(lineStr, startPosInt, (posStartOfTagInt - startPosInt)) & "§")   ' Only for the purpose of debugging.
      'MsgBox ("foundTagStr (Part # of #) = " & "§" & Mid(lineStr, posStartOfTagInt, (posEndOfTagInt + Len(endOfTagStr) - posStartOfTagInt)) & "§")   ' Only for the purpose of debugging.
      foundNotPartOfTagStr = Mid(lineStr, startPosInt, (posStartOfTagInt - startPosInt))
      foundTagStr = Mid(lineStr, posStartOfTagInt, (posEndOfTagInt + Len(endOfTagStr) - posStartOfTagInt))
    Else
      ' Found no start and end of tag on the same line fragment.
      'MsgBox ("foundNotPartOfTagStr (Part # of #) = " & "§" & Mid(lineStr, startPosInt, (Len(lineStr))) & "§")   ' Only for the purpose of debugging.
      foundNotPartOfTagStr = Mid(lineStr, startPosInt, (Len(lineStr)))
    End If
    processedLineStr = processedLineStr + foundNotPartOfTagStr + tagAlt2Title(foundTagStr)
    startPosInt = startPosInt + Len(foundNotPartOfTagStr) + Len(foundTagStr)
  Loop
  'MsgBox ("startPosInt = " & CStr(startPosInt))   ' Only for the purpose of debugging.
  'MsgBox ("processedLineStr = " & processedLineStr)   ' Only for the purpose of debugging.
  lineAlt2Title = processedLineStr
End Function

Function tagAlt2Title(strTag) 'As String
' Process Tag: HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
Const startOfTagStr = "<img " 'As String
Const endOfTagStr = ">" 'As String
Const startOfSrcAttbStr = " src=""" 'As String
Const endOfSrcAttbStr = """" 'As String
Const startOfAltAttbStr = " alt=""" 'As String
Const endOfAltAttbStr = """" 'As String
Const startOfTitleAttbStr = " title=""" 'As String
Const endOfTitleAttbStr = """" 'As String
Dim tagStr 'As String
Dim processedTagStr 'As String
Dim i 'As Integer   ' Iterator for loops.
Dim CompareMode 'As Integer   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
Dim posStartOfSrcAttbInt 'As Integer
Dim posEndOfSrcAttbInt 'As Integer
Dim srcAttbStr 'As String
Dim blnFoundSrcAttb 'As Boolean
Dim srcAttbFileNameStr 'As String
Dim foundAttbStr 'As String
Dim posStartOfAltAttbInt 'As Integer
Dim posEndOfAltAttbInt 'As Integer
Dim posStartOfTitleAttbInt 'As Integer
Dim posEndOfTitleAttbInt 'As Integer
Dim altAttbStr 'As String
Dim titleAttbStr 'As String
Dim blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreExistingAndBothAreBlank 'As Boolean
Dim blnOptionallyAddAltAttbAndTitleAttbIfBothAreMissing 'As Boolean
Dim blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing 'As Boolean
  i = 0
  CompareMode = 1   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
  tagStr = strTag   ' Don't modify input variables.
  processedTagStr = ""
  posStartOfSrcAttbInt = 0
  posEndOfSrcAttbInt = 0
  srcAttbStr = ""
  blnFoundSrcAttb = False
  srcAttbFileNameStr = ""
  foundAttbStr = ""
  posStartOfAltAttbInt = 0
  posEndOfAltAttbInt = 0
  posStartOfTitleAttbInt = 0
  posEndOfTitleAttbInt = 0
  altAttbStr = ""
  titleAttbStr = ""
  '****************************************************************************
  '****   Below here are the variables that can be edited by the user!   ****
  '****************************************************************************
  ' User changeable option Start. / Bruger udskiftelig indstilling Start.
  '
  ' Optionally use value of Src Attribute to Alt Attribute and Title Attribute if both 
  ' of these are existing and both of these are blank (False|True) [Default: False].
  blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreExistingAndBothAreBlank = False
  '
  ' Optionally add Alt Attribute and Title Attribute if both of these are 
  ' missing (False|True) [Default: True].
  blnOptionallyAddAltAttbAndTitleAttbIfBothAreMissing = True
  ' Optionally use value of Src Attribute to Alt Attribute and Title Attribute if both 
  ' of these are missing (False|True) [Default: False].
  blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing = False
  '
  ' User changeable option End. / Bruger udskiftelig indstilling Slut.
  '****************************************************************************
  '****   Above here are the variables that can be edited by the user!   ****
  '****************************************************************************
  If IsNull(tagStr) = True Then
    ' Make sure of the variable value if 'nothing' is the contents of the input.
    tagStr = ""
  End If
  If tagStr = "" Then
    ' The passed parameter (variable) must be blank and therefore...
    ' Do nothing.
    processedTagStr = tagStr
    tagAlt2Title = processedTagStr
    Exit Function
  End If
  If Lcase(Mid(tagStr, 1, Len(startOfTagStr))) <> Lcase(startOfTagStr) _
    Or Lcase(Mid(tagStr, Len(tagStr) - (Len(endOfTagStr) - 1), Len(endOfTagStr))) <> Lcase(endOfTagStr) _
    Or InStr((1 + Len(startOfTagStr)), tagStr, startOfTagStr, CompareMode) <> 0 Then 
    ' The passed tag must start and end the line and also be on the same line, and 
    ' there must only be one tag at the line otherwise...
    ' Do nothing.
    processedTagStr = tagStr
    tagAlt2Title = processedTagStr
    Exit Function
  End If
  If InStr(1, tagStr, startOfSrcAttbStr, CompareMode) <> 0 Then
    ' Found Src Attribute.
    blnFoundSrcAttb = True
    posStartOfSrcAttbInt = InStr(1, tagStr, startOfSrcAttbStr, CompareMode)
    posEndOfSrcAttbInt = InStr(posStartOfSrcAttbInt + (Len(startOfSrcAttbStr)), tagStr, endOfSrcAttbStr, CompareMode)
    srcAttbStr = CStr(Mid(tagStr, (posStartOfSrcAttbInt + Len(startOfSrcAttbStr)), (posEndOfSrcAttbInt - (posStartOfSrcAttbInt + Len(startOfSrcAttbStr)))))
    'MsgBox ("srcAttbStr = " & "§" & srcAttbStr & "§")   ' Only for the purpose of debugging.
  Else
    ' Found No Src Attribute.
    blnFoundSrcAttb = False
    srcAttbStr = ""
  End If
  If InStrRev(srcAttbStr, "/") Then
    ' Get Src Attribute file name consisting of 'filename.extension'.
    srcAttbFileNameStr = CStr(Mid(srcAttbStr, (InStrRev(srcAttbStr, "/") + 1), Len(srcAttbStr)))
  Else
    ' Src Attribute file name consisting of 'filename.extension'.
    srcAttbFileNameStr = srcAttbStr
  End If
  'MsgBox ("srcAttbFileNameStr = " & "§" & srcAttbFileNameStr & "§")   ' Only for the purpose of debugging.
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) <> 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) = 0 Then
    foundAttbStr = Lcase("foundOnlyAltAttb")
  End If
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) = 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) <> 0 Then
    foundAttbStr = Lcase("foundOnlyTitleAttb")
  End If
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) <> 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) <> 0 Then
    foundAttbStr = Lcase("foundAltAndTitleAttb")
  End If
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) = 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) = 0 Then
    foundAttbStr = Lcase("foundNoAltAndTitleAttb")
  End If
  Select Case Lcase(foundAttbStr)
    Case "foundonlyaltattb"
      ' Found Only Alt Attribute.
      ' Use value of Alt Attribute to Title Attribute.
      posStartOfAltAttbInt = InStr(1, tagStr, startOfAltAttbStr, CompareMode)
      posEndOfAltAttbInt = InStr(posStartOfAltAttbInt + (Len(startOfAltAttbStr)), tagStr, endOfAltAttbStr, CompareMode)
      altAttbStr = CStr(Mid(tagStr, (posStartOfAltAttbInt + Len(startOfAltAttbStr)), (posEndOfAltAttbInt - (posStartOfAltAttbInt + Len(startOfAltAttbStr)))))
      'MsgBox ("altAttbStr = " & "§" & altAttbStr & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, (posEndOfAltAttbInt)) & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (posEndOfAltAttbInt + 1), (Len(tagStr) - posEndOfAltAttbInt)) & "§")   ' Only for the purpose of debugging.
      processedTagStr = Mid(tagStr, 1, (posEndOfAltAttbInt)) & _
      startOfTitleAttbStr & altAttbStr & endOfTitleAttbStr & _
      Mid(tagStr, (posEndOfAltAttbInt + 1), (Len(tagStr) - posEndOfAltAttbInt))
    Case "foundonlytitleattb"
      ' Found Only Title Attribute.
      ' Use value of Title Attribute to Alt Attribute.
      posStartOfTitleAttbInt = InStr(1, tagStr, startOfTitleAttbStr, CompareMode)
      posEndOfTitleAttbInt = InStr(posStartOfTitleAttbInt + (Len(startOfTitleAttbStr)), tagStr, endOfTitleAttbStr, CompareMode)
      titleAttbStr = CStr(Mid(tagStr, (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)), (posEndOfTitleAttbInt - (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)))))
      'MsgBox ("titleAttbStr = " & "§" & titleAttbStr & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, (posStartOfTitleAttbInt - 1)) & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (posStartOfTitleAttbInt), Len(tagStr)) & "§")   ' Only for the purpose of debugging.
      processedTagStr = Mid(tagStr, 1, (posStartOfTitleAttbInt - 1)) & _
      startOfAltAttbStr & titleAttbStr & endOfAltAttbStr & _
      Mid(tagStr, (posStartOfTitleAttbInt), Len(tagStr))
    Case "foundaltandtitleattb"
      ' Found Alt And Title Attribute.
      If blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreExistingAndBothAreBlank = False Then
        ' Do NOT use value of Src Attribute to Alt Attribute and Title Attribute if both of these are existing and both of these are blank.
        ' Do nothing.
        processedTagStr = tagStr
      Else
        ' Do use value of Src Attribute to Alt Attribute and Title Attribute if both of these are existing and both of these are blank.
        posStartOfAltAttbInt = InStr(1, tagStr, startOfAltAttbStr, CompareMode)
        posEndOfAltAttbInt = InStr(posStartOfAltAttbInt + (Len(startOfAltAttbStr)), tagStr, endOfAltAttbStr, CompareMode)
        altAttbStr = CStr(Mid(tagStr, (posStartOfAltAttbInt + Len(startOfAltAttbStr)), (posEndOfAltAttbInt - (posStartOfAltAttbInt + Len(startOfAltAttbStr)))))
        'MsgBox ("altAttbStr = " & "§" & altAttbStr & "§")   ' Only for the purpose of debugging.
        posStartOfTitleAttbInt = InStr(1, tagStr, startOfTitleAttbStr, CompareMode)
        posEndOfTitleAttbInt = InStr(posStartOfTitleAttbInt + (Len(startOfTitleAttbStr)), tagStr, endOfTitleAttbStr, CompareMode)
        titleAttbStr = CStr(Mid(tagStr, (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)), (posEndOfTitleAttbInt - (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)))))
        'MsgBox ("titleAttbStr = " & "§" & titleAttbStr & "§")   ' Only for the purpose of debugging.
        If altAttbStr = "" And titleAttbStr = "" Then
          ' Alt Attribute and Title Attribute are both blank.
          If posStartOfAltAttbInt < posStartOfTitleAttbInt Then
            ' Occurrence order: / Forekomst raekkefoelge: Alt Attribute - Title Attribute.
            'MsgBox ("tagStr (Part 1 of 3) = " & "§" & Mid(tagStr, 1, (posEndOfAltAttbInt - 1)) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 2 of 3) = " & "§" & Mid(tagStr, posEndOfAltAttbInt, (posStartOfTitleAttbInt - posEndOfAltAttbInt + Len(startOfTitleAttbStr))) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 3 of 3) = " & "§" & Mid(tagStr, posEndOfTitleAttbInt, Len(tagStr)) & "§")   ' Only for the purpose of debugging.
            processedTagStr = Mid(tagStr, 1, (posEndOfAltAttbInt - 1)) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfAltAttbInt, (posStartOfTitleAttbInt - posEndOfAltAttbInt + Len(startOfTitleAttbStr))) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfTitleAttbInt, Len(tagStr))
          Else
            ' Occurrence order: / Forekomst raekkefoelge: Title Attribute - Alt Attribute.
            'MsgBox ("tagStr (Part 1 of 3) = " & "§" & Mid(tagStr, 1, (posEndOfTitleAttbInt - 1)) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 2 of 3) = " & "§" & Mid(tagStr, posEndOfTitleAttbInt, (posStartOfAltAttbInt - posEndOfTitleAttbInt + Len(startOfAltAttbStr))) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 3 of 3) = " & "§" & Mid(tagStr, posEndOfAltAttbInt, Len(tagStr)) & "§")   ' Only for the purpose of debugging.
            processedTagStr = Mid(tagStr, 1, (posEndOfTitleAttbInt - 1)) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfTitleAttbInt, (posStartOfAltAttbInt - posEndOfTitleAttbInt + Len(startOfAltAttbStr))) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfAltAttbInt, Len(tagStr))
          End If
        Else
          ' Alt Attribute and Title Attribute are both NOT blank.
          ' Do nothing.
          processedTagStr = tagStr
        End If
      End If
    Case "foundnoaltandtitleattb"
      ' Found No Alt And Title Attribute.
      If blnOptionallyAddAltAttbAndTitleAttbIfBothAreMissing = False Then
        ' Do NOT add Alt Attribute and Title Attribute if both of these are missing.
        ' Do nothing.
        processedTagStr = tagStr
      Else
        ' Do add Alt Attribute and Title Attribute if both of these are missing.
        If blnFoundSrcAttb = True Then
          ' Src Attribute was found.
          'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, (posEndOfSrcAttbInt)) & "§")   ' Only for the purpose of debugging.
          'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (posEndOfSrcAttbInt + 1), (Len(tagStr) - posEndOfSrcAttbInt)) & "§")   ' Only for the purpose of debugging.
          If blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing = False Then
            ' Do NOT use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, (posEndOfSrcAttbInt)) & _
            startOfAltAttbStr & endOfAltAttbStr & _
            startOfTitleAttbStr & endOfTitleAttbStr & _
            Mid(tagStr, (posEndOfSrcAttbInt + 1), (Len(tagStr) - posEndOfSrcAttbInt))
          Else
            ' Do use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, (posEndOfSrcAttbInt)) & _
            startOfAltAttbStr & srcAttbFileNameStr & endOfAltAttbStr & _
            startOfTitleAttbStr & srcAttbFileNameStr & endOfTitleAttbStr & _
            Mid(tagStr, (posEndOfSrcAttbInt + 1), (Len(tagStr) - posEndOfSrcAttbInt))
          End If
        Else
          ' No Src Attribute was found.
          'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, Len(RTrim(startOfTagStr))) & "§")   ' Only for the purpose of debugging.
          'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (Len(RTrim(startOfTagStr)) + 1), (Len(tagStr) - Len(RTrim(startOfTagStr)))) & "§")   ' Only for the purpose of debugging.
          If blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing = False Then
            ' Do NOT use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, Len(RTrim(startOfTagStr))) & _
            startOfAltAttbStr & endOfAltAttbStr & _
            startOfTitleAttbStr & endOfTitleAttbStr & _
            Mid(tagStr, (Len(RTrim(startOfTagStr)) + 1), (Len(tagStr) - Len(RTrim(startOfTagStr))))
          Else
            ' Do use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, Len(RTrim(startOfTagStr))) & _
            startOfAltAttbStr & srcAttbFileNameStr & endOfAltAttbStr & _
            startOfTitleAttbStr & srcAttbFileNameStr & endOfTitleAttbStr & _
            Mid(tagStr, (Len(RTrim(startOfTagStr)) + 1), (Len(tagStr) - Len(RTrim(startOfTagStr))))
          End If
        End If
      End If
    Case Else
      ' ERROR.
      ' Do nothing.
      processedTagStr = tagStr
  End Select
  'MsgBox ("processedTagStr = " & processedTagStr)   ' Only for the purpose of debugging.
  tagAlt2Title = processedTagStr
End Function

Sub Write2Log(strText)
' Write to log file.
Dim fs 'As Scripting.FileSystemObject
Dim ts 'As Scripting.TextStream
Const ForAppending = 8
  Set fs = CreateObject("Scripting.FileSystemObject")
  'MsgBox ("Wscript.ScriptFullName & ""log"" = " & Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log")   ' Only for the purpose of debugging.
  Set ts = fs.OpenTextFile(Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log", ForAppending, True)
  ts.Write("Time Stamp: " _
  & "" & Now & " " _
  & "Processed file: " _
  & "" & strText & " " _
  & "MODIFIED" _
  & "" & vbCrLf)
  ts.Close
  ' Clean up.
  Set ts = Nothing
  Set fs = Nothing
End Sub

Function FileNameLikeMine(strFileExtension) 'As String
' Returns a file name the same as the script name except
' for the file extension. 
Dim fs 'As Object
Dim strExtension 'As String
  Set fs = CreateObject("Scripting.FileSystemObject")
  strExtension = strFileExtension   ' Don't modify input variables.
  If Len(strExtension) < 1 Then strExtension = "txt"
  If strExtension = "." Then strExtension = "txt"
  If Left(strExtension, 1) = "." Then strExtension = Mid(strExtension, 2)
  FileNameLikeMine = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & strExtension
  'MsgBox ("FileNameLikeMine = " & FileNameLikeMine)   ' Only for the purpose of debugging.
  ' Clean up.
  Set fs = Nothing
End Function

Function LongName(strFullPathAndFile) 'As String
' Converts a legitimate short file name into the long file name.
Dim strOriginalFile 'As String
Dim fs, fil, fils, fol
Dim blnFound 'As Boolean
  Set fs = CreateObject("Scripting.FileSystemObject")
  blnFound = False
  strOriginalFile = fs.GetFile(strFullPathAndFile).ShortPath
  Set fol = fs.GetFolder(fs.GetParentFolderName(strFullPathAndFile))
  Set fils = fol.Files
  For Each fil In fils
    If fil.ShortPath = strOriginalFile Then
      strOriginalFile = fil.Path
      blnFound = True
      Exit For
    End If
  Next
  If blnFound Then
    LongName = strOriginalFile
  Else
    LongName = strFullPathAndFile
  End If
  'MsgBox ("LongName = " & LongName)   ' Only for the purpose of debugging.
  ' Clean up.
  Set fils = Nothing
  Set fol = Nothing
  Set fs = Nothing
End Function

Function doBeep(iTimes)
  '#--------------------------------------------------------------------------
  '#  FUNCTION.......:  doBeep()
  '#  ARGUMENTS......:  iTimes = the number of times the computer will beep.
  '#  PURPOSE........:  Causes the computer's internal speaker to beep. On 
  '#                    some systems the beep will be executed from the actual 
  '#                    speakers.
  '#  EXAMPLE........:  doBeep("7")
  '#  NOTES..........:  This was surprisingly hard to figure out, yet highly 
  '#                    useful. There is a timing issue, the script will 
  '#                    execute the beeps faster than the speaker can make 
  '#                    individual noises.
  '#--------------------------------------------------------------------------
  ' Define variables.
  Dim oShell
  Set oShell = CreateObject("Wscript.Shell")
  Dim iTemp 'As Integer   ' Iterator for loops.
  For iTemp = 1 To CInt(iTimes) Step 1
    oShell.Run "%comspec% /c echo " & Chr(7), 0, False
    Wscript.Sleep 300
  Next
  ' Clean up.
  Set oShell = Nothing
End Function

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

1 Implementation: (How to use:) /
1 Implementering: (Sådan bruger du:)

Simple word processor: / Simpel tekstbehandlerprogram:

  1. Open a new Text Document in a text editor similar to Microsoft Notepad /
    Åben et nyt Tekst Dokument i et tekst redigeringsprogram lignende Microsoft Notesblok
  2. Copy the code above /
    Kopier koden ovenfor
  3. Paste the code into the new Text Document /
    Indsæt koden i det nye Tekst Dokument
  4. Save the document before any other changes under the file name alttitle.vbs /
    Gem dokumentet før nogen andre ændringer under filnavnet alttitle.vbs
  5. Make sure that your text editor do not have added the file extension .txt to the saved file - in that case just rename the file to the correct file name consisting of 'filename.extension' /
    Sørg for, at dit tekst redigeringsprogram ikke har tilføjet filtypen .txt til den gemte fil - i dette tilfælde bare omdøb filen til det korrekte filnavn bestående af 'filnavn.filtype'

2 Implementation: (How to use:) /
2 Implementering: (Sådan bruger du:)

  1. Copy 'alttitle.vbs' to an empty folder or directory /
    Kopier 'alttitle.vbs' til en tom mappe eller bibliotek
  2. Copy the files (with the file extensions 'htm', or 'html' and the attributes 'Normal', or 'Archive') you want to process to the same folder or directory /
    Kopier filerne (med filtypenavnene 'htm' eller 'html' og attributterne 'Normal' eller 'Arkiv') som du vil behandle til den samme mappe eller bibliotek
  3. Run this 'alttitle.vbs' script (double-click the script file name) /
    Kør 'alttitle.vbs' skriptet (dobbelt-klik på skript filnavnet)

Note: / Bemærk:

For that the HTML tag supported by this script can be processed by this script, the tag must start with '<img ' and end with '>' on the same line. The attribute 'alt' to match must start with 'alt="' and end with '"'. And, if present, the attribute 'title' to match must start with 'title="' and end with '"'. /
For at HTML tag der understøttes af dette skript kan blive behandlet af dette skript, skal tag'et begynde med '<img ' og slutte med '>' på den samme linie. Tilhørende attribut 'alt' skal begynde med 'alt="' og slutte med '"'. Og, hvis den findes, tilhørende attribut 'title' skal begynde med 'title="' og slutte med '"'.

Furthermore, attribute 'alt' starting with 'alt='', 'alt=\"', or 'alt=\'' is not processed by this script. Applies equally to attribute 'title' starting with 'title='', 'title=\"', or 'title=\'' and other variants. /
Yderligere er attributten 'alt' begyndende med 'alt='', 'alt=\"' eller 'alt=\'' ikke behandlet af dette skript. Gælder tilsvarende for attributten 'title' begyndende med 'title='', 'title=\"' eller 'title=\'' og andre varianter.

Likewise, the tags 'input' and 'area' which also can contain an 'alt' and/or 'title' attribute is not processed by this script. /
Ligeledes bliver tag'ene 'input' og 'area', som også kan indeholde en 'alt' og/eller 'title' attribut, ikke behandlet af dette skript.

Other Features: / Andre funktioner:

In the function "tagAlt2Title" in the sectíon "User changeable option" is it possible to... /
I funktionen "tagAlt2Title" i afsnittet "Bruger udskiftelig indstilling" er det muligt at...

  1. Optionally use value of Src attribute to Alt attribute and Title attribute if both of these are existing and both of these are blank (False|True) [Default: False]. /
    Valgfrit brug værdien af Src attributten til Alt attributten og Title attributten hvis begge disse eksisterer og begge disse er tomme (False|True) [Standard: False].
  2.  
    1. Optionally add Alt Attribute and Title Attribute if both of these are missing (False|True) [Default: True]. /
      Valgfrit tilføj Alt attribut og Title attribut hvis begge disse mangler (False|True) [Standard: True].
    2. Optionally use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing (False|True) [Default: False]. /
      Valgfrit brug værdien af Src attributten til Alt attributten og Title attributten hvis begge disse mangler (False|True) [Standard: False].

(How to...) / (Hvordan...)

(Just change the value right after the equal sign from True to False, and vice versa.) /
(Bare ændre værdien lige efter lighedstegnet fra sand 'True' til falsk 'False' og omvendt.)

or... / eller...

You can download a version of the source code from my Download page here: / Du kan downloade en version af kildekoden fra min Download side her:

[VBS] Download "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa" 'alttitle.vbs' for VBScript & WSH COM object "WScript": alttitle.zip / [VBS] Download "HTML tag (billede) 'img' attribut: 'alt' til 'title', og omvendt" 'alttitle.vbs' for VBScript & WSH COM objekt "WScript": alttitle.zipOpen this link in new window / Åben dette link i nyt vindue


(Geometric Shapes) Source code snippetsExtras: / Ekstramateriale:

When developing this script the functions 'lineAlt2Title' and 'tagAlt2Title' have been developed and tested in the files 'lineAlt2Title.vbs' and 'tagAlt2Title.vbs' respectively. These files have been included so you can use these files to safely and easily test the functions. /
Ved udviklingen af dette script er funktionerne 'lineAlt2Title' og 'tagAlt2Title' blevet udviklet og testet i filerne 'lineAlt2Title.vbs' og 'tagAlt2Title.vbs' henholdsvis. Disse filer er medtaget så man kan bruge disse filer til sikkert og nemt at teste funktionerne.

Overview - Function(s)... / Oversigt - Funktion(er)...

- and Sub procedure(s)... / - og Sub procedure(r)...

A sub procedure is used exactly the same way as a function, the only difference being that it doesn't return a value and therefore can't be used as part of an argument. Sub procedures are used by Visual Basic to provide event handling. / En sub procedure anvendes på nøjagtig samme måde som en funktion, den eneste forskel er, at den ikke returnerer en værdi, og derfor ikke kan bruges som en del af et argument. Sub procedurer anvendes af Visual Basic til at tilvejebringe begivenhed håndtering.

Developed and tested under Microsoft Windows 7 Professional - Danish version. / Udviklet og testet under Microsoft Windows 7 Professional - dansk version.



' All variables must be declared before use.
Option Explicit

'
' lineAlt2Title.vbs
' (- a VBScript which uses the root WSH (Windows Script Host) COM object "WScript")
'

Main

Sub Main()
Dim strInput 'As String
  ' Test string(s).
    '***************************************************************************************************************
    '****   How to use: Uncomment the line you want to use, and comment out the lines you do not want to use.   ****
    '***************************************************************************************************************
  strInput = "<p align=""left"">Text <img src=""./3.jpg"" alt=""3alt.jpg"" title=""3title.jpg"" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle""> text.</p>"
  'strInput = "<img only one on the line>"
  'strInput = "<img start line> abc"
  'strInput = "<img start line abc"
  'strInput = "abc <img end line>"
  'strInput = "abc <img end line"
  'strInput = "<img #1><img #2>"
  'strInput = "<img #1> <img #2>"
  'strInput = "abc<img #1><img #2>"
  'strInput = "<img #1><img #2>abc"
  'strInput = "abc<img #1>def<img #2>ghi"
  'strInput = "abc<img #1>def<img #2><img #3>ghi"
  'strInput = "abc"
  MsgBox "lineAlt2Title = " & lineAlt2Title(strInput), vbOKOnly, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa"
End Sub

Function lineAlt2Title(strLine) 'As String
' Process Line: HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
Const startOfTagStr = "<img " 'As String
Const endOfTagStr = ">" 'As String
Dim lineStr 'As String
Dim processedLineStr 'As String
Dim i 'As Integer   ' Iterator for loops.
Dim CompareMode 'As Integer   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
Dim startPosInt 'As Integer
Dim posStartOfTagInt 'As Integer
Dim posEndOfTagInt 'As Integer
Dim foundNotPartOfTagStr 'As String
Dim foundTagStr 'As String
  i = 0
  CompareMode = 1   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
  lineStr = strLine   ' Don't modify input variables.
  processedLineStr = ""
  startPosInt = 1   ' Important!
  posStartOfTagInt = 0
  posEndOfTagInt = 0
  foundNotPartOfTagStr = ""
  foundTagStr = ""
  If IsNull(lineStr) = True Then
    ' Make sure of the variable value if 'nothing' is the contents of the input.
    lineStr = ""
  End If
  If lineStr = "" Then
    ' The passed parameter (variable) must be a blank line and therefore...
    ' Do nothing.
    processedLineStr = lineStr
    lineAlt2Title = processedLineStr
    Exit Function
  End If
  Do While startPosInt <= Len(lineStr)
    ' Don't get stuck because of an error made during the development of the code.
    ' Do not allow an infinite loop. / Tillad ikke en uendelig loekke.
    ' Stop the loop.   ' Only for the purpose of debugging.
    'If MsgBox ("Do not allow an infinite loop." & " Continue the loop?", vbOkCancel, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa") = vbCancel Then Exit Do   ' Only for the purpose of debugging.
    foundNotPartOfTagStr = ""
    foundTagStr = ""
    'MsgBox("startPosInt = " & CStr(startPosInt) & "; Length of lineStr = " & CStr(Len(lineStr)))   ' Only for the purpose of debugging.
    ' The found tag must start and end on the same line (fragment).
    posStartOfTagInt = InStr(startPosInt, lineStr, startOfTagStr, CompareMode)
    If posStartOfTagInt <> 0 Then
      ' Found start of tag.
      posEndOfTagInt = InStr(posStartOfTagInt + (Len(startOfTagStr)), lineStr, endOfTagStr, CompareMode)
    Else
      ' Found no start of tag.
      posEndOfTagInt = 0
    End If
    'MsgBox ("startPosInt = " & CStr(startPosInt) & "; posStartOfTagInt = " & CStr(posStartOfTagInt) & "; posEndOfTagInt = " & CStr(posEndOfTagInt))   ' Only for the purpose of debugging.
    If posStartOfTagInt <> 0 And posEndOfTagInt <> 0 Then
      ' Found start and end of tag on the same line fragment.
      'MsgBox ("foundNotPartOfTagStr (Part # of #) = " & "§" & Mid(lineStr, startPosInt, (posStartOfTagInt - startPosInt)) & "§")   ' Only for the purpose of debugging.
      'MsgBox ("foundTagStr (Part # of #) = " & "§" & Mid(lineStr, posStartOfTagInt, (posEndOfTagInt + Len(endOfTagStr) - posStartOfTagInt)) & "§")   ' Only for the purpose of debugging.
      foundNotPartOfTagStr = Mid(lineStr, startPosInt, (posStartOfTagInt - startPosInt))
      foundTagStr = Mid(lineStr, posStartOfTagInt, (posEndOfTagInt + Len(endOfTagStr) - posStartOfTagInt))
    Else
      ' Found no start and end of tag on the same line fragment.
      'MsgBox ("foundNotPartOfTagStr (Part # of #) = " & "§" & Mid(lineStr, startPosInt, (Len(lineStr))) & "§")   ' Only for the purpose of debugging.
      foundNotPartOfTagStr = Mid(lineStr, startPosInt, (Len(lineStr)))
    End If
    processedLineStr = processedLineStr + foundNotPartOfTagStr + tagAlt2Title(foundTagStr)
    startPosInt = startPosInt + Len(foundNotPartOfTagStr) + Len(foundTagStr)
  Loop
  'MsgBox ("startPosInt = " & CStr(startPosInt))   ' Only for the purpose of debugging.
  'MsgBox ("processedLineStr = " & processedLineStr)   ' Only for the purpose of debugging.
  lineAlt2Title = processedLineStr
End Function

Function tagAlt2Title(strTag) 'As String
' Process Tag: HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
' *** Dummy function. / Attrap funktion. ***
Dim tagStr 'As String
  tagStr = strTag   ' Don't modify input variables.
  tagAlt2Title = tagStr
End Function

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

1 Implementation: (How to use:) /
1 Implementering: (Sådan bruger du:)

Simple word processor: / Simpel tekstbehandlerprogram:

  1. Open a new Text Document in a text editor similar to Microsoft Notepad /
    Åben et nyt Tekst Dokument i et tekst redigeringsprogram lignende Microsoft Notesblok
  2. Copy the code above /
    Kopier koden ovenfor
  3. Paste the code into the new Text Document /
    Indsæt koden i det nye Tekst Dokument
  4. Save the document before any other changes under the file name lineAlt2Title.vbs /
    Gem dokumentet før nogen andre ændringer under filnavnet lineAlt2Title.vbs
  5. Make sure that your text editor do not have added the file extension .txt to the saved file - in that case just rename the file to the correct file name consisting of 'filename.extension' /
    Sørg for, at dit tekst redigeringsprogram ikke har tilføjet filtypen .txt til den gemte fil - i dette tilfælde bare omdøb filen til det korrekte filnavn bestående af 'filnavn.filtype'

2 Implementation: (How to use:) /
2 Implementering: (Sådan bruger du:)

  1. Run this 'lineAlt2Title.vbs' script (double-click the script file name) /
    Kør 'lineAlt2Title.vbs' skriptet (dobbelt-klik på skript filnavnet)

Overview - Function(s)... / Oversigt - Funktion(er)...

- and Sub procedure(s)... / - og Sub procedure(r)...

A sub procedure is used exactly the same way as a function, the only difference being that it doesn't return a value and therefore can't be used as part of an argument. Sub procedures are used by Visual Basic to provide event handling. / En sub procedure anvendes på nøjagtig samme måde som en funktion, den eneste forskel er, at den ikke returnerer en værdi, og derfor ikke kan bruges som en del af et argument. Sub procedurer anvendes af Visual Basic til at tilvejebringe begivenhed håndtering.

Developed and tested under Microsoft Windows 7 Professional - Danish version. / Udviklet og testet under Microsoft Windows 7 Professional - dansk version.



' All variables must be declared before use.
Option Explicit

'
' tagAlt2Title.vbs
' (- a VBScript which uses the root WSH (Windows Script Host) COM object "WScript")
'

Main

Sub Main()
Dim strInput 'As String
  ' Test string(s).
    '***************************************************************************************************************
    '****   How to use: Uncomment the line you want to use, and comment out the lines you do not want to use.   ****
    '***************************************************************************************************************
  strInput = "<img src=""./3.jpg"" alt=""3alt.jpg"" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" title=""3title.jpg"" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" alt=""3alt.jpg"" title=""3title.jpg"" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" alt="""" title="""" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" alt="""" hspace=""0"" title="""" width=""829"" height=""1185"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" title="""" alt="""" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" title="""" hspace=""0"" alt="""" width=""829"" height=""1185"" vspace=""0"" border=""0"" align=""middle"">"
  'strInput = "<img src=""./3.jpg"" width=""829"" height=""1185"" hspace=""0"" vspace=""0"" border=""0"" align=""middle"">"
  MsgBox "tagAlt2Title = " & tagAlt2Title(strInput), vbOKOnly, "HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa"
End Sub

Function tagAlt2Title(strTag) 'As String
' Process Tag: HTML tag (image) 'img' attribute: 'alt' to 'title', and vice versa.
Const startOfTagStr = "<img " 'As String
Const endOfTagStr = ">" 'As String
Const startOfSrcAttbStr = " src=""" 'As String
Const endOfSrcAttbStr = """" 'As String
Const startOfAltAttbStr = " alt=""" 'As String
Const endOfAltAttbStr = """" 'As String
Const startOfTitleAttbStr = " title=""" 'As String
Const endOfTitleAttbStr = """" 'As String
Dim tagStr 'As String
Dim processedTagStr 'As String
Dim i 'As Integer   ' Iterator for loops.
Dim CompareMode 'As Integer   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
Dim posStartOfSrcAttbInt 'As Integer
Dim posEndOfSrcAttbInt 'As Integer
Dim srcAttbStr 'As String
Dim blnFoundSrcAttb 'As Boolean
Dim srcAttbFileNameStr 'As String
Dim foundAttbStr 'As String
Dim posStartOfAltAttbInt 'As Integer
Dim posEndOfAltAttbInt 'As Integer
Dim posStartOfTitleAttbInt 'As Integer
Dim posEndOfTitleAttbInt 'As Integer
Dim altAttbStr 'As String
Dim titleAttbStr 'As String
Dim blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreExistingAndBothAreBlank 'As Boolean
Dim blnOptionallyAddAltAttbAndTitleAttbIfBothAreMissing 'As Boolean
Dim blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing 'As Boolean
  i = 0
  CompareMode = 1   ' Comparison Mode: Value 0 [Binary - case sensitive] or 1 [Text - case insensitive].
  tagStr = strTag   ' Don't modify input variables.
  processedTagStr = ""
  posStartOfSrcAttbInt = 0
  posEndOfSrcAttbInt = 0
  srcAttbStr = ""
  blnFoundSrcAttb = False
  srcAttbFileNameStr = ""
  foundAttbStr = ""
  posStartOfAltAttbInt = 0
  posEndOfAltAttbInt = 0
  posStartOfTitleAttbInt = 0
  posEndOfTitleAttbInt = 0
  altAttbStr = ""
  titleAttbStr = ""
  '****************************************************************************
  '****   Below here are the variables that can be edited by the user!   ****
  '****************************************************************************
  ' User changeable option Start. / Bruger udskiftelig indstilling Start.
  '
  ' Optionally use value of Src Attribute to Alt Attribute and Title Attribute if both 
  ' of these are existing and both of these are blank (False|True) [Default: False].
  blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreExistingAndBothAreBlank = False
  '
  ' Optionally add Alt Attribute and Title Attribute if both of these are 
  ' missing (False|True) [Default: True].
  blnOptionallyAddAltAttbAndTitleAttbIfBothAreMissing = True
  ' Optionally use value of Src Attribute to Alt Attribute and Title Attribute if both 
  ' of these are missing (False|True) [Default: False].
  blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing = False
  '
  ' User changeable option End. / Bruger udskiftelig indstilling Slut.
  '****************************************************************************
  '****   Above here are the variables that can be edited by the user!   ****
  '****************************************************************************
  If IsNull(tagStr) = True Then
    ' Make sure of the variable value if 'nothing' is the contents of the input.
    tagStr = ""
  End If
  If tagStr = "" Then
    ' The passed parameter (variable) must be blank and therefore...
    ' Do nothing.
    processedTagStr = tagStr
    tagAlt2Title = processedTagStr
    Exit Function
  End If
  If Lcase(Mid(tagStr, 1, Len(startOfTagStr))) <> Lcase(startOfTagStr) _
    Or Lcase(Mid(tagStr, Len(tagStr) - (Len(endOfTagStr) - 1), Len(endOfTagStr))) <> Lcase(endOfTagStr) _
    Or InStr((1 + Len(startOfTagStr)), tagStr, startOfTagStr, CompareMode) <> 0 Then 
    ' The passed tag must start and end the line and also be on the same line, and 
    ' there must only be one tag at the line otherwise...
    ' Do nothing.
    processedTagStr = tagStr
    tagAlt2Title = processedTagStr
    Exit Function
  End If
  If InStr(1, tagStr, startOfSrcAttbStr, CompareMode) <> 0 Then
    ' Found Src Attribute.
    blnFoundSrcAttb = True
    posStartOfSrcAttbInt = InStr(1, tagStr, startOfSrcAttbStr, CompareMode)
    posEndOfSrcAttbInt = InStr(posStartOfSrcAttbInt + (Len(startOfSrcAttbStr)), tagStr, endOfSrcAttbStr, CompareMode)
    srcAttbStr = CStr(Mid(tagStr, (posStartOfSrcAttbInt + Len(startOfSrcAttbStr)), (posEndOfSrcAttbInt - (posStartOfSrcAttbInt + Len(startOfSrcAttbStr)))))
    'MsgBox ("srcAttbStr = " & "§" & srcAttbStr & "§")   ' Only for the purpose of debugging.
  Else
    ' Found No Src Attribute.
    blnFoundSrcAttb = False
    srcAttbStr = ""
  End If
  If InStrRev(srcAttbStr, "/") Then
    ' Get Src Attribute file name consisting of 'filename.extension'.
    srcAttbFileNameStr = CStr(Mid(srcAttbStr, (InStrRev(srcAttbStr, "/") + 1), Len(srcAttbStr)))
  Else
    ' Src Attribute file name consisting of 'filename.extension'.
    srcAttbFileNameStr = srcAttbStr
  End If
  'MsgBox ("srcAttbFileNameStr = " & "§" & srcAttbFileNameStr & "§")   ' Only for the purpose of debugging.
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) <> 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) = 0 Then
    foundAttbStr = Lcase("foundOnlyAltAttb")
  End If
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) = 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) <> 0 Then
    foundAttbStr = Lcase("foundOnlyTitleAttb")
  End If
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) <> 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) <> 0 Then
    foundAttbStr = Lcase("foundAltAndTitleAttb")
  End If
  If InStr(1, tagStr, startOfAltAttbStr, CompareMode) = 0 And InStr(1, tagStr, startOfTitleAttbStr, CompareMode) = 0 Then
    foundAttbStr = Lcase("foundNoAltAndTitleAttb")
  End If
  Select Case Lcase(foundAttbStr)
    Case "foundonlyaltattb"
      ' Found Only Alt Attribute.
      ' Use value of Alt Attribute to Title Attribute.
      posStartOfAltAttbInt = InStr(1, tagStr, startOfAltAttbStr, CompareMode)
      posEndOfAltAttbInt = InStr(posStartOfAltAttbInt + (Len(startOfAltAttbStr)), tagStr, endOfAltAttbStr, CompareMode)
      altAttbStr = CStr(Mid(tagStr, (posStartOfAltAttbInt + Len(startOfAltAttbStr)), (posEndOfAltAttbInt - (posStartOfAltAttbInt + Len(startOfAltAttbStr)))))
      'MsgBox ("altAttbStr = " & "§" & altAttbStr & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, (posEndOfAltAttbInt)) & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (posEndOfAltAttbInt + 1), (Len(tagStr) - posEndOfAltAttbInt)) & "§")   ' Only for the purpose of debugging.
      processedTagStr = Mid(tagStr, 1, (posEndOfAltAttbInt)) & _
      startOfTitleAttbStr & altAttbStr & endOfTitleAttbStr & _
      Mid(tagStr, (posEndOfAltAttbInt + 1), (Len(tagStr) - posEndOfAltAttbInt))
    Case "foundonlytitleattb"
      ' Found Only Title Attribute.
      ' Use value of Title Attribute to Alt Attribute.
      posStartOfTitleAttbInt = InStr(1, tagStr, startOfTitleAttbStr, CompareMode)
      posEndOfTitleAttbInt = InStr(posStartOfTitleAttbInt + (Len(startOfTitleAttbStr)), tagStr, endOfTitleAttbStr, CompareMode)
      titleAttbStr = CStr(Mid(tagStr, (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)), (posEndOfTitleAttbInt - (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)))))
      'MsgBox ("titleAttbStr = " & "§" & titleAttbStr & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, (posStartOfTitleAttbInt - 1)) & "§")   ' Only for the purpose of debugging.
      'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (posStartOfTitleAttbInt), Len(tagStr)) & "§")   ' Only for the purpose of debugging.
      processedTagStr = Mid(tagStr, 1, (posStartOfTitleAttbInt - 1)) & _
      startOfAltAttbStr & titleAttbStr & endOfAltAttbStr & _
      Mid(tagStr, (posStartOfTitleAttbInt), Len(tagStr))
    Case "foundaltandtitleattb"
      ' Found Alt And Title Attribute.
      If blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreExistingAndBothAreBlank = False Then
        ' Do NOT use value of Src Attribute to Alt Attribute and Title Attribute if both of these are existing and both of these are blank.
        ' Do nothing.
        processedTagStr = tagStr
      Else
        ' Do use value of Src Attribute to Alt Attribute and Title Attribute if both of these are existing and both of these are blank.
        posStartOfAltAttbInt = InStr(1, tagStr, startOfAltAttbStr, CompareMode)
        posEndOfAltAttbInt = InStr(posStartOfAltAttbInt + (Len(startOfAltAttbStr)), tagStr, endOfAltAttbStr, CompareMode)
        altAttbStr = CStr(Mid(tagStr, (posStartOfAltAttbInt + Len(startOfAltAttbStr)), (posEndOfAltAttbInt - (posStartOfAltAttbInt + Len(startOfAltAttbStr)))))
        'MsgBox ("altAttbStr = " & "§" & altAttbStr & "§")   ' Only for the purpose of debugging.
        posStartOfTitleAttbInt = InStr(1, tagStr, startOfTitleAttbStr, CompareMode)
        posEndOfTitleAttbInt = InStr(posStartOfTitleAttbInt + (Len(startOfTitleAttbStr)), tagStr, endOfTitleAttbStr, CompareMode)
        titleAttbStr = CStr(Mid(tagStr, (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)), (posEndOfTitleAttbInt - (posStartOfTitleAttbInt + Len(startOfTitleAttbStr)))))
        'MsgBox ("titleAttbStr = " & "§" & titleAttbStr & "§")   ' Only for the purpose of debugging.
        If altAttbStr = "" And titleAttbStr = "" Then
          ' Alt Attribute and Title Attribute are both blank.
          If posStartOfAltAttbInt < posStartOfTitleAttbInt Then
            ' Occurrence order: / Forekomst raekkefoelge: Alt Attribute - Title Attribute.
            'MsgBox ("tagStr (Part 1 of 3) = " & "§" & Mid(tagStr, 1, (posEndOfAltAttbInt - 1)) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 2 of 3) = " & "§" & Mid(tagStr, posEndOfAltAttbInt, (posStartOfTitleAttbInt - posEndOfAltAttbInt + Len(startOfTitleAttbStr))) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 3 of 3) = " & "§" & Mid(tagStr, posEndOfTitleAttbInt, Len(tagStr)) & "§")   ' Only for the purpose of debugging.
            processedTagStr = Mid(tagStr, 1, (posEndOfAltAttbInt - 1)) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfAltAttbInt, (posStartOfTitleAttbInt - posEndOfAltAttbInt + Len(startOfTitleAttbStr))) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfTitleAttbInt, Len(tagStr))
          Else
            ' Occurrence order: / Forekomst raekkefoelge: Title Attribute - Alt Attribute.
            'MsgBox ("tagStr (Part 1 of 3) = " & "§" & Mid(tagStr, 1, (posEndOfTitleAttbInt - 1)) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 2 of 3) = " & "§" & Mid(tagStr, posEndOfTitleAttbInt, (posStartOfAltAttbInt - posEndOfTitleAttbInt + Len(startOfAltAttbStr))) & "§")   ' Only for the purpose of debugging.
            'MsgBox ("tagStr (Part 3 of 3) = " & "§" & Mid(tagStr, posEndOfAltAttbInt, Len(tagStr)) & "§")   ' Only for the purpose of debugging.
            processedTagStr = Mid(tagStr, 1, (posEndOfTitleAttbInt - 1)) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfTitleAttbInt, (posStartOfAltAttbInt - posEndOfTitleAttbInt + Len(startOfAltAttbStr))) & _
            srcAttbFileNameStr & _
            Mid(tagStr, posEndOfAltAttbInt, Len(tagStr))
          End If
        Else
          ' Alt Attribute and Title Attribute are both NOT blank.
          ' Do nothing.
          processedTagStr = tagStr
        End If
      End If
    Case "foundnoaltandtitleattb"
      ' Found No Alt And Title Attribute.
      If blnOptionallyAddAltAttbAndTitleAttbIfBothAreMissing = False Then
        ' Do NOT add Alt Attribute and Title Attribute if both of these are missing.
        ' Do nothing.
        processedTagStr = tagStr
      Else
        ' Do add Alt Attribute and Title Attribute if both of these are missing.
        If blnFoundSrcAttb = True Then
          ' Src Attribute was found.
          'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, (posEndOfSrcAttbInt)) & "§")   ' Only for the purpose of debugging.
          'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (posEndOfSrcAttbInt + 1), (Len(tagStr) - posEndOfSrcAttbInt)) & "§")   ' Only for the purpose of debugging.
          If blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing = False Then
            ' Do NOT use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, (posEndOfSrcAttbInt)) & _
            startOfAltAttbStr & endOfAltAttbStr & _
            startOfTitleAttbStr & endOfTitleAttbStr & _
            Mid(tagStr, (posEndOfSrcAttbInt + 1), (Len(tagStr) - posEndOfSrcAttbInt))
          Else
            ' Do use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, (posEndOfSrcAttbInt)) & _
            startOfAltAttbStr & srcAttbFileNameStr & endOfAltAttbStr & _
            startOfTitleAttbStr & srcAttbFileNameStr & endOfTitleAttbStr & _
            Mid(tagStr, (posEndOfSrcAttbInt + 1), (Len(tagStr) - posEndOfSrcAttbInt))
          End If
        Else
          ' No Src Attribute was found.
          'MsgBox ("tagStr (Part 1 of 2) = " & "§" & Mid(tagStr, 1, Len(RTrim(startOfTagStr))) & "§")   ' Only for the purpose of debugging.
          'MsgBox ("tagStr (Part 2 of 2) = " & "§" & Mid(tagStr, (Len(RTrim(startOfTagStr)) + 1), (Len(tagStr) - Len(RTrim(startOfTagStr)))) & "§")   ' Only for the purpose of debugging.
          If blnOptionallyUseSrcAttbToAltAttbAndTitleAttbIfBothAreMissing = False Then
            ' Do NOT use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, Len(RTrim(startOfTagStr))) & _
            startOfAltAttbStr & endOfAltAttbStr & _
            startOfTitleAttbStr & endOfTitleAttbStr & _
            Mid(tagStr, (Len(RTrim(startOfTagStr)) + 1), (Len(tagStr) - Len(RTrim(startOfTagStr))))
          Else
            ' Do use value of Src Attribute to Alt Attribute and Title Attribute if both of these are missing.
            processedTagStr = Mid(tagStr, 1, Len(RTrim(startOfTagStr))) & _
            startOfAltAttbStr & srcAttbFileNameStr & endOfAltAttbStr & _
            startOfTitleAttbStr & srcAttbFileNameStr & endOfTitleAttbStr & _
            Mid(tagStr, (Len(RTrim(startOfTagStr)) + 1), (Len(tagStr) - Len(RTrim(startOfTagStr))))
          End If
        End If
      End If
    Case Else
      ' ERROR.
      ' Do nothing.
      processedTagStr = tagStr
  End Select
  'MsgBox ("processedTagStr = " & processedTagStr)   ' Only for the purpose of debugging.
  tagAlt2Title = processedTagStr
End Function

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

1 Implementation: (How to use:) /
1 Implementering: (Sådan bruger du:)

Simple word processor: / Simpel tekstbehandlerprogram:

  1. Open a new Text Document in a text editor similar to Microsoft Notepad /
    Åben et nyt Tekst Dokument i et tekst redigeringsprogram lignende Microsoft Notesblok
  2. Copy the code above /
    Kopier koden ovenfor
  3. Paste the code into the new Text Document /
    Indsæt koden i det nye Tekst Dokument
  4. Save the document before any other changes under the file name tagAlt2Title.vbs /
    Gem dokumentet før nogen andre ændringer under filnavnet tagAlt2Title.vbs
  5. Make sure that your text editor do not have added the file extension .txt to the saved file - in that case just rename the file to the correct file name consisting of 'filename.extension' /
    Sørg for, at dit tekst redigeringsprogram ikke har tilføjet filtypen .txt til den gemte fil - i dette tilfælde bare omdøb filen til det korrekte filnavn bestående af 'filnavn.filtype'

2 Implementation: (How to use:) /
2 Implementering: (Sådan bruger du:)

  1. Run this 'tagAlt2Title.vbs' script (double-click the script file name) /
    Kør 'tagAlt2Title.vbs' skriptet (dobbelt-klik på skript filnavnet)


...or use "Regular Expression" / ...eller brug "Regular Expression"

A regular expression (regexp | regex | RE) is a text pattern consisting of a combination of alphanumeric characters and special characters known as metacharacters. A close relative is in fact the wildcard expressionWhat / Hvad which are often used in file management. The pattern is used to match against text strings. The result of a match is either successful or not, however when a match is successful not all of the pattern must match in all cases. /
En regular expression (regexp | regex | RE) [regulær udtryk] er et tekst mønster bestående af en kombination af alfanumeriske tegn og specialtegn kendt som metategn. En nær slægtning er i virkeligheden det jokertegn udtrykWhat / Hvad, som ofte anvendes i filhåndtering. Mønsteret bruges til at matche mod tekststrenge. Resultatet af en matchning er enten en succes eller ej, men når en matchning er vellykket, skal ikke hele mønstret matche i alle tilfælde.

Regular expressions are used in three different ways: Regular text match, search and replace, and splitting. The latter is basically the same as the reverse match i.e. everything the regular expression did not match. /
Regular expressions [regulære udtryk] anvendes på tre forskellige måder: Almindelig tekst matchning, søg og erstat samt opsplitning. Sidstnævnte er grundlæggende det samme som den omvendte matchning, dvs. alt det, som det regular expression [regulære udtryk] ikke matchede.

Regular expressions are often simply called regexps, regex, or RE. /
Regular expressions [regulære udtryk] er ofte blot kaldet regexp, regex eller RE.

Use for example: / Brug for eksempel:

Search and Replace (SR) Script Text

[ For the program "Search and Replace" from Funduc Software at: http://www.funduc.com ] /
[ Til programmet "Search and Replace" fra Funduc Software ved: http://www.funduc.com ]

Warning! Always make a backup copy of your files before running this type of code. /
Advarsel! Lav altid en backup-kopi af dine filer før denne type kode køres.

Regular Expression

Step 1: /
Trin 1:

Add the content from the attribute 'alt' to a new attribute 'title' on all your pages in all your folders but only if you do not already have any 'title' attributes in your pages. /
Tilføj indholdet fra attributten 'alt' til en ny attribut 'title' på alle dine sider i alle dine mapper, men kun hvis du ikke allerede har nogen 'title' attributter i dine sider.

SR Script File (*.srs) extract: /
SR Skript Fil (*.srs) uddrag:



Search_subdir=1
[Search /ix]
 alt="*[]"
[Replace]
 alt="%1" title="%1"

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

Note that the first character in the "Search" and "Replace" lines is a space character. /
Bemærk at første karakter i "Search" og "Replace" linierne er en mellemrum karakter.

TextPad

[ For the program "TextPad" from Helios Software Solutions at: http://www.heliosof.demon.co.uk ] /
[ Til programmet "TextPad" fra Helios Software Solutions ved: http://www.heliosof.demon.co.uk ]

How to Use Regular Expressions / Sådan bruger du Regular Expressions

Developed and tested with the HTML (HyperText Markup Language) File: <filename>.htm. /
Udviklet og afprøvet med HTML (HyperText Markup Language) fil: <filnavn>.htm.

How to... / Hvordan...

#1 Search for attribute alt="..." and replace with alt="..." title="..." attributes... /
#1 Søg efter attributten alt="..." og erstat med alt="..." title="..." attributterne...

(... used in HTML tags (image) 'img', 'input' and 'area') /
(... brugt i HTML tag'ene (billede) 'img', 'input' og 'area')

...in the text part of HTML source code. /
...i tekst delen af HTML kildekoden.

Using... [ TextPad - Regular Expressions ] /
Ved at bruge... [ TextPad - Regular Expressions ]

[ ] Any one of the characters in the brackets, or any of a range of characters separated by a hyphen (-), or a character class operator. / Enhver af tegnene i parenteserne, eller enhver af et område af tegn adskilt af en bindestreg (-), eller en tegn klasse operator [operatør].
* Matches zero or more of the preceding characters or expressions. / Matcher nul eller flere af de foregående tegn eller udtryk.
[^] Any characters except for those after the caret "^". / Alle tegn bortset fra dem efter indskudstegnet "^".
\( \) Groups a tagged expression to use in replacement expressions. An RE can have up to 9 tagged expressions, numbered according to their order in the RE. The corresponding replacement expression is \x, for x in the range 1-9. / Grupperer et markeret udtryk til brug i udskiftnings-udtryk. En regular expression [regulær udtryk] kan have op til 9 markerede udtryk, nummereret i henhold til deres rækkefølge i regular expression [regulær udtryk]. Det tilsvarende udskiftnings-udtryk er \x, for x i intervallet 1-9.
\ "Escapes" the special meaning of the above expressions, so that they can be matched as literal characters. Hence, to match a literal "\", you must use "\\". / "Escapes" [undgår] den særlige betydning af de ovennævnte udtryk, så de kan blive matchet som bogstavelige tegn. Derfor, for at matche en bogstavelig "\", skal du bruge "\\".
[:blank:] Space or tab. (Note the extra pairs of brackets.) / Mellemrum eller tabulator. (Bemærk de ekstra par af parenteser.)

How... / Hvordan...

Always work on a copy of the original file! /
Arbejd altid på en kopi af den oprindelige fil!

  1. From the Search menu, choose Find, Replace, or Find in Files. /
    Fra søgemenuen vælg Find, Erstat eller Find i filer.
  2. In the Find What box, type a regular expression. /
    I Find hvad feltet skriv en regular expression [regulær udtryk]
  3. Check the "Regular expression" box. /
    Afmærk "Regular expression" boksen.

#1 Find what (start from the top of the page) (Note that the first character is a space character): /
#1 Find hvad (start fra toppen af siden) (Bemærk at første karakter er en mellemrum karakter):

 alt=\"\([^\"]*\)\"
or / eller
[[:blank:]]alt=\"\([^\"]*\)\"

Replace with (do not use "Replace All") (Note that the first character is a space character): /
Erstat med (brug ikke "Erstat alle") (Bemærk at første karakter er en mellemrum karakter):

 alt="\1" title="\1"

Example(s) / Eksempel(ler)

Example(s): /
Eksempel(ler):

HTML (HyperText Markup Language) File (*.htm) extract: /
HTML (HyperText Markup Language) Fil (*.htm) uddrag:



<P ALIGN="left"><img src="filename.ext" alt="" width="200"> <img src="filename.ext" alt=" " width="200"></P>

<P ALIGN="left"><img src="filename.ext" alt="MyAlt" width="200"></P>

<P ALIGN="left"><img src="filename.ext" alt="My Alt" width="200"></P>

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

Result: /
Resultat:

The result from the "Search and Replace (SR) Script Text" and "TextPad" above-mentioned 1 step should be that attribute alt="..." have been replaced with alt="..." title="..." attributes... like this: /
Resultatet fra "Search and Replace (SR) Script Text" og "TextPad" ovenfor nævnte 1 trin skulle være at attribut alt="..." er blevet erstattet med alt="..." title="..." attributterne... ligesom dette:



<P ALIGN="left"><img src="filename.ext" alt="" title="" width="200"> <img src="filename.ext" alt=" " title=" " width="200"></P>

<P ALIGN="left"><img src="filename.ext" alt="MyAlt" title="MyAlt" width="200"></P>

<P ALIGN="left"><img src="filename.ext" alt="My Alt" title="My Alt" width="200"></P>

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.


(Geometric Shapes) Source code snippetsSource code snippets / Kildekode småstykker

- often included as functions for use in modules with program code, macros, and scripts etcetera. / - mange gange inkluderet som funktioner til brug i moduler med programkode, makroer og scripts og så videre.

The code might need some minor tweaks to run in your application. / Koden kan behøve nogle mindre ændringer for at kunne afvikles i dit anvendelsesområde.

Warning / Advarsel Licence: Free to use, but please share improvements. No warranty - use at own risk. /
Warning / Advarsel Licens: Fri brug, men del venligst forbedringer. Ingen garanti - brug på eget ansvar.

Warning: Don't run the script files without reading them first!
Total absence of any guarantee, warranty, or responsibility for script files, the script(s), the files they may produce, or the effects the script(s) or script-produced files may have. The script(s) is, after all, plain text. The burden is on the person using the script(s) to examine the script source code and determine whether or not a script is usable and safe. Operating systems and browsers are constantly changing. What works today may not work tomorrow!

Advarsel: Kør ikke script-filerne uden at læse dem først!
Totalt fravær af nogen form for garanti, garanti eller ansvar for script-filer, scriptet(scriptene), de filer, de kan producere eller de virkninger, scriptet(scriptene) eller scriptproducerede filer kan have. Scriptet(Scriptene) er, trods alt, almindelig tekst. Byrden er på brugeren af scriptet(scriptene) til at undersøge script kildekoden og afgøre, hvorvidt et script er brugbart og sikkert. Operativsystemer og browsere er under konstant forandring. Hvad fungerer i dag, fungerer muligvis ikke i morgen!


   Top of This Page
   Return
   Go to Home Page