Jump to content

reading a text file, and adding information


Bert
 Share

Recommended Posts

Simple problem, but not sure on how to solve it...

I have a text file. Just a few lines, but it will be edited from tile to time. I need to read each line in it, and add a "<br>" at the end of it. If the line is blank, a "<BR>" will be added.

Example:

This is the first line<br>

<br>

This is the third line<br>

THis is the forth line<br>

What I'm working with is a addin for the AutoIt helpfile. The section that allows for the adding of comments is done through notepad. The problem is the Windows helpfile viewer reads in HTML, and notepad is text based. I can add the "<br>" by hand each time I make a entry, but it be nice to have the script do it for me.

The section of code that makes the comment box:

Func _CreateComment($s_FuncName)
    ; Create a new element to hold the codebox
    $oComment = $oIE.document.createElement ("")
   
    ; Gather previous comments if they exist
    $sCommentFile = $sCommentPath & $s_FuncName & ".txt"
    $sFuncComment = FileRead($sCommentFile)
    
    If @error Then $sFuncComment = ""
   
    ; Build the HTML for the commentbox
    If Not IsObj($oComment) Then Return 0
    $sHTML = ''
    $sHTML &= '<p><b>Comment</b></p>'
    $sHTML &= '<p class="codebox">'
    $sHTML &= '<br>'
    $sHTML &= '<font face="Comic Sans MS" size="2">' & $sFuncComment & '</font>'
    $sHTML &= '<br><br>'
    $sHTML &= '<OBJECT id=hhctrl type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=58 height=57>'
    $sHTML &= '<PARAM name="Command" value="ShortCut">'
    $sHTML &= '<PARAM name="Button" value="Text:Add Comment">'
    $sHTML &= '<PARAM name="Item1" value=",Examples\HelpFile\Comments\' & $s_FuncName & '.txt,">'
    $sHTML &= '</OBJECT>'
    With $oComment
        .innerHTML = $sHTML
    EndWith
   
    ; Insert the commentbox after the codebox
    If Not IsObj($oParent) Then Return 0
    $oParent.insertAdjacentElement ("afterEnd", $oComment)
   
    Return 1
EndFunc   ;==>_CreateComment
Link to comment
Share on other sites

I'm now ran into another problem, and this one is a real head scratcher. The script will make a several buttons to allow for the creation of custom scripts. The problem I'm having is to change the font in the button. Since I'm dealing with HTML, I thought a simple <B> would do it. For some reason, it isn't working. I tried GUICtrlSetFont, and that didn't work either

Func _CreateExample2($s_FuncName)
    ; Create a new element to hold the button
    $oButton3 = $oIE.document.createElement ("")
   
    ; Build the HTML for the button
    ;$font="Comic Sans MS"   ;didn't work
    ;$s_FuncName1 = GUICtrlSetFont ($s_FuncName,9, 500, 2, $font)   ;didn't work
    If Not IsObj($oButton3) Then Return 0
    $sHTML = "&nbsp;"
    $sHTML &= '<OBJECT id=hhctrl type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=80 height=57>'
    $sHTML &= '<PARAM name="Command" value="ShortCut">'
    $sHTML &= '<PARAM name="Button" value="Text:Open ' & $s_FuncName & ' Custom Scripts folder">'
    ;$sHTML &= '<PARAM name="Button" value="Text:Open ' & $s_FuncName1 & ' Custom Scripts folder">'    ;didn't work
    ;$sHTML &= '<PARAM name="Button" value="Text:Open <B>' & $s_FuncName & '</b> Custom Scripts folder">'   ;didn't work
    $sHTML &= '<PARAM name="Item1" value=",Examples\HelpFile\Examples\' & $s_FuncName & '\,">'
    $sHTML &= '</OBJECT>'
    With $oButton3
        .innerHTML = $sHTML
    EndWith
    ; Insert the button as the next child of the codebox
    If Not IsObj($oParent) Then Return 0
    $oParent.appendChild ($oButton3)
   
    Return 1
EndFunc   ;==>_CreateExample2
Link to comment
Share on other sites

I'm now ran into another problem, and this one is a real head scratcher. The script will make a several buttons to allow for the creation of custom scripts. The problem I'm having is to change the font in the button. Since I'm dealing with HTML, I thought a simple <B> would do it. For some reason, it isn't working. I tried GUICtrlSetFont, and that didn't work either

Func _CreateExample2($s_FuncName)
    ; Create a new element to hold the button
    $oButton3 = $oIE.document.createElement ("")
   
    ; Build the HTML for the button
    ;$font="Comic Sans MS"   ;didn't work
    ;$s_FuncName1 = GUICtrlSetFont ($s_FuncName,9, 500, 2, $font)   ;didn't work
    If Not IsObj($oButton3) Then Return 0
    $sHTML = "&nbsp;"
    $sHTML &= '<OBJECT id=hhctrl type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=80 height=57>'
    $sHTML &= '<PARAM name="Command" value="ShortCut">'
    $sHTML &= '<PARAM name="Button" value="Text:Open ' & $s_FuncName & ' Custom Scripts folder">'
    ;$sHTML &= '<PARAM name="Button" value="Text:Open ' & $s_FuncName1 & ' Custom Scripts folder">'    ;didn't work
    ;$sHTML &= '<PARAM name="Button" value="Text:Open <B>' & $s_FuncName & '</b> Custom Scripts folder">'   ;didn't work
    $sHTML &= '<PARAM name="Item1" value=",Examples\HelpFile\Examples\' & $s_FuncName & '\,">'
    $sHTML &= '</OBJECT>'
    With $oButton3
        .innerHTML = $sHTML
    EndWith
    ; Insert the button as the next child of the codebox
    If Not IsObj($oParent) Then Return 0
    $oParent.appendChild ($oButton3)
   
    Return 1
EndFunc   ;==>_CreateExample2
Since this is a resistered object rather than an HTML button you are completely at the mercy of what the code in hhctrl.ocx does to what you pass to it in the PARAM. If <b> doesn't get rendered, you might try CSS, but it is unlikely that it will work either.

You can find more into on the control here

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...